Skip to content
This repository has been archived by the owner on Jun 2, 2019. It is now read-only.

Commit

Permalink
Fixed parsing of non-regular files
Browse files Browse the repository at this point in the history
- In case the file analyzed is not a regular local file but e.g. a Linux pipe, the parser used to read only the first ~16KB of the file. If the total size of all the tags exceeded 16KB, then some tags could not be parsed. Typically, this prevented parsing the embedded cover art.
- The problem was caused by incorrect assumptions on the behavior of the system function fread.
  • Loading branch information
paulijar committed Sep 21, 2016
1 parent 89c8a68 commit 382c015
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/getID3/getid3_handler.php
Expand Up @@ -84,7 +84,17 @@ protected function fread($bytes) {
if (!getid3_lib::intValueSupported($pos)) {
throw new getid3_exception('cannot fread('.$bytes.' from '.$this->ftell().') because beyond PHP filesystem limit', 10);
}
return fread($this->getid3->fp, $bytes);

// System fread function may return less data than requested in case the file is not a regular local file.
// See http://php.net/manual/en/function.fread.php. Call it repeatedly in a loop if that is the case.
$contents = '';
do {
$part = fread($this->getid3->fp, $bytes);
$partLength = strlen($part);
$bytes -= $partLength;
$contents .= $part;
} while ($bytes > 0 && $partLength > 0);
return $contents;
}

protected function fseek($bytes, $whence=SEEK_SET) {
Expand Down

0 comments on commit 382c015

Please sign in to comment.