From 382c01546e4976656d991cbda8c32e2040fc5e75 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pauli=20J=C3=A4rvinen?= Date: Wed, 21 Sep 2016 23:50:40 +0300 Subject: [PATCH] Fixed parsing of non-regular files - 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. --- src/getID3/getid3_handler.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/getID3/getid3_handler.php b/src/getID3/getid3_handler.php index 6545933..f1f43f6 100644 --- a/src/getID3/getid3_handler.php +++ b/src/getID3/getid3_handler.php @@ -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) {