Page MenuHomePhabricator

InvalidArgumentException: Cannot add non-finite floats to ApiResult
Closed, ResolvedPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   InvalidArgumentException: Cannot add non-finite floats to ApiResult
exception.trace
from /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiResult.php(372)
#0 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiResult.php(362): ApiResult::validateValue(double)
#1 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiResult.php(362): ApiResult::validateValue(array)
#2 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiResult.php(362): ApiResult::validateValue(array)
#3 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiResult.php(400): ApiResult::validateValue(array)
#4 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiUpload.php(135): ApiResult->addValue(string, string, array)
#5 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiMain.php(1892): ApiUpload->execute()
#6 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiMain.php(870): ApiMain->executeAction()
#7 /srv/mediawiki/php-1.38.0-wmf.24/includes/api/ApiMain.php(841): ApiMain->executeActionWithErrorHandling()
#8 /srv/mediawiki/php-1.38.0-wmf.24/api.php(90): ApiMain->execute()
#9 /srv/mediawiki/php-1.38.0-wmf.24/api.php(45): wfApiMain()
#10 /srv/mediawiki/w/api.php(3): require(string)
#11 {main}
Impact
Notes

Details

Request URL
https://commons.wikimedia.org/w/api.php

Event Timeline

Not sure if an issue with the Api base class or the caller in ApiUpload. Usually I'd suspect the latter, but the fact that it triggers a fatal only after several layers deep inside ApiResult suggests that perhaps that is doing something wrong also or instead.

The calls to ApiResult::validateValue are recursive for array input. The data are the imageinfo after a success upload by UploadBase::getImageInfo, which gets its info from ApiQueryImageInfo (prop=imageinfo). This could be related to the uploaded file and its metadata

More recently there is

2022-10-07 03:48:21.136561 [5211b6f6-2d3f-4750-a18a-1911eed0c6b8] mw1426 commonswiki 1.40.0-wmf.4 exception ERROR: [5211b6f6-2d3f-4750-a18a-1911eed0c6b8] /w/api.php   InvalidArgumentException: Cannot add non-finite floats to ApiResult {"exception_url":"/w/api.php","reqId":"5211b6f6-2d3f-4750-a18a-1911eed0c6b8","caught_by":"entrypoint"}

On PHP 7.4, division by zero raises a warning and returns INF. On PHP 8.1 it is an exception. I see there are some unguarded divisions in Exif.php but this particular log entry was probably associated with this warning:

2022-10-07 03:44:33.178965 [2aac6fa1-fb63-4480-8094-6c1d85351c7c] mw1382 commonswiki 1.40.0-wmf.4 error ERROR: [2aac6fa1-fb63-4480-8094-6c1d85351c7c] /w/api.php   PHP Warning: Division by zero {"exception_url":"/w/api.php","reqId":"2aac6fa1-fb63-4480-8094-6c1d85351c7c","caught_by":"mwe_handler"} 
[Exception ErrorException] (/srv/mediawiki/php-1.40.0-wmf.4/vendor/james-heinrich/getid3/getid3/module.audio-video.matroska.php:299) PHP Warning: Division by zero
  #0 /srv/mediawiki/php-1.40.0-wmf.4/vendor/james-heinrich/getid3/getid3/module.audio-video.matroska.php(299): MWExceptionHandler::handleError(integer, string, string, integer, array)
  #1 /srv/mediawiki/php-1.40.0-wmf.4/vendor/james-heinrich/getid3/getid3/getid3.php(781): getid3_matroska->Analyze()
  #2 /srv/mediawiki/php-1.40.0-wmf.4/extensions/TimedMediaHandler/includes/Handlers/ID3Handler/ID3Handler.php(40): getID3->analyze(string)
  #3 /srv/mediawiki/php-1.40.0-wmf.4/extensions/TimedMediaHandler/includes/Handlers/WebMHandler/WebMHandler.php(19): MediaWiki\TimedMediaHandler\Handlers\ID3Handler\ID3Handler->getID3(string)
  #4 /srv/mediawiki/php-1.40.0-wmf.4/extensions/TimedMediaHandler/includes/Handlers/ID3Handler/ID3Handler.php(59): MediaWiki\TimedMediaHandler\Handlers\WebMHandler\WebMHandler->getID3(string)
  #5 /srv/mediawiki/php-1.40.0-wmf.4/includes/media/MediaHandler.php(240): MediaWiki\TimedMediaHandler\Handlers\ID3Handler\ID3Handler->getMetadata(FSFile, string)
  #6 /srv/mediawiki/php-1.40.0-wmf.4/includes/utils/MWFileProps.php(89): MediaHandler->getSizeAndMetadataWithFallback(FSFile, string)
  #7 /srv/mediawiki/php-1.40.0-wmf.4/includes/upload/UploadBase.php(559): MWFileProps->getPropsFromPath(string, string)
  #8 /srv/mediawiki/php-1.40.0-wmf.4/includes/upload/UploadFromChunks.php(384): UploadBase->verifyPartialFile()
  #9 /srv/mediawiki/php-1.40.0-wmf.4/includes/upload/UploadFromChunks.php(77): UploadFromChunks->verifyChunk()
  #10 /srv/mediawiki/php-1.40.0-wmf.4/includes/api/ApiUpload.php(367): UploadFromChunks->tryStashFile(User, boolean)
  #11 /srv/mediawiki/php-1.40.0-wmf.4/includes/api/ApiUpload.php(264): ApiUpload->performStash(string)
  #12 /srv/mediawiki/php-1.40.0-wmf.4/includes/api/ApiUpload.php(157): ApiUpload->getChunkResult(array)
  #13 /srv/mediawiki/php-1.40.0-wmf.4/includes/api/ApiUpload.php(128): ApiUpload->getContextResult()
  #14 /srv/mediawiki/php-1.40.0-wmf.4/includes/api/ApiMain.php(1900): ApiUpload->execute()
  #15 /srv/mediawiki/php-1.40.0-wmf.4/includes/api/ApiMain.php(875): ApiMain->executeAction()
  #16 /srv/mediawiki/php-1.40.0-wmf.4/includes/api/ApiMain.php(846): ApiMain->executeActionWithErrorHandling()
  #17 /srv/mediawiki/php-1.40.0-wmf.4/api.php(90): ApiMain->execute()
  #18 /srv/mediawiki/php-1.40.0-wmf.4/api.php(45): wfApiMain()
  #19 /srv/mediawiki/w/api.php(3): require(string)
  #20 {main}

That is T289189.

Following T275268, it shouldn't be possible for INF in image metadata to be permanently stored in the database, even in legacy data, so this can probably only happen on upload.

We could filter out the INF from metadata arrays in ApiUpload, but if the only source of INF is division by zero, it will go away in PHP 8.1 anyway, replaced by an exception at the source.

TheDJ claimed this task.
TheDJ subscribed.

Error is no longer present in the logs