[PATCH] prevent null-pointer dereference

Georg Gottleuber <[email protected]> Wed, 14 Dec 2011 13:24:08 +0100
Newsgroups gmane.comp.printing.ghostscript.jbig2dec.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------050900030807020602050102
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi,

I found a NULL-pointer dereference at jbig2_image_clone in
jbig2_image.c:61 with current git version (c29b63557cb191f)

It occurs if jbig2dec is called with <global_stream> <page_stream> and
no page segment with image description is inside <page_stream>.
Function jbig2_page_out tries to jbig2_image_clone with a null-pointer.

The attached patch should fix this. Please merge it.

Regards,
Georg

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.17 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk7olWgACgkQ5sLITM1qIaLKjQCgnRxPGrtPUMxyAINcN8CrNt8i
HRkAn2Q2v+38beGn3gUHrLKEu65oD4B7
=WUB9
-----END PGP SIGNATURE-----

--------------050900030807020602050102
Content-Type: text/x-patch;
 name="0001-prevent-null-pointer-dereference-in-jbig2_image.c-63.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename*0="0001-prevent-null-pointer-dereference-in-jbig2_image.c-63.pa";
 filename*1="tch"

diff --git a/jbig2_image.c b/jbig2_image.c
index 7037d71..45db3b3 100644
--- a/jbig2_image.c
+++ b/jbig2_image.c
@@ -60,7 +60,9 @@ Jbig2Image* jbig2_image_new(Jbig2Ctx *ctx, int width, int height)
 /* clone an image pointer by bumping its reference count */
 Jbig2Image* jbig2_image_clone(Jbig2Ctx *ctx, Jbig2Image *image)
 {
-	image->refcount++;
+	if (image != NULL)
+		image->refcount++;
+
 	return image;
 }

--------------050900030807020602050102
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
jbig2-dev mailing list
[email protected]
http://ghostscript.com/cgi-bin/mailman/listinfo/jbig2-dev

--------------050900030807020602050102--