This is the mail archive of the java-patches@gcc.gnu.org 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]
Other format: [Raw text]

FYI: Manifest reading of JarFile


Hi,

The following was found by one of the JRVM devlopers (Julian Dolby) and
committed to Classpath a while ago. When a JarFile is opened with the
verify flag on then the Manifest should be available if it is never
explicitly used by the program and the file has been closed again.

2003-02-07  Mark Wielaard  <mark@klomp.org>
                                                                                
        * java/util/jar/JarFile.java (JarFile(String, boolean)): Read manifest
        when verify is true.
        (JarFile(File, boolean)): Likewise.
        (manifestRead): Set manifestRead field correctly.

I am committing this to branch and mainline.

This make the Eclipse online Update Manger work. I have successfully
used this to install the WebDav support that was needed for the Sftp
File Synchronization plugin (which works flawlessly under gij BTW).
<http://www.klomp.org/eclipse-plugins/org.klomp.eclipse.team.sftp/>

Note that we don't actually verify the Manifest entry (and to run
Eclipse you have to disable the byte code verifyer) so this is certainly
not recommended for loading arbitraty (untrusted) classees from the net.

Cheers,

Mark
Index: java/util/jar/JarFile.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/util/jar/JarFile.java,v
retrieving revision 1.10
diff -u -r1.10 JarFile.java
--- java/util/jar/JarFile.java	3 Dec 2002 22:06:30 -0000	1.10
+++ java/util/jar/JarFile.java	7 Feb 2003 21:20:41 -0000
@@ -1,5 +1,5 @@
 /* JarFile.java - Representation of a jar file
-   Copyright (C) 2000 Free Software Foundation, Inc.
+   Copyright (C) 2000, 2003 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -71,10 +71,10 @@
    */
   private Manifest manifest;
 
-  /** Wether to verify the manifest and all entries. */
+  /** Whether to verify the manifest and all entries. */
   private boolean verify;
 
-  /** Wether the has already been loaded. */
+  /** Whether the has already been loaded. */
   private boolean manifestRead = false;
 
   // Constructors
@@ -109,6 +109,11 @@
     FileNotFoundException, IOException
   {
     super(fileName);
+    if (verify)
+      {
+	manifest = readManifest();
+	verify();
+      }
   }
 
   /**
@@ -141,6 +146,11 @@
     IOException
   {
     super(file);
+    if (verify)
+      {
+	manifest = readManifest();
+	verify();
+      }
   }
 
   /**
@@ -165,6 +175,11 @@
     FileNotFoundException, IOException, IllegalArgumentException
   {
     super(file, mode);
+    if (verify)
+      {
+	manifest = readManifest();
+	verify();
+      }
   }
 
   // Methods
@@ -196,15 +211,18 @@
 	if (manEntry != null)
 	  {
 	    InputStream in = super.getInputStream(manEntry);
+	    manifestRead = true;
 	    return new Manifest(in);
 	  }
 	else
 	  {
+	    manifestRead = true;
 	    return null;
 	  }
       }
     catch (IOException ioe)
       {
+	manifestRead = true;
 	return null;
       }
   }

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