Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:43289 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 50474 invoked from network); 10 Mar 2009 11:16:24 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 10 Mar 2009 11:16:24 -0000 Authentication-Results: pb1.pair.com header.from=mmcnicklebugs@googlemail.com; sender-id=pass; domainkeys=bad Authentication-Results: pb1.pair.com smtp.mail=mmcnicklebugs@googlemail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain googlemail.com designates 209.85.219.166 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: mmcnicklebugs@googlemail.com X-Host-Fingerprint: 209.85.219.166 mail-ew0-f166.google.com Received: from [209.85.219.166] ([209.85.219.166:46181] helo=mail-ew0-f166.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 5C/FA-30036-70C46B94 for ; Tue, 10 Mar 2009 06:16:24 -0500 Received: by ewy10 with SMTP id 10so1089067ewy.23 for ; Tue, 10 Mar 2009 04:16:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:content-type :date:message-id:mime-version:x-mailer; bh=TW3ACh2NJ9zpUS0Dz3EZx3m+TtQmSlqDiTjpmcb3n78=; b=jkohqYf4fjK+H928HZy2fz00ev172B0FOhd26SaShjsCii2I1H1enP8peJ1YlTlDN4 yd+Y8OY4ZpVFk8otPxCpZ7+vZDRSHcP4ZnYtr3fhKXM0XCziZtvFjfFjfi76gszGAeyU r1FuqG0qbbyTvPvuhOXDkvrwSdSHI44Qss/c0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=googlemail.com; s=gamma; h=subject:from:to:content-type:date:message-id:mime-version:x-mailer; b=anx/7gVFUbbUrxM2TfOv67YthexUwc3kJcOnGShEzCd/BFwdUu5wUIgniyaQ0F0uDH CP2oL5Gk6i0b3em/zcoUWFvoBmCvvbIoDKtklUs/KdpB/BYJPyQOFGa+i/JLyJIwExB7 JaJnF2xxJqHQYsWgxRD0M/g4RrdvsrgTIkTZ8= Received: by 10.216.11.66 with SMTP id 44mr2605507wew.146.1236683780764; Tue, 10 Mar 2009 04:16:20 -0700 (PDT) Received: from ?192.168.1.5? (82-41-240-108.cable.ubr04.sgyl.blueyonder.co.uk [82.41.240.108]) by mx.google.com with ESMTPS id f4sm3914278nfh.46.2009.03.10.04.16.19 (version=SSLv3 cipher=RC4-MD5); Tue, 10 Mar 2009 04:16:20 -0700 (PDT) To: internals@lists.php.net Content-Type: multipart/mixed; boundary="=-LGWUadtFoSt1dGurztqf" Date: Tue, 10 Mar 2009 11:17:13 +0000 Message-ID: <1236683833.23999.18.camel@vimes> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Subject: [PATCH] Bug #45799 - imagepng() crashes on empty image From: mmcnicklebugs@googlemail.com (Martin McNickle) --=-LGWUadtFoSt1dGurztqf Content-Type: text/plain Content-Transfer-Encoding: 7bit Hi all, I've created a simple patch for Bug #45799 [1] It employs a simple check to see if there are any colors associated with the image before outputting the PNG header. The patch is against CVS 5.3, shown below for convenience. I can create patches for the other branches if required. The tests pass. This is my first patch to PHP, so I've done anything wrong, give me some pointers as to how to fix it. Thanks, -- Martin McNickle [1] http://bugs.php.net/bug.php?id=45799 Index: ext/gd/libgd/gd_png.c =================================================================== RCS file: /repository/php-src/ext/gd/libgd/gd_png.c,v retrieving revision 1.17.4.2.2.5.2.3 diff -u -r1.17.4.2.2.5.2.3 gd_png.c --- ext/gd/libgd/gd_png.c 14 Jan 2009 10:16:15 -0000 1.17.4.2.2.5.2.3 +++ ext/gd/libgd/gd_png.c 10 Mar 2009 11:12:02 -0000 @@ -650,6 +650,12 @@ png_set_PLTE(png_ptr, info_ptr, palette, colors); } + if (colors <= 0 && !im->trueColor) { + php_gd_error("gd-png error: Invalid number of colors in palette./martin"); + png_destroy_write_struct (&png_ptr, &info_ptr); + return; + } + /* write out the PNG header info (everything up to first IDAT) */ png_write_info(png_ptr, info_ptr); --=-LGWUadtFoSt1dGurztqf Content-Disposition: attachment; filename=libgd.patch Content-Type: text/x-patch; name=libgd.patch; charset=utf-8 Content-Transfer-Encoding: 7bit Index: ext/gd/libgd/gd_png.c =================================================================== RCS file: /repository/php-src/ext/gd/libgd/gd_png.c,v retrieving revision 1.17.4.2.2.5.2.3 diff -u -r1.17.4.2.2.5.2.3 gd_png.c --- ext/gd/libgd/gd_png.c 14 Jan 2009 10:16:15 -0000 1.17.4.2.2.5.2.3 +++ ext/gd/libgd/gd_png.c 10 Mar 2009 11:12:02 -0000 @@ -650,6 +650,12 @@ png_set_PLTE(png_ptr, info_ptr, palette, colors); } + if (colors <= 0 && !im->trueColor) { + php_gd_error("gd-png error: Invalid number of colors in palette./martin"); + png_destroy_write_struct (&png_ptr, &info_ptr); + return; + } + /* write out the PNG header info (everything up to first IDAT) */ png_write_info(png_ptr, info_ptr); --=-LGWUadtFoSt1dGurztqf--