Mercurial > hg > mgallery
changeset 319:bf4115b6dc2a
Improve WebP parsing resiliency. feof($fh) does not return true when ftell() == filesize exactly.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 06 Apr 2020 20:48:07 +0300 |
parents | 9638512be261 |
children | a4c6937dfaaf |
files | mgtool.php |
diffstat | 1 files changed, 3 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mgtool.php Mon Apr 06 20:26:21 2020 +0300 +++ b/mgtool.php Mon Apr 06 20:48:07 2020 +0300 @@ -279,7 +279,7 @@ return "Invalid WebP file, chunk size larger than file size"; $done = 0; - while (!feof($fh) && $done < 2) + while (!feof($fh) && ftell($fh) < $fileData["size"] && $done < 2) { // Read chunk header if (($data = @fread($fh, 2 * 4)) == FALSE) @@ -287,12 +287,12 @@ $chunk = unpack("c4id/L1size", $data); - /* +/* printf("chunk: '%c%c%c%c' (%02x %02x %02x %02x) osize=%d\n", $chunk["id1"], $chunk["id2"], $chunk["id3"], $chunk["id4"], $chunk["id1"], $chunk["id2"], $chunk["id3"], $chunk["id4"], $chunk["size"]); - */ +*/ // Check for EXIF chunk if ($chunk["id1"] == 0x45 && $chunk["id2"] == 0x58 &&