This is the mail archive of the java-patches@sourceware.cygnus.com mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

ZipFile patch for PR 25



I'm about to commit this fix to PR 25.  It computes data offsets
correctly for ZipEntry objects.

1999-11-07  Anthony Green  <green@cygnus.com>

	* java/util/zip/ZipFile.java: Compute the offset of the ZipEntry
	data correctly.

Index: libjava/java/util/zip/ZipFile.java
===================================================================
RCS file: /cvs/java/libgcj/libjava/java/util/zip/ZipFile.java,v
retrieving revision 1.4
diff -u -r1.4 ZipFile.java
--- ZipFile.java        1999/08/18 14:16:41     1.4
+++ ZipFile.java        1999/11/07 08:18:34
@@ -122,10 +122,13 @@
   public InputStream getInputStream(ZipEntry ze)  throws IOException
   {
     byte[] buffer = new byte[(int) ze.getSize()];
-    int data_offset = ZipConstants.LOCAL_FILE_HEADER_SIZE + name.length();
-    if (ze.extra != null)
-      data_offset += ze.extra.length;
-    file.seek(ze.relativeOffset + data_offset);
+
+    /* Read the size of the extra field, and skip to the start of the
+       data.  */
+    file.seek (ze.relativeOffset + ZipConstants.LOCAL_FILE_HEADER_SIZE - 2);
+    int extraFieldLength = readu2();
+    file.skipBytes (ze.getName().length() + extraFieldLength);
+
     file.readFully(buffer);
 
     InputStream is = new ByteArrayInputStream (buffer);

AG

-- 
Anthony Green                                               Cygnus Solutions
                                                       Sunnyvale, California

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]