Issue Details (XML | Word | Printable)

Key: JRUBY-1230
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Thomas E Enebo
Reporter: Nathan Fiedler
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JRuby

Zip::ZipFile.open() fails only in JRuby (rubyzip)

Created: 20/Jul/07 06:00 PM   Updated: 24/Sep/08 11:55 PM   Resolved: 26/Jul/07 12:38 AM
Return to search
Component/s: None
Affects Version/s: JRuby 1.1
Fix Version/s: JRuby 1.1

Time Tracking:
Not Specified

File Attachments: 1. File iodiff.diff (3 kB)

Environment:
$ uname -a
Linux caffe.sfbay.sun.com 2.6.20-1.2962.fc6 #1 SMP Tue Jun 19 18:50:05 EDT 2007 x86_64 x86_64 x86_64 GNU/Linux

$ java -version
java version "1.6.0_02"
Java(TM) SE Runtime Environment (build 1.6.0_02-b05)
Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_02-b05, mixed mode)

rubyzip version 0.9.1


 Description  « Hide

% jirb
irb(main):002:0> require 'rubygems'
=> true
irb(main):003:0> require 'zip/zip'
=> true
irb(main):004:0> Zip::ZipFile.open('path/to/file.zip')
TypeError: can't dup NilClass
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1369:in `map'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1132:in `dup'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1369:in `initialize'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1379:in `new'
from /opt/jruby-1.0/lib/ruby/gems/1.8/gems/rubyzip-0.9.1/lib/zip/zip.rb:1379:in `open'
from (irb):4:in `binding'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:150:in `eval_input'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:70:in `signal_status'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:189:in `eval_input'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:70:in `each_top_level_statement'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:190:in `loop'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:190:in `catch'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:190:in `eval_input'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:70:in `start'
from :-1:in `catch'
from /opt/jruby-1.0/lib/ruby/1.8/irb.rb:71:in `start'
from :-1irb(main):005:0>

It seems that the rubyzip code is failing to successfully read the zip file, but it does not realize and results in the error. This exact same sequence works fine with native irb.



Nicolas Modrzyk added a comment - 23/Jul/07 02:53 AM

That one took me a long time.

Basically, need to add the following line to RubyIO:
if (len == 0) return RubyString.newString(getRuntime(),"");

The problem was that when reading an entry, the zip.rb code goes through the following code:
@comment = io.read(commentLength)
unless (@comment && @comment.length == commentLength)
raise ZipError, "Truncated cdir zip entry header"
end

which looks pretty innocent, but commentLength was 0, thus the code in JRuby was returning null instead of an empty string.
The following code of zip was then raising an exception, this resulting in a null entry, which could not be duplicated, thus the following exception:
/zip.rb:1390:in `map': can't dup NilClass (TypeError)
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1148:in `dup'
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1390:in `initialize'
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1401:in `new'
from /Users/niko/tools/gems/gems/rubyzip-0.9.1/lib/zip/zip.rb:1401:in `open'
from :1

The patch is also including the path for (since it hasn't been committed in the trunk yet):
http://jira.codehaus.org/browse/JRUBY-1108


Nick Sieger added a comment - 26/Jul/07 12:38 AM

Thanks again for the fixes.


Charles Oliver Nutter added a comment - 23/Apr/08 10:11 AM

Marking bugs with invalid "fixed for release" as fixed in 1.1.