All tags may not be read from "non-regular file"

Locked
paulijar
User
Posts: 3
Joined: Mon Jul 25, 2016 10:13 pm
Are you a spambot?: no

All tags may not be read from "non-regular file"

Post by paulijar » Mon Jul 25, 2016 11:11 pm

I was having problems loading the cover art from many of my MP3 files in the owncloud application which uses getID3. The problem seemed to happen especially on files with larger embedded cover images and I was getting error messages like this:
error parsing \"APIC\" (600 bytes into the ID3v2.3 tag). (ERROR: $frame_size (28271) > strlen($framedata) (null)).

Drilling down to the code, I found out that the root cause for the problem was how getID3 uses the PHP system function fread(). It seems to assume that fread() would always return as many bytes as were requested. However, according the PHP manual (http://php.net/manual/en/function.fread.php), this is the case only with regular local files, but not e.g. with Linux pipes. The call may return only part of the requested data and a new call is needed to get more.

I was able to fix the problem by modifying protected function fread($bytes) in getid3.php. I replaced the line

Code: Select all

return fread($this->getid3->fp, $bytes);
with block

Code: Select all

$contents = '';
do {
    $part = fread($this->getid3->fp, $bytes);
    $partLength = strlen($part);
    $bytes -= $partLength;
    $contents .= $part;
} while ($bytes > 0 && $partLength > 0);
return $contents;
With this change it worked like a charm and all the cover art tags could be parsed with no errors.

paulijar
User
Posts: 3
Joined: Mon Jul 25, 2016 10:13 pm
Are you a spambot?: no

Re: All tags may not be read from "non-regular file"

Post by paulijar » Mon Jul 25, 2016 11:19 pm

Forgot to mention that the version of getID3 used in owncloud is 1.9.9 but I checked that there are no relevant source code changes in the most recent development version.

James Heinrich
getID3() v1 developer
Posts: 1435
Joined: Fri May 04, 2001 4:00 pm
Are you a spambot?: no
Location: Northern Ontario, Canada
Contact:

Re: All tags may not be read from "non-regular file"

Post by James Heinrich » Mon Jul 25, 2016 11:55 pm

Thanks. It's not something I've run into but your solution seems sound. I have incorporated it:
https://github.com/JamesHeinrich/getID3 ... 296576bce5

paulijar
User
Posts: 3
Joined: Mon Jul 25, 2016 10:13 pm
Are you a spambot?: no

Re: All tags may not be read from "non-regular file"

Post by paulijar » Tue Jul 26, 2016 10:12 am

Great, thanks!

Locked