Bug 23617

Summary: Out of memory when classpath contains jar file with zip-style comment
Product: gcc Reporter: Wil Mahan <wmahan>
Component: javaAssignee: Not yet assigned to anyone <unassigned>
Severity: normal CC: bflat1, gcc-bugs, java-prs, tromey
Priority: P2 Keywords: ice-on-valid-code, patch
Version: 4.0.1   
Target Milestone: 4.0.3   
URL: http://gcc.gnu.org/ml/java-patches/2005-q3/msg00274.html
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2005-08-29 04:56:23
Attachments: Possible fix for gcc/java/zextract.c against latest CVS

Description Wil Mahan 2005-08-29 04:50:25 UTC
When trying to compile a file with Debian's gcj 4.0.1-2, I got an error like this:

HelloWorld.java:0: error: malformed .zip archive in CLASSPATH:

jc1: out of memory allocating 1342179073 bytes after a total of 389120 bytes

It turns out the .jar file the error mentions has a zipfile comment. (JAR is
based on the zip format, which allows an variable-length comment at the end of
the file.) The compilation was successful when I removed the jar file from the

Here's a simple test case to summarize: with gcj 4.0.1, the Info-ZIP utility,
and any class, say HelloWorld.java:

$ jar -cf test.jar; gcj -classpath test.jar HelloWorld.java # works fine

$ jar -cf test.jar; echo "some comment" | zip -z test.jar; gcj -classpath
test.jar HelloWorld.java
enter new zip file comment (end with .):

jc1: out of memory allocating 1663067502 bytes after a total of 135168 bytes

This problem is similar to bug 13020 for FastJar. I came up with a similar
solution: modifying zextract.c to check for a zipfile comment, and if necessary
scan backwards for the end-central-header signature. Unfortunately I haven't had
a chance to test the change compiled into gcc, although it appears to work in a
small test program.
Comment 1 Wil Mahan 2005-08-29 04:53:44 UTC
Created attachment 9611 [details]
Possible fix for gcc/java/zextract.c against latest CVS
Comment 2 Andrew Pinski 2005-08-29 04:56:23 UTC
Confirmed, I thought there was already a bug about this (not the fast jar one you pointed out) but looks 
like there is not.

Could you sent your patch to java-patches@ and gcc-patches@ with a changelog and a comment and 
what this patch does?
Comment 3 Wil Mahan 2005-08-29 06:02:06 UTC
Done. I expected a bug to already have been reported about this, but I couldn't
find one. Thanks for the fast response!
Comment 4 Tom Tromey 2005-10-03 14:26:10 UTC
*** Bug 24162 has been marked as a duplicate of this bug. ***
Comment 5 CVS Commits 2005-10-24 17:22:48 UTC
Subject: Bug 23617

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-4_0-branch
Changes by:	tromey@gcc.gnu.org	2005-10-24 17:22:41

Modified files:
	gcc/java       : ChangeLog zextract.c 

Log message:
	2005-10-24  Wil Mahan  <wmahan@gmail.com>
	PR java/23617
	* zextract.c (read_zip_archive): Fix out of memory error when
	reading jar files with zip-style comments.


Comment 6 Tom Tromey 2005-11-08 19:10:44 UTC
Subject: Bug 23617

Author: tromey
Date: Tue Nov  8 19:10:39 2005
New Revision: 106648

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=106648
2005-11-08  Wil Mahan  <wmahan@gmail.com>

	PR java/23617
	* zextract.c (read_zip_archive): Fix out of memory error when
	reading jar files with zip-style comments.


Comment 7 Tom Tromey 2005-11-08 19:11:52 UTC
Fix is on 4.0 branch and trunk.