Page MenuHomePhabricator

getid3: PHP Warning: Division by zero
Open, In Progress, MediumPublicPRODUCTION ERROR

Description

Error
normalized_message
[{reqId}] {exception_url}   PHP Warning: Division by zero
exception.trace
from /srv/mediawiki/php-1.37.0-wmf.18/vendor/james-heinrich/getid3/getid3/module.audio-video.mpeg.php(619)
#0 /srv/mediawiki/php-1.37.0-wmf.18/vendor/james-heinrich/getid3/getid3/module.audio-video.mpeg.php(619): MWExceptionHandler::handleError(integer, string, string, integer, array)
#1 /srv/mediawiki/php-1.37.0-wmf.18/vendor/james-heinrich/getid3/getid3/module.audio-video.mpeg.php(180): getid3_mpeg::videoAspectRatioLookup(integer, integer, integer, integer)
#2 /srv/mediawiki/php-1.37.0-wmf.18/vendor/james-heinrich/getid3/getid3/getid3.php(636): getid3_mpeg->Analyze()
#3 /srv/mediawiki/php-1.37.0-wmf.18/extensions/TimedMediaHandler/includes/handlers/ID3Handler/ID3Handler.php(32): getID3->analyze(string)
#4 /srv/mediawiki/php-1.37.0-wmf.18/extensions/TimedMediaHandler/includes/handlers/ID3Handler/ID3Handler.php(51): ID3Handler->getID3(string)
#5 /srv/mediawiki/php-1.37.0-wmf.18/includes/media/MediaHandler.php(240): ID3Handler->getMetadata(FSFile, string)
#6 /srv/mediawiki/php-1.37.0-wmf.18/includes/utils/MWFileProps.php(88): MediaHandler->getSizeAndMetadataWithFallback(FSFile, string)
#7 /srv/mediawiki/php-1.37.0-wmf.18/includes/upload/UploadBase.php(552): MWFileProps->getPropsFromPath(string, string)
#8 /srv/mediawiki/php-1.37.0-wmf.18/includes/upload/UploadFromChunks.php(382): UploadBase->verifyPartialFile()
#9 /srv/mediawiki/php-1.37.0-wmf.18/includes/upload/UploadFromChunks.php(241): UploadFromChunks->verifyChunk()
#10 /srv/mediawiki/php-1.37.0-wmf.18/includes/api/ApiUpload.php(274): UploadFromChunks->addChunk(string, integer, integer)
#11 /srv/mediawiki/php-1.37.0-wmf.18/includes/api/ApiUpload.php(153): ApiUpload->getChunkResult(array)
#12 /srv/mediawiki/php-1.37.0-wmf.18/includes/api/ApiUpload.php(124): ApiUpload->getContextResult()
#13 /srv/mediawiki/php-1.37.0-wmf.18/includes/api/ApiMain.php(1842): ApiUpload->execute()
#14 /srv/mediawiki/php-1.37.0-wmf.18/includes/api/ApiMain.php(821): ApiMain->executeAction()
#15 /srv/mediawiki/php-1.37.0-wmf.18/includes/api/ApiMain.php(792): ApiMain->executeActionWithErrorHandling()
#16 /srv/mediawiki/php-1.37.0-wmf.18/api.php(90): ApiMain->execute()
#17 /srv/mediawiki/php-1.37.0-wmf.18/api.php(45): wfApiMain()
#18 /srv/mediawiki/w/api.php(3): require(string)
#19 {main}
Impact

Unclear, but probably some display error. Wrong aspect ratio?

Notes

Noticed 2 of these in 1.37.0-wmf.18 during train log triage.

Details

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

Event Timeline

Krinkle added a subscriber: Krinkle.

We've not seen this before, and there were a number of recent patches merged in TMH. Perhaps one of those caused this regression? /cc @brion.

Looks like it's related to the MPEG file uploads aspect ratio handling, one of the cases may be bad and is failing on specific files being uploaded from time to time. Let me see if I can narrow it down; the logs don't include the source material being uploaded alas so I can't just inspect a held file. :(

The entire data extraction through to the exception is performed within the getid3 library and is specific to files that are being interpreted as MPEG-2 video. It looks sensible enough, unless it contravenes the spec or the input files are corrupt I'm not sure what could cause this failure.

Arguably throwing an exception here is correct behavior, though it might be wise to wrap this low-level arithmetic error in a high-level exception that aids in understanding the error report.

Agh dangit it's not catchable is it. Silly PHP.

Ah well, I'll open a protective patch on the getid3 library and we can apply it later with other updates.

Yeah, this one may be my fault. I wrote the code that's failing in getid3. lol

Upstream pull req with quick workaround to avoid failing (but may result in wrong interpretation of aspect ratio): https://github.com/JamesHeinrich/getID3/pull/359

We can pull it in once it hits, no need to go out of sequence I think unless we can find specific files triggering it first.

brion changed the task status from Open to In Progress.Dec 23 2021, 1:14 AM
brion claimed this task.
brion raised the priority of this task from Low to Medium.

Going ahead and checking for any other files that cause problems while I'm at it though. I'll run the tests tomorrow after downloading the data set.

Bumping prio to medium since it may mean rejection of legit files (don't know yet)

I found a previously-uploaded file that triggers the error and am trying to track it down inside getid3. Filed an upstream bug w/ the link & repro: https://github.com/JamesHeinrich/getID3/issues/360

Confirmed with upstream that the workaround is good enough for now, so we either wait until he gets a release out or we patch it locally. I've found about a half dozen files already uploaded that trigger this bug when re-parsed, so those may also trigger it this bug if something causes metadata to be re-read from the file.

They are:

  • Born_of_a_Dream_-_Extra_Feature.mpg
  • Fröbel-Stern_basteln_(98MB).mpg
  • Prometei_–_Marco_Bertarini_teaser.mpg
  • Ruffed_Lemur_at_Ikeda_zoo_Japan.mpg
  • Zdravko_Pečar_-_Elephant_Hunt.mpg
  • لغو_ناگهانی_سفر_مدیر_اجرایی_بنیاد_ویکی?مدیا_به_ایران.mpg

They're all MPEG-2 but there's a lot of difference in resolutions and frame rates. Anyway if we have more trouble with them, that's the ones we got.

tstarling added a subscriber: tstarling.

Per the stack trace I posted at T303784, this also affects module.audio-video.matroska.php, line 299. I found a few more issues by code review. I'll make a PR.

In PHP 8.1, division by zero will throw a DivisionByZeroError.