From 5840ee8a1f9b0f7b88a449fd60c253f2f0e83b64 Mon Sep 17 00:00:00 2001 From: "wtc%google.com" Date: Fri, 5 Sep 2008 23:14:24 +0000 Subject: [PATCH] Bug 302670: add an extra dummy byte at the end to support zlib 1.1.4. r=nelson. git-svn-id: svn://10.0.0.236/trunk@254071 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/security/nss/lib/jar/jarfile.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/mozilla/security/nss/lib/jar/jarfile.c b/mozilla/security/nss/lib/jar/jarfile.c index fc3ed2ae93e..9ba5902e624 100644 --- a/mozilla/security/nss/lib/jar/jarfile.c +++ b/mozilla/security/nss/lib/jar/jarfile.c @@ -360,7 +360,8 @@ static int jar_physical_inflate unsigned long prev_total, ochunk, tin; - if ((inbuf = (char *) PORT_ZAlloc (ICHUNK)) == NULL) + /* Raw inflate in zlib 1.1.4 needs an extra dummy byte at the end */ + if ((inbuf = (char *) PORT_ZAlloc (ICHUNK + 1)) == NULL) return JAR_ERR_MEMORY; if ((outbuf = (char *) PORT_ZAlloc (OCHUNK)) == NULL) @@ -400,6 +401,12 @@ static int jar_physical_inflate at += chunk; + if (at == length) + { + /* add an extra dummy byte at the end */ + inbuf[chunk++] = 0xDD; + } + zs.next_in = (Bytef *) inbuf; zs.avail_in = chunk; zs.avail_out = OCHUNK; @@ -676,17 +683,16 @@ static int jar_extract_mf (JAR *jar, jarArch format, JAR_FILE fp, char *ext) continue; } - if (phy->length == 0) + if (phy->length == 0 || phy->length > 0xFFFF) { - /* manifest files cannot be zero length! */ + /* manifest files cannot be zero length or too big! */ + /* the 0xFFFF limit is per J2SE SDK */ return JAR_ERR_CORRUPT; } /* Read in the manifest and parse it */ - /* limit is per J2SE SDK */ - if (phy->length <= 0xFFFF) { - manifest = (char ZHUGEP *) PORT_ZAlloc (phy->length + 1); - } + /* Raw inflate in zlib 1.1.4 needs an extra dummy byte at the end */ + manifest = (char ZHUGEP *) PORT_ZAlloc (phy->length + 1); if (manifest) { JAR_FSEEK (fp, phy->offset, (PRSeekWhence)0); @@ -702,6 +708,8 @@ static int jar_extract_mf (JAR *jar, jarArch format, JAR_FILE fp, char *ext) if (phy->compression == 8) { length = phy->length; + /* add an extra dummy byte at the end */ + manifest[length++] = 0xDD; status = jar_inflate_memory ((unsigned int) phy->compression, &length, phy->uncompressed_length, &manifest);