From: Antony Dovgal Date: Mon, 12 Feb 2007 20:30:52 +0000 (+0000) Subject: MFH: fix #40109 (iptcembed fails on non-jfif jpegs) X-Git-Tag: php-5.2.2RC1~420 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=511463854b2ea520604ec22c0d0d80cc329727ae;p=php MFH: fix #40109 (iptcembed fails on non-jfif jpegs) --- diff --git a/NEWS b/NEWS index 30df68de7f..9530c3f9ab 100644 --- a/NEWS +++ b/NEWS @@ -9,6 +9,7 @@ PHP NEWS methods). (Tony) - Fixed bug #40428 (imagepstext() doesn't accept optional parameter). (Pierre) - Fixed bug #40410 (ext/posix does not compile on MacOS 10.3.9). (Tony) +- Fixed bug #40109 (iptcembed fails on non-jfif jpegs). (Tony) - Fixed bug #39836 (SplObjectStorage empty after unserialize). (Marcus) 08 Feb 2007, PHP 5.2.1 diff --git a/ext/standard/iptc.c b/ext/standard/iptc.c index 3b80a17b19..81844e7067 100644 --- a/ext/standard/iptc.c +++ b/ext/standard/iptc.c @@ -183,6 +183,7 @@ PHP_FUNCTION(iptcembed) unsigned int spool = 0, done = 0, inx, len; unsigned char *spoolbuf=0, *poi=0; struct stat sb; + zend_bool written = 0; switch(ZEND_NUM_ARGS()){ case 3: @@ -226,7 +227,8 @@ PHP_FUNCTION(iptcembed) if (spool < 2) { fstat(fileno(fp), &sb); - poi = spoolbuf = emalloc(len + sizeof(psheader) + sb.st_size + 1024); + poi = spoolbuf = safe_emalloc(1, len + sizeof(psheader) + sb.st_size + 1024, 1); + memset(poi, 0, len + sizeof(psheader) + sb.st_size + 1024 + 1); } if (php_iptc_get1(fp, spool, poi?&poi:0 TSRMLS_CC) != 0xFF) { @@ -264,6 +266,13 @@ PHP_FUNCTION(iptcembed) case M_APP0: /* APP0 is in each and every JPEG, so when we hit APP0 we insert our new APP13! */ + case M_APP1: + if (written) { + /* don't try to write the data twice */ + break; + } + written = 1; + php_iptc_skip_variable(fp, spool, poi?&poi:0 TSRMLS_CC); if (len & 1) len++; /* make the length even */