diff options
author | Wil Mahan <wmahan@gmail.com> | 2005-11-08 19:10:39 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2005-11-08 19:10:39 +0000 |
commit | 1c57e8763bb9fea0aea2bbe98883b56c3248c9c5 (patch) | |
tree | 02f067118f66733f528d5903be6307b87e0fb3e8 /gcc/java/zextract.c | |
parent | a8bfea9ca9505c79fab6ad75c6d90bccbb485b22 (diff) | |
download | gcc-1c57e8763bb9fea0aea2bbe98883b56c3248c9c5.zip gcc-1c57e8763bb9fea0aea2bbe98883b56c3248c9c5.tar.gz gcc-1c57e8763bb9fea0aea2bbe98883b56c3248c9c5.tar.bz2 |
re PR java/23617 (Out of memory when classpath contains jar file with zip-style comment)
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.
From-SVN: r106648
Diffstat (limited to 'gcc/java/zextract.c')
-rw-r--r-- | gcc/java/zextract.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/gcc/java/zextract.c b/gcc/java/zextract.c index c10b952..461cfbd 100644 --- a/gcc/java/zextract.c +++ b/gcc/java/zextract.c @@ -1,7 +1,7 @@ /* Handle a .class file embedded in a .zip archive. This extracts a member from a .zip file, but does not handle uncompression (since that is not needed for classes.zip). - Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004 + Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. This file is part of GCC. @@ -287,6 +287,25 @@ 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 |