[kaffe] CVS kaffe (guilhem): Fix bug #55

Kaffe CVS cvs-commits at kaffe.org
Sat Sep 30 13:36:36 PDT 2006


PatchSet 7429 
Date: 2006/09/30 20:21:48
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Fix bug #55

2006-09-30  Guilhem Lavaux  <guilhem at kaffe.org>

        * kaffe/kaffevm/jar.c
        (getCentralDirCount): Look for the last signature into a larger block
        at the end of the file.

        Fix bug #55

Members: 
	ChangeLog:1.4929->1.4930 
	kaffe/kaffevm/jar.c:1.41->1.42 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4929 kaffe/ChangeLog:1.4930
--- kaffe/ChangeLog:1.4929	Tue Sep 26 20:13:28 2006
+++ kaffe/ChangeLog	Sat Sep 30 20:21:48 2006
@@ -1,3 +1,11 @@
+2006-09-30  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* kaffe/kaffevm/jar.c
+	(getCentralDirCount): Look for the last signature into a larger block
+	at the end of the file.
+
+	Fix bug #55
+
 2006-09-26  Guilhem Lavaux  <guilhem at kaffe.org>
 
 	* kaffe/kaffevm/jni/jni-refs.c:
Index: kaffe/kaffe/kaffevm/jar.c
diff -u kaffe/kaffe/kaffevm/jar.c:1.41 kaffe/kaffe/kaffevm/jar.c:1.42
--- kaffe/kaffe/kaffevm/jar.c:1.41	Sat Jul 15 11:10:31 2006
+++ kaffe/kaffe/kaffevm/jar.c	Sat Sep 30 20:21:52 2006
@@ -62,6 +62,12 @@
 static const char * JAR_ERROR_UNSUPPORTED_COMPRESSION      = "Unsupported compression in JAR file";
 
 /*
+ * This constant determines how large is the block in which we must
+ * look for the central directory end.
+ */
+#define MAX_CENTRAL_END_DISPLACEMENT 65536
+
+/*
  * The jarCache keeps a list of all the jarFiles cached in the system.
  * However, since some JAR files are opened and closed frequently we don't
  * actively flush unused files from the system unless there are more than
@@ -768,38 +774,48 @@
 	/* The central directory end is at the end of the file */
 	if( (pos = jarSeek(jf, (off_t)-FILE_SIZEOF_CENTRALEND, SEEK_END)) > 0 )
 	{
-		jarCentralDirectoryEnd cde;
+	  jarCentralDirectoryEnd cde;
+	  int displacement;
 
-		if( readJarHeader(jf, CENTRAL_END_SIGNATURE,
-				  &cde, FILE_SIZEOF_CENTRALEND) )
-		{
-			jarInstantiate(jf, (uint8 *)&cde,
-				       instantiateCentralDirEnd);
-			if( cde.nrOfEntriesInDirectory >
-			    (cde.sizeOfDirectory / FILE_SIZEOF_CENTRALDIR) )
-			{
-				jf->error = JAR_ERROR_ENTRY_COUNT_MISMATCH;
-			}
-			else if( cde.sizeOfDirectory > (unsigned)pos )
-			{
-				jf->error = JAR_ERROR_IMPOSSIBLY_LARGE_DIRECTORY;
-			}
-			else if( jarSeek(jf,
-					 (off_t)cde.offsetOfDirectory,
-					 SEEK_SET) >= 0 )
-			{
-				*out_dir_size = cde.sizeOfDirectory;
-				retval = cde.nrOfEntriesInDirectory;
-			}
-		}
-		else
-		{
-			jf->error = JAR_ERROR_NO_END;
-		}
+	  displacement = FILE_SIZEOF_CENTRALEND;
+	  while (!readJarHeader(jf, CENTRAL_END_SIGNATURE,
+				&cde, FILE_SIZEOF_CENTRALEND) )
+	    {
+	      if (displacement == MAX_CENTRAL_END_DISPLACEMENT)
+		{
+		  jf->error = JAR_ERROR_NO_END;
+		  return retval;
+		}
+	      
+	      displacement++;
+	      jarSeek(jf, (off_t)-displacement, SEEK_END);
+	    }
+
+	  jf->error = NULL;
+	  
+	  jarInstantiate(jf, (uint8 *)&cde,
+			 instantiateCentralDirEnd);
+	  if( cde.nrOfEntriesInDirectory >
+	      (cde.sizeOfDirectory / FILE_SIZEOF_CENTRALDIR) )
+	    {
+	      jf->error = JAR_ERROR_ENTRY_COUNT_MISMATCH;
+	    }
+	  else if( cde.sizeOfDirectory > (unsigned)pos )
+	    {
+	      jf->error = JAR_ERROR_IMPOSSIBLY_LARGE_DIRECTORY;
+	    }
+	  else if( jarSeek(jf,
+			   (off_t)cde.offsetOfDirectory,
+			   SEEK_SET) >= 0 )
+	    {
+	      *out_dir_size = cde.sizeOfDirectory;
+	      retval = cde.nrOfEntriesInDirectory;
+	    }
+	  
 	}
 	return( retval );
 }
-
+	
 /*
  * Read the central directory records from the file
  */




More information about the kaffe mailing list