What might explain an "invalid stored block lengths" error?
Asked Answered
B

1

7

I am running a Rails (3.2.3) application with Ruby 1.9.3p194 on the basic Ubuntu lucid32 image in a Vagrant virtual box. The virtual box is running on Leopard, for what it's worth. I'm trying to use rubyzip in the application to decompress a zip archive - 2009_da_lmp.zip. Using code directly from examples in the rubyzip repository, I can confirm that I can list the archive file contents:

#f is the absolute path to 2009_da_lmp.zip (string)
Zip::ZipFile.open(f) { |zf| zf.entries[0] }  
 => 20090101_da_lmp.csv #that is indeed a file in the archive.

Using some more code from the examples in the repository, I try to get at an actual file in the archive:

Zip::ZipInputStream.open(f) { |zis|
  entry = zis.get_next_entry
  print "first line of '#{entry.name}' (#{entry.size} bytes: ) "
  puts "'#{zis.gets.chomp}'" }

=> first line of '20090101_da_lmp.csv' (826610 bytes: ) Zlib::DataError: 
   invalid stored block lengths #and a long stack trace I can provide 
                                #if that might help

The Mac OS decompression utility unzips the archive fine. I was wondering if it was some kind of encoding-related thing (my locale is set to en_US.UTF-8 because to make using PostgreSQL in dev less painful), but I don't know how to tell if that's the case. I can't find any information on what might cause this error.

Brogue answered 14/5, 2012 at 2:55 Comment(0)
J
12

This is a typical error found when feeding random data to an inflater. In fact you will get this error about 1/4 of the time from random data (when the low three bits of the first byte are 000 or 001). So I would guess that the inflation is simply starting at the wrong byte for some reason.

Junejuneau answered 14/5, 2012 at 16:10 Comment(1)
Thanks Mark. This helped me confirm my suspicion that the file was corrupted. I think my early missteps with rubyzip accidentally wrote something to the archive, but I had successfully unzipped it before with the Mac OS decompressor, so I got confused. Deleting the corrupted file and replacing it with a fresh one did the trick.Brogue

© 2022 - 2024 — McMap. All rights reserved.