Java Zip extraction gets random "invalid stored block length" exceptions

  • I’m using Java to extract files from a zip as part of a automated data import operation. This has been working pretty well for nearly a year, but now I’m seeing sporadic ZipExceptions that indicate “invalid stored block length”. It extracts all the files just fine, even logging every single file after extracting it, so as a band-aid I’m just trapping the single “block length” error and ignoring it, but that’s inelegant at best. I’d like to know why it’s happening.- The zip files are created on a remote system by another automated process. Our system downloads that zip, extracts the contents, and imports it. The entire system works as fine as frog hair, except for these spurrious glitches during extraction.

  • Because I don’t know what else to do, a simplified version of the relevant section of our system appears below. Thanks for your time!..

p=fully qualified path to working directory

basename=name of zip file, sans “.zip”

log("- Extracting ZIP to "+p, “+”);

String zFile=p+baseName+“.zip”;

try {

BufferedOutputStream outFile=null;

FileInputStream fis=new FileInputStream(zFile);

ZipInputStream zis=new ZipInputStream(new BufferedInputStream(fis));

ZipEntry entry;

while((entry=zis.getNextEntry())!=null) {

	int count;

	byte data[]=new byte[2048];

	String entName=entry.getName();

	FileOutputStream fos=new FileOutputStream(p+entName);

	outFile=new BufferedOutputStream(fos, 2048);

	while ((count=zis.read(data, 0, 2048))!=-1) outFile.write(data, 0, count);

	outFile.flush();

	outFile.close();

	log("  \""+srcFile+"\"");

} // while((entry...

zis.close();

log("= Extracted", "-");

return rtnval;

} catch(Exception e) {

log("*** "+e.toString()+" ***", "0");

e.printStackTrace();

}

Subject: SOLVED: Java Zip extraction gets random “invalid stored block length” exceptions…

  • This was an improperly created ZIP file that contained more files in the manifest than the ZIP actualy contained.