ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject cvs commit: ant/src/main/org/apache/tools/zip ZipEntry.java ZipFile.java
Date Thu, 03 Jul 2003 15:38:40 GMT
bodewig     2003/07/03 08:38:40

  Modified:    src/main/org/apache/tools/zip ZipEntry.java ZipFile.java
  Log:
  Improve algorithm that searches for the central directory - don't get fooled by signatures
appearing inside payload.
  
  Revision  Changes    Path
  1.11      +2 -2      ant/src/main/org/apache/tools/zip/ZipEntry.java
  
  Index: ZipEntry.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipEntry.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ZipEntry.java	3 Jul 2003 15:00:36 -0000	1.10
  +++ ZipEntry.java	3 Jul 2003 15:38:39 -0000	1.11
  @@ -417,7 +417,7 @@
        * @since 1.10
        */
       public boolean isDirectory() {
  -	return getName().endsWith("/");
  +        return getName().endsWith("/");
       }
   
       protected void setName(String name) {
  
  
  
  1.4       +39 -11    ant/src/main/org/apache/tools/zip/ZipFile.java
  
  Index: ZipFile.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/zip/ZipFile.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ZipFile.java	3 Jul 2003 14:59:59 -0000	1.3
  +++ ZipFile.java	3 Jul 2003 15:38:39 -0000	1.4
  @@ -320,15 +320,42 @@
           }
       }
   
  +    private static final int MIN_EOCD_SIZE =
  +        /* end of central dir signature    */ 4 +
  +        /* number of this disk             */ 2 +
  +        /* number of the disk with the     */   +
  +        /* start of the central directory  */ 2 +
  +        /* total number of entries in      */   +
  +        /* the central dir on this disk    */ 2 +
  +        /* total number of entries in      */   +
  +        /* the central dir                 */ 2 +
  +        /* size of the central directory   */ 4 +
  +        /* offset of start of central      */   +
  +        /* directory with respect to       */   +
  +        /* the starting disk number        */ 4 +
  +        /* zipfile comment length          */ 2;
  +
  +    private static final int CFD_LOCATOR_OFFSET =
  +        /* end of central dir signature    */ 4 +
  +        /* number of this disk             */ 2 +
  +        /* number of the disk with the     */   +
  +        /* start of the central directory  */ 2 +
  +        /* total number of entries in      */   +
  +        /* the central dir on this disk    */ 2 +
  +        /* total number of entries in      */   +
  +        /* the central dir                 */ 2 +
  +        /* size of the central directory   */ 4;
  +
       /**
  -     * Searches for the first occurence of the central file header
  -     * signature.
  +     * Searches for the "End of central dir record", parses
  +     * it and positions the stream at the first central directory
  +     * record.
        */
       private void positionAtCentralDirectory() 
           throws IOException, ZipException {
  -        archive.seek(0);
  -        int off = 0;
  -        byte[] sig = ZipOutputStream.CFH_SIG.getBytes();
  +        long off = archive.length() - MIN_EOCD_SIZE;
  +        archive.seek(off);
  +        byte[] sig = ZipOutputStream.EOCD_SIG.getBytes();
           int curr = archive.read();
           boolean found = false;
           while (curr != -1) {
  @@ -344,16 +371,17 @@
                           }
                       }
                   }
  -                archive.seek(++off);
  -            } else {
  -                off++;
               }
  +            archive.seek(--off);
               curr = archive.read();
           }
           if (!found) {
               throw new ZipException("archive is not a ZIP archive");
           }
  -        archive.seek(off);
  +        archive.seek(off + CFD_LOCATOR_OFFSET);
  +        byte[] cfdOffset = new byte[4];
  +        archive.readFully(cfdOffset);
  +        archive.seek((new ZipLong(cfdOffset)).getValue());
       }
   
       /**
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message