Strange rubyzip behaviour (Errno::EFBIG)

Hi,
I’m having a really weird issue trying to use rubyzip on FreeBSD 4.9.
Whenever I try to open a file, no matter what the size, I get:

Errno::EFBIG: File too large

Example is as follows(using rubyzip-0.5.5):

travis@aop:~$ uname -a
FreeBSD aop.intranet 4.9-RELEASE-p4 FreeBSD
4.9-RELEASE-p4 #0: Wed Mar 17 16:55:09 EST 2004
root@aop.intranet:/usr/obj/usr/src/sys/MYKERNEL i386

travis@aop:~$ ruby -v
ruby 1.8.1 (2003-12-25) [i386-freebsd4]

travis@aop:~/rubyzip/test$ irb
irb(main):001:0> $:.push("…")
=> ["/usr/local/lib/ruby/site_ruby/1.8",
"/usr/local/lib/ruby/site_ruby/1.8/i386-freebsd4",
"/usr/local/lib/ruby/site_ruby",
"/usr/local/lib/ruby/1.8",
"/usr/local/lib/ruby/1.8/i386-freebsd4", “.”, “…”]
irb(main):002:0> require ‘zip/zip’
…/zip/zip.rb:11: warning: already initialized constant Tempfile
=> true
irb(main):003:0> Zip::ZipFile.new(“rubycode.zip”)
Errno::EFBIG: File too large - rubycode.zip
from …/zip/zip.rb:818:in read' from ../zip/zip.rb:818:inget_e_o_c_d’
from …/zip/zip.rb:783:in read_e_o_c_d' from ../zip/zip.rb:808:inread_from_stream’
from …/zip/zip.rb:869:in initialize' from ../zip/zip.rb:869:inopen’
from …/zip/zip.rb:869:in initialize' from (irb):3:innew’
from (irb):3

travis@aop:~/rubyzip/test$ file rubycode.zip
rubycode.zip: Zip archive data, at least v2.0 to extract

travis@aop:~/rubyzip/test$ ls -l rubycode.zip
-rw-r–r-- 1 travis devel 617 Apr 19 2002 rubycode.zip

I’ve also tried rubyzip-0.5.3 installed from ports and gotten the same exact
problem. Any help would be appreciated.

Thanks,
Travis Whitton

I have never experienced the Errno::EFBIG exception myself. If anyone
else on this list has tried rubyzip and seen this problem I’d be
interested in hearing about it.

Travis, could you try something like this:

require ‘zip/zip’

is = File.open(“rubycode.zip”, “rb”)
is.seek(5, IO::SEEK_SET)
is.read

Does that cause the problem? If it does, try without requiring
‘zip/zip’.

Rubyzip doesn’t do anything too weird with the files, all it does is
opening the archive file in “rb”-mode and seek-around and read a bit,
which is what the code fragment above is intended to mimic.

I have run the test suite succesfully myself on Windows XP/ruby-1.8.0
(pragprog build) and on RedHat 9.0 Linux/ruby-1.8.1 before making the
release.

Cheers,

Thomas

Travis Whitton whitton@atlantic.net wrote in message news:slrnc6jf42.v93.whitton@grub.ath.cx

···

Hi,
I’m having a really weird issue trying to use rubyzip on FreeBSD 4.9.
Whenever I try to open a file, no matter what the size, I get:

Errno::EFBIG: File too large

Example is as follows(using rubyzip-0.5.5):

travis@aop:~$ uname -a
FreeBSD aop.intranet 4.9-RELEASE-p4 FreeBSD
4.9-RELEASE-p4 #0: Wed Mar 17 16:55:09 EST 2004
root@aop.intranet:/usr/obj/usr/src/sys/MYKERNEL i386

travis@aop:~$ ruby -v
ruby 1.8.1 (2003-12-25) [i386-freebsd4]

travis@aop:~/rubyzip/test$ irb
irb(main):001:0> $:.push(“…”)
=> [“/usr/local/lib/ruby/site_ruby/1.8”,
“/usr/local/lib/ruby/site_ruby/1.8/i386-freebsd4”,
“/usr/local/lib/ruby/site_ruby”,
“/usr/local/lib/ruby/1.8”,
“/usr/local/lib/ruby/1.8/i386-freebsd4”, “.”, “…”]
irb(main):002:0> require ‘zip/zip’
…/zip/zip.rb:11: warning: already initialized constant Tempfile
=> true
irb(main):003:0> Zip::ZipFile.new(“rubycode.zip”)
Errno::EFBIG: File too large - rubycode.zip
from …/zip/zip.rb:818:in read' from ../zip/zip.rb:818:in get_e_o_c_d’
from …/zip/zip.rb:783:in read_e_o_c_d' from ../zip/zip.rb:808:in read_from_stream’
from …/zip/zip.rb:869:in initialize' from ../zip/zip.rb:869:in open’
from …/zip/zip.rb:869:in initialize' from (irb):3:in new’
from (irb):3

travis@aop:~/rubyzip/test$ file rubycode.zip
rubycode.zip: Zip archive data, at least v2.0 to extract

travis@aop:~/rubyzip/test$ ls -l rubycode.zip
-rw-r–r-- 1 travis devel 617 Apr 19 2002 rubycode.zip

I’ve also tried rubyzip-0.5.3 installed from ports and gotten the same exact
problem. Any help would be appreciated.

Thanks,
Travis Whitton

I have committed a fix for this problem to the CVS version of rubyzip.

Thomas

Travis, could you try something like this:

require ‘zip/zip’

is = File.open(“rubycode.zip”, “rb”)
is.seek(5, IO::SEEK_SET)
is.read

irb(main):002:0> require ‘zip/zip’
…/zip/zip.rb:11: warning: already initialized constant Tempfile
=> true
irb(main):003:0> is = File.open(“rubycode.zip”, “rb”)
=> #<File:rubycode.zip>
irb(main):004:0> is.seek(5, IO::SEEK_SET)
=> 0
irb(main):005:0> is.read
=> “\000\000\000\010\000\275…”

Does that cause the problem? If it does, try without requiring
‘zip/zip’.

Looks like it works fine.

Rubyzip doesn’t do anything too weird with the files, all it does is
opening the archive file in “rb”-mode and seek-around and read a bit,
which is what the code fragment above is intended to mimic.

I’ll see if I can figure it out later when I have more time.

Thanks,
Travis

I’ve distilled the problem down to the following lines of code.

travis@aop:~$ touch foo.txt
travis@aop:~$ cat crash.rb
MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE = 65536 + 18
name = “foo.txt”

File.open(name, “rb”) do |f|
f.seek(-MAX_END_OF_CENTRAL_DIRECTORY_STRUCTURE_SIZE, IO::SEEK_END)
f.read
end
travis@aop:~$ ruby crash.rb
crash.rb:6:in read': File too large - foo.txt (Errno::EFBIG) from crash.rb:6 from crash.rb:4:inopen’
from crash.rb:4

travis@aop:~$ ruby crash.rb
crash.rb:6:in read': File too large - foo.txt (Errno::EFBIG) from crash.rb:6 from crash.rb:4:in open’
from crash.rb:4

Aah, on my systems (ruby 1.8.1 (2003-12-25) [i686-linux] and ruby 1.8.0
(2003-08-04) [i386-mswin32]) your example raises Errno::EINVAL which rubyzip
expects and handles.

I wonder if it is matz’ intention that the ruby interpreter should mend such
inconsistencies between different operating systems. Otherwise I will add
another rescue-clause that handles Errno::EFBIG.

Cheers,

Thomas

Hi,

At Fri, 2 Apr 2004 03:34:23 +0900,
Thomas Sondergaard wrote in [ruby-talk:96327]:

I wonder if it is matz’ intention that the ruby interpreter should mend such
inconsistencies between different operating systems. Otherwise I will add
another rescue-clause that handles Errno::EFBIG.

Why not just SystemCallError?

···


Nobu Nakada