public inbox for java-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Patch: out of memory error when reading jar files with zip comments
@ 2005-08-29  6:00 Wil Mahan
  2005-10-03 16:56 ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Wil Mahan @ 2005-08-29  6:00 UTC (permalink / raw)
  To: java-patches, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 879 bytes --]

Hi,

When gcj's CLASSPATH contains a .jar file with a zip-style comment, I
get an error like this:

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

A test case is:

jar -cf test.jar   # create an empty jar file
echo "some comment" | zip -z test.jar  # add a zip comment
gcj -classpath test.jar Foo.java   # fails with above message

The problem is that the code for reading .jar files (which are really
special .zip files) does not handle zip-style comments. I just
submitted PR java/23617 regarding this issue. Attached is my attempt to
fix it by scanning back through the comment from the end, until the
end-central-header section is reached.

Thanks,
Wil

2005-08-29  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.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: zipcomment.patch --]
[-- Type: text/x-patch; name="zipcomment.patch", Size: 1260 bytes --]

Index: zextract.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/java/zextract.c,v
retrieving revision 1.20
diff -u -d -p -r1.20 zextract.c
--- zextract.c	25 Jun 2005 00:33:05 -0000	1.20
+++ zextract.c	29 Aug 2005 05:50:58 -0000
@@ -287,6 +287,21 @@ read_zip_archive (ZipFile *zipf)
     return -1;
   if (read (zipf->fd, buffer, ECREC_SIZE+4) != ECREC_SIZE+4)
     return -2;
+  if (buffer[0] != 'P' || strncmp ((const char *) &buffer[1], END_CENTRAL_SIG, 3)) {
+    /* We could not find the end-central-header signature, probably
+       because a zipfile comment is present. Scan backwards until we
+       find the signature. */
+    if (lseek (zipf->fd, (long)(-ECREC_SIZE), SEEK_END) <= 0)
+      return -2;
+    while (buffer[0] != 'P' || strncmp ((const char *) &buffer[1], END_CENTRAL_SIG, 3)) {
+      if (lseek (zipf->fd, -5, SEEK_CUR) < 0)
+        return -2;
+      if (read (zipf->fd, buffer, 4) != 4)
+        return -2;
+    } 
+    if (read (zipf->fd, buffer + 4, ECREC_SIZE) != ECREC_SIZE)
+      return -2;
+  }
   zipf->count = makeword((const uch *) &buffer[TOTAL_ENTRIES_CENTRAL_DIR]);
   zipf->dir_size = makelong((const uch *) &buffer[SIZE_CENTRAL_DIRECTORY]);
 #define ALLOC xmalloc

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: out of memory error when reading jar files with zip comments
  2005-08-29  6:00 Patch: out of memory error when reading jar files with zip comments Wil Mahan
@ 2005-10-03 16:56 ` Tom Tromey
  2005-10-17 13:57   ` Mark Wielaard
  0 siblings, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2005-10-03 16:56 UTC (permalink / raw)
  To: Wil Mahan; +Cc: java-patches, gcc-patches

>>>>> "Wil" == Wil Mahan <wmahan@gmail.com> writes:

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

What is the status of this patch?  Is the paperwork not ready?

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: out of memory error when reading jar files with zip comments
  2005-10-03 16:56 ` Tom Tromey
@ 2005-10-17 13:57   ` Mark Wielaard
  2005-10-17 18:45     ` Tom Tromey
  2005-10-24 17:22     ` Tom Tromey
  0 siblings, 2 replies; 7+ messages in thread
From: Mark Wielaard @ 2005-10-17 13:57 UTC (permalink / raw)
  To: tromey; +Cc: Wil Mahan, java-patches, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 491 bytes --]

On Mon, 2005-10-03 at 10:50 -0600, Tom Tromey wrote:
> >>>>> "Wil" == Wil Mahan <wmahan@gmail.com> writes:
> 
> Wil> 2005-08-29  Wil Mahan  <wmahan@gmail.com>
> Wil> 	PR java/23617
> Wil> 	* zextract.c (read_zip_archive): Fix out of memory error when
> Wil> 	reading jar files with zip-style comments.
> 
> What is the status of this patch?  Is the paperwork not ready?

Paperwork is ready now. Thanks Wil.
Tom, if you agree with this patch can you commit it?

Cheers,

Mark

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: out of memory error when reading jar files with zip comments
  2005-10-17 13:57   ` Mark Wielaard
@ 2005-10-17 18:45     ` Tom Tromey
  2005-10-24 17:22     ` Tom Tromey
  1 sibling, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2005-10-17 18:45 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Wil Mahan, java-patches, gcc-patches

>>>>> "Mark" == Mark Wielaard <mark@klomp.org> writes:

Mark> Paperwork is ready now. Thanks Wil.
Mark> Tom, if you agree with this patch can you commit it?

The tree is in a slushy state.  It can go in 4.0.x though.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: out of memory error when reading jar files with zip comments
  2005-10-17 13:57   ` Mark Wielaard
  2005-10-17 18:45     ` Tom Tromey
@ 2005-10-24 17:22     ` Tom Tromey
  2005-11-09  7:45       ` Ranjit Mathew
  1 sibling, 1 reply; 7+ messages in thread
From: Tom Tromey @ 2005-10-24 17:22 UTC (permalink / raw)
  To: Mark Wielaard; +Cc: Wil Mahan, java-patches, gcc-patches

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

I'm finally checking this in on the 4.0 branch.
It should go in the trunk as well a bit later.

Tom

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: out of memory error when reading jar files with zip comments
  2005-10-24 17:22     ` Tom Tromey
@ 2005-11-09  7:45       ` Ranjit Mathew
  2005-11-09 18:17         ` Tom Tromey
  0 siblings, 1 reply; 7+ messages in thread
From: Ranjit Mathew @ 2005-11-09  7:45 UTC (permalink / raw)
  To: tromey; +Cc: Wil Mahan, java-patches, gcc-patches

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

Tom Tromey wrote:
> Wil> 2005-08-29  Wil Mahan  <wmahan@gmail.com>
> Wil> PR java/23617
> Wil> * zextract.c (read_zip_archive): Fix out of memory error when
> Wil> reading jar files with zip-style comments.
> 
> I'm finally checking this in on the 4.0 branch.
> It should go in the trunk as well a bit later.

Now that you've checked this into trunk, I should
note that it also seems to fix the failure for Jacks
testcase "non-jls-zip-2".

Ranjit.

- --
Ranjit Mathew      Email: rmathew AT gmail DOT com

Bangalore, INDIA.    Web: http://ranjitmathew.hostingzero.com/


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFDcajyYb1hx2wRS48RAgK9AJ9hvdRi2V7k1kjQCOaDh6a5r0wuqgCdHhvn
Bo2JCZw6umXakDj4B5r3p2U=
=Qji6
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Patch: out of memory error when reading jar files with zip comments
  2005-11-09  7:45       ` Ranjit Mathew
@ 2005-11-09 18:17         ` Tom Tromey
  0 siblings, 0 replies; 7+ messages in thread
From: Tom Tromey @ 2005-11-09 18:17 UTC (permalink / raw)
  To: Ranjit Mathew; +Cc: Wil Mahan, java-patches

>>>>> "Ranjit" == Ranjit Mathew <rmathew@gmail.com> writes:

Ranjit> Now that you've checked this into trunk, I should
Ranjit> note that it also seems to fix the failure for Jacks
Ranjit> testcase "non-jls-zip-2".

Thanks for the reminder.  I'm checking this in on the trunk and the
4.0 branch.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>

	* testsuite/libjava.jacks/jacks.xfail (non-jls-zip-2): Now
	passes.

Index: testsuite/libjava.jacks/jacks.xfail
===================================================================
--- testsuite/libjava.jacks/jacks.xfail	(revision 106647)
+++ testsuite/libjava.jacks/jacks.xfail	(working copy)
@@ -686,4 +686,3 @@
 non-jls-jsr41.4-loop-7
 non-jls-jsr41.4-loop-8
 non-jls-jsr41.4-loop-9
-non-jls-zip-2

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2005-11-09 18:17 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-08-29  6:00 Patch: out of memory error when reading jar files with zip comments Wil Mahan
2005-10-03 16:56 ` Tom Tromey
2005-10-17 13:57   ` Mark Wielaard
2005-10-17 18:45     ` Tom Tromey
2005-10-24 17:22     ` Tom Tromey
2005-11-09  7:45       ` Ranjit Mathew
2005-11-09 18:17         ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).