angelu2001 / php-reader

Automatically exported from code.google.com/p/php-reader
0 stars 0 forks source link

Dealing with bad ID3 #77

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
I have an ID3 file that was causing a crash (memory allocation error).  
Tracking in to it, the file has an USLT frame with an incorrect length -- it is 
actually one byte longer than stated in the frame length.  So when the library 
tried to read the next frame it was a byte off and went kinda crazy.

Although the frame was incorrect, the crash could be avoided by a simple change 
in the Id3v2.php file.  At line 188, right after the check for the first 
character === 0 you can check to see if the character is A-Z or 0-9, as 
required for all frame identifiers according to the ID3 spec.  So adding a line 
like this:

   if (!ctype_digit($identifier[0]) && !ctype_upper($identifier[0]))
    continue;

Gets past the errant byte and allows the following frames to be read.  
Obviously there are other potential errors that this wouldn't fix, but I 
believe this is a safe and legitimate check to perform on the $identifier.

Original issue reported on code.google.com by stephen....@gmail.com on 16 Apr 2015 at 8:50

GoogleCodeExporter commented 8 years ago
Related to this, I added the following to Reader.php to prevent memory 
allocation crashes
when things do somehow get out of sync.  This allows the calling program to 
catch the error
and recover in whatever way is appropriate...

    public function read($length)
    {

    // SSP: Added sanity check
    if ($length > 65535) {
            require_once('Zend/Io/Exception.php');
            throw new Zend_Io_Exception("Unable to read more than 65535 bytes, $length requested.");
    }

    ...

Original comment by stephen....@gmail.com on 17 Apr 2015 at 5:21