JamesHeinrich / getID3

http://www.getid3.org/
Other
1.15k stars 245 forks source link

ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) #315

Closed paulijar closed 3 years ago

paulijar commented 3 years ago

I got a report from an end user that a few of his files are breaking the file scanning. I got also a sample file which I shall email shortly. The error message indicates that the scanning is terminated at https://github.com/JamesHeinrich/getID3/blob/a5f31b38c865ec6b0fc07041214e9d111a02775f/getid3/module.tag.id3v2.php#L999 because of the reason shown in the issue title. That is, the $frame_offset goes beyond the end of the target data buffer.

This actually terminates the file analysis only when PHP 8.0 is used, because there, the platform throws a ValueError on invalid argument value. On PHP 7.x, this just emits a warning and the file analysis continues and returns valid-looking data.

The original report is here: https://github.com/owncloud/music/issues/856

JamesHeinrich commented 3 years ago

Thanks for the sample file, fixed in https://github.com/JamesHeinrich/getID3/commit/897de3874132c56e760ddb4e16916306b7a3d96e.

The file has a badly-written "USLT" (lyrics) frame. The frame requires at a minimum 5 bytes (1x encoding, 3x language, 1x description/data terminator) even if the frame contains no actual data, but the sample file has the frame stop after the encoding byte. I have added a check for sufficient data before attempting to parse it.

paulijar commented 3 years ago

Thanks! Your response time was astonishing as always. 🎉