Bug #70096 [Asn->Ana]: Repeated iptcembed() adds superfluous FF bytes

From: Date: Sat, 18 Jul 2015 19:42:39 +0000
Subject: Bug #70096 [Asn->Ana]: Repeated iptcembed() adds superfluous FF bytes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194543@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=70096&edit=1 ID: 70096 Updated by: cmb@php.net Reported by: cmb@php.net Summary: Repeated iptcembed() adds superfluous FF bytes -Status: Assigned +Status: Analyzed Type: Bug Package: GetImageSize related Operating System: * PHP Version: 7.0.0beta1 Assigned To: cmb Block user comment: N Private report: N New Comment: The algorithm to embed an APP13 marker segment into the file works by processing the marker segments, and to copy them verbatim. The only special handling is that after the first APP0 or APP1 marker segment the new APP13 marker segment is inserted, and an existing APP13 marker segment is skipped. After the latter has been done, the rest of the stream is copied in one go; no need for further processing the individual marker segments. However, when an existing APP13 is recognized[1], its first byte (FF) has already been copied to the buffer[2], and only the rest of the marker segment is skipped. This results in duplication of this byte. [1] <https://github.com/php/php-src/blob/php-5.6.11/ext/standard/iptc.c#L236> [2] <https://github.com/php/php-src/blob/php-5.6.11/ext/standard/iptc.c#L227> Previous Comments: ------------------------------------------------------------------------ [2015-07-18 19:14:18] cmb@php.net Related To: Bug #54173 ------------------------------------------------------------------------ [2015-07-18 19:06:07] cmb@php.net Description: ------------ Repeately calling iptcembed() causes a superfluous FF byte to be added with each call. While this may not be a violation of the JFIF standard (the specs are not publicly available, apparently), I'd nonetheless consider this a bug, because repeated embedding of the same metadata should not result in different files. Test script: --------------- <?php $filename = __DIR__ . '/test.jpg'; @unlink($filename); $im = imagecreatetruecolor(10, 10); imagejpeg($im, $filename); imagedestroy($im); $data = "\x1C\x02x\x00\x0ATest image" . "\x1C\x02t\x00\x22Copyright 2008-2009, The PHP Group"; $content = iptcembed($data, $filename); $fp = fopen($filename, "wb"); fwrite($fp, $content); fclose($fp); echo filesize($filename), PHP_EOL; clearstatcache(); $content = iptcembed($data, $filename); $fp = fopen($filename, "wb"); fwrite($fp, $content); fclose($fp); echo filesize($filename), PHP_EOL; ?> Expected result: ---------------- 779 779 Actual result: -------------- 779 780 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=70096&edit=1

« previous php.bugs (#194543) next »