com php-src: Fix #70096: Repeated iptcembed() adds superfluous FF bytes: ext/standard/iptc.c ext/standard/tests/image/bug70096.phpt
| From: | Christoph Michael Becker | Date: | Sat, 18 Jul 2015 20:48:54 +0000 |
| Subject: | com php-src: Fix #70096: Repeated iptcembed() adds superfluous FF bytes: ext/standard/iptc.c ext/standard/tests/image/bug70096.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-88035@lists.php.net to get a copy of this message | ||
Commit: 8c483ce36cb07d7e986484da93cf064ad1cc9dd7
Author: Christoph M. Becker <cmb@php.net> Sat, 18 Jul 2015 22:48:54 +0200
Parents: a66efb0b154236e63f98b95bd12bc31fea90500c
Branches: PHP-5.6 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=8c483ce36cb07d7e986484da93cf064ad1cc9dd7
Log:
Fix #70096: Repeated iptcembed() adds superfluous FF bytes
When there is already an APP13 marker segment in the file, iptcembed() doesn't
skip the first byte (0xFF) of this segment, what leads to unnecessary and
potentially invalid duplication of this byte. This patch fixes this issue.
Bugs:
https://bugs.php.net/70096
Changed paths:
M ext/standard/iptc.c
A ext/standard/tests/image/bug70096.phpt
Diff:
diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c
index 05d778b..169ee96 100644
--- a/ext/standard/iptc.c
+++ b/ext/standard/iptc.c
@@ -236,6 +236,7 @@ PHP_FUNCTION(iptcembed)
case M_APP13:
/* we are going to write a new APP13 marker, so don't output the old one */
php_iptc_skip_variable(fp, 0, 0 TSRMLS_CC);
+ fgetc(fp); /* skip already copied 0xFF byte */
php_iptc_read_remaining(fp, spool, poi?&poi:0 TSRMLS_CC);
done = 1;
break;
diff --git a/ext/standard/tests/image/bug70096.phpt b/ext/standard/tests/image/bug70096.phpt
new file mode 100644
index 0000000..1674d07
--- /dev/null
+++ b/ext/standard/tests/image/bug70096.phpt
@@ -0,0 +1,31 @@
+--TEST--
+Bug #70096 (Repeated iptcembed() adds superfluous FF bytes)
+--SKIPIF--
+<?php
+if (!extension_loaded('gd')) die('skip gd extension not available');
+?>
+--FILE--
+<?php
+$filename = __DIR__ . '/bug70096.jpg';
+$im = imagecreatetruecolor(10, 10);
+imagejpeg($im, $filename);
+imagedestroy($im);
+$data = "\x1C\x02x\x00\x0ATest image"
+ . "\x1C\x02t\x00\x22Copyright 2008-2009, The PHP Group";
+$content1 = iptcembed($data, $filename);
+$fp = fopen($filename, "wb");
+fwrite($fp, $content1);
+fclose($fp);
+$content2 = iptcembed($data, $filename);
+$fp = fopen($filename, "wb");
+fwrite($fp, $content2);
+fclose($fp);
+var_dump($content1 === $content2);
+?>
+--CLEAN--
+<?php
+$filename = __DIR__ . '/bug70096.jpg';
+@unlink($filename);
+?>
+--EXPECT--
+bool(true)