From a269ab64baad972b1e1bd5ce1fbbedb8614c3426 Mon Sep 17 00:00:00 2001 From: Guillaume Degoulet Date: Wed, 30 Jan 2019 11:38:17 +0100 Subject: [PATCH 1/4] bug: https://bugs.php.net/bug.php?id=77546 --- ext/standard/iptc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index 2196e43f2e633..0dffdb31d2e94 100644 --- a/ext/standard/iptc.c +++ b/ext/standard/iptc.c @@ -273,7 +273,7 @@ PHP_FUNCTION(iptcembed) iptcdata_len++; /* make the length even */ } - psheader[ 2 ] = (char) (iptcdata_len+28)>>8; + psheader[ 2 ] = (char) ((iptcdata_len+28)>>8); psheader[ 3 ] = (iptcdata_len+28)&0xff; for (inx = 0; inx < 28; inx++) { From 82435907ea4635c1bf29c5756c64b54e8c850e66 Mon Sep 17 00:00:00 2001 From: Guillaume Degoulet Date: Wed, 30 Jan 2019 12:07:26 +0100 Subject: [PATCH 2/4] add phpt test file related Fix bug #77546 --- ext/standard/tests/image/iptcembed_002.phpt | 93 +++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 ext/standard/tests/image/iptcembed_002.phpt diff --git a/ext/standard/tests/image/iptcembed_002.phpt b/ext/standard/tests/image/iptcembed_002.phpt new file mode 100644 index 0000000000000..4782b23836113 --- /dev/null +++ b/ext/standard/tests/image/iptcembed_002.phpt @@ -0,0 +1,93 @@ +--TEST-- +iptcembed() valid jpg stream +--FILE-- +> 8) . chr($length & 0xFF); } + else { $retval .= chr(0x80) . chr(0x04) . chr(($length >> 24) & 0xFF) . chr(($length >> 16) & 0xFF) . chr(($length >> 8) & 0xFF) . chr($length & 0xFF); } + return $retval . $value; + } + + +$file="1x1.jpg"; +$file2="1x1_with_iptc_tags.jpg"; +$base64_1x1_jpeg="/9j/4AAQSkZJRgABAQEAYABgAAD//gA8Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2ODApLCBxdWFsaXR5ID0gMTAwCv/bAEMAAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/bAEMBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAf/AABEIAAEAAQMBEQACEQEDEQH/xAAfAAABBQEBAQEBAQAAAAAAAAAAAQIDBAUGBwgJCgv/xAC1EAACAQMDAgQDBQUEBAAAAX0BAgMABBEFEiExQQYTUWEHInEUMoGRoQgjQrHBFVLR8CQzYnKCCQoWFxgZGiUmJygpKjQ1Njc4OTpDREVGR0hJSlNUVVZXWFlaY2RlZmdoaWpzdHV2d3h5eoOEhYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4eLj5OXm5+jp6vHy8/T19vf4+fr/xAAfAQADAQEBAQEBAQEBAAAAAAAAAQIDBAUGBwgJCgv/xAC1EQACAQIEBAMEBwUEBAABAncAAQIDEQQFITEGEkFRB2FxEyIygQgUQpGhscEJIzNS8BVictEKFiQ04SXxFxgZGiYnKCkqNTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqCg4SFhoeIiYqSk5SVlpeYmZqio6Slpqeoqaqys7S1tre4ubrCw8TFxsfIycrS09TV1tfY2dri4+Tl5ufo6ery8/T19vf4+fr/2gAMAwEAAhEDEQA/AP8AP/oA/9k="; +#write file +$fd=fopen($file,"wb"); +if ($fd) { fputs($fd,base64_decode($base64_1x1_jpeg)); fclose($fd); } +#check file md5 +$md5=md5_file($file); +if ($md5!="07dd8594450e8c18ab8a79d7cb4573c7") { echo "md5 error".PHP_EOL;exit(1); } +#check jpeg properties +list($width, $height, $type, $attr) = getimagesize($file,$info); +if ($width!=1) { echo "width error".PHP_EOL;exit(1); } +if ($height!=1) { echo "height error".PHP_EOL;exit(1); } +if ($type!=2) { echo "type error".PHP_EOL;exit(1); } +if (!isset($info["APP0"])) { echo "APP0 error".PHP_EOL;exit(1); } + +#our iptc tags +$tags=array(); +$tags["2#105"]= "Tauren"; +$tags["2#120"]= "Tauren with Trunk"; +$tags["2#110"]= "Copyright 2004-2016, Blizzard"; +$tags["2#025"]= "Tauren, Chaman, Blizzard"; +$tags["2#090"]= "Thunder Bluffs"; +#feed iptc string for iptcembed +$iptc=''; +foreach ($tags as $tag => $string) { $rec=$tag[0]; $tag = substr($tag, 2); $iptc .= iptc_make_tag($rec, $tag, $string); } +#check iptc string md5 +if (md5(base64_encode($iptc))!="7056c4b3060f92a4f9e5b7d0caa61859") { echo "iptc md5 error".PHP_EOL;exit(1); } + +# +$content = iptcembed($iptc, $file,0); +if ($content === false) {echo "iptcembed error".PHP_EOL;exit(1); } +$fd=fopen($file2,"wb"); +if ($fd) { fputs($fd,$content); fclose($fd); } + +#check jpeg properties for new image with iptc tags +echo "new generated image with itpc tags : $file2".PHP_EOL; +$ret = getimagesize($file2,$info); +if ($ret===false) { echo "getimagesize error".PHP_EOL;exit(1); } +list($width, $height, $type, $attr) = $ret; +if ($width!=1) { echo "width error".PHP_EOL;exit(1); } +if ($height!=1) { echo "height error".PHP_EOL;exit(1); } +if ($type!=2) { echo "type error".PHP_EOL;exit(1); } +if (!isset($info["APP0"])) { echo "APP0 error".PHP_EOL;exit(1); } +if (!isset($info["APP13"])) { echo "APP13 error".PHP_EOL;exit(1); } + +$error=0; +$iptc_data_from_created_image = iptcparse($info['APP13']); +foreach ($tags as $tag => $string) { + #check if tag exists + if (!isset($iptc_data_from_created_image[$tag])) { + echo "error iptc tag $tag not found".PHP_EOL; + $error++; + } else { + #check value + if ($iptc_data_from_created_image[$tag][0]!=$string) { + echo "error tag $tag : bad value ($string != ".$iptc_data_from_created_image[$tag][0].")".PHP_EOL; + $error++; + } + } +} +#clean before exit +@unlink($file); +@unlink($file2); +if ($error==0) { echo "OK".PHP_EOL;exit(0);} +echo "something wrong: $error errors".PHP_EOL; +?> +--EXPECT-- +new generated image with itpc tags : 1x1_with_iptc_tags.jpg +OK +Done From 21f4316813e253574fa0b3abccf83257ba20c9cd Mon Sep 17 00:00:00 2001 From: Guillaume Degoulet Date: Wed, 30 Jan 2019 13:02:50 +0100 Subject: [PATCH 3/4] oops ! copy/paste error --- ext/standard/tests/image/iptcembed_002.phpt | 1 - 1 file changed, 1 deletion(-) diff --git a/ext/standard/tests/image/iptcembed_002.phpt b/ext/standard/tests/image/iptcembed_002.phpt index 4782b23836113..83862ae395484 100644 --- a/ext/standard/tests/image/iptcembed_002.phpt +++ b/ext/standard/tests/image/iptcembed_002.phpt @@ -90,4 +90,3 @@ echo "something wrong: $error errors".PHP_EOL; --EXPECT-- new generated image with itpc tags : 1x1_with_iptc_tags.jpg OK -Done From 1c0501a87b891568d1ffb3d769adb3d1273c16fc Mon Sep 17 00:00:00 2001 From: Guillaume Degoulet Date: Wed, 30 Jan 2019 15:03:47 +0100 Subject: [PATCH 4/4] add test description and catch fopen error properly --- ext/standard/tests/image/iptcembed_002.phpt | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/ext/standard/tests/image/iptcembed_002.phpt b/ext/standard/tests/image/iptcembed_002.phpt index 83862ae395484..ad0446cf62af1 100644 --- a/ext/standard/tests/image/iptcembed_002.phpt +++ b/ext/standard/tests/image/iptcembed_002.phpt @@ -3,6 +3,8 @@ iptcembed() valid jpg stream --FILE-- $string) { $rec=$tag[0]; $tag = substr($tag, 2); $iptc #check iptc string md5 if (md5(base64_encode($iptc))!="7056c4b3060f92a4f9e5b7d0caa61859") { echo "iptc md5 error".PHP_EOL;exit(1); } -# +#use iptcembed to get jpeg stream content with iptc tags $content = iptcembed($iptc, $file,0); + +#write new image with iptc tags if ($content === false) {echo "iptcembed error".PHP_EOL;exit(1); } $fd=fopen($file2,"wb"); if ($fd) { fputs($fd,$content); fclose($fd); } +else { echo "error cant write $file2".PHP_EOL;exit(1); } + #check jpeg properties for new image with iptc tags echo "new generated image with itpc tags : $file2".PHP_EOL;