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

From: Date: Sat, 18 Jul 2015 20:58:49 +0000
Subject: Bug #70096 [Ana->Csd]: Repeated iptcembed() adds superfluous FF bytes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-194546@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:             Analyzed
+Status:             Closed
 Type:               Bug
 Package:            GetImageSize related
 Operating System:   *
 PHP Version:        7.0.0beta1
 Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=php-src.git;a=commit;h=8c483ce36cb07d7e986484da93cf064ad1cc9dd7
Log: Fix #70096: Repeated iptcembed() adds superfluous FF bytes


Previous Comments:
------------------------------------------------------------------------
[2015-07-18 19:42:38] cmb@php.net

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>

------------------------------------------------------------------------
[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


Thread (3 messages)

« previous php.bugs (#194546) next »