[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [cp-patches] Patch: minor ZipFile improvement
From: |
Anthony Green |
Subject: |
Re: [cp-patches] Patch: minor ZipFile improvement |
Date: |
Thu, 15 Sep 2005 08:07:48 -0700 |
On Thu, 2005-09-15 at 07:27 -0600, Tom Tromey wrote:
> Actually we ought to try reading until we get all 4 bytes or see EOF.
> A short read is valid and not an error.
Ok, how about this?
2005-09-14 Anthony Green <address@hidden>
* java/util/zip/ZipFile.java (checkZipFile): Make sure we read all
4 bytes of the magic number.
Index: java/util/zip/ZipFile.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipFile.java,v
retrieving revision 1.26
diff -u -r1.26 ZipFile.java
--- java/util/zip/ZipFile.java 13 Sep 2005 22:19:15 -0000 1.26
+++ java/util/zip/ZipFile.java 15 Sep 2005 15:03:56 -0000
@@ -144,9 +144,18 @@
private void checkZipFile() throws IOException, ZipException
{
byte[] magicBuf = new byte[4];
- raf.read(magicBuf);
+ boolean validRead = true;
- if (readLeInt(magicBuf, 0) != LOCSIG)
+ try
+ {
+ raf.readFully (magicBuf);
+ }
+ catch (EOFException)
+ {
+ validRead = false;
+ }
+
+ if (validRead == false || readLeInt(magicBuf, 0) != LOCSIG)
{
raf.close();
throw new ZipException("Not a valid zip file");