Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: JRuby 1.5.2
    • Fix Version/s: JRuby 1.5.4, JRuby 1.6RC1
    • Component/s: Core Classes/Modules
    • Labels:
      None
    • Environment:
    • Number of attachments :
      1

      Description

      Loading a marshalled Ruby hash from a file succeeds with JRuby 1.5.2, but one of the hash keys is completely wrong (-125 instead of 60803). The marshalled hash loads just fine in 1.8.7-p302, 1.9.2-p0, and Rubinius 1.0.1.

      Code used to load the hash is fairly standard stuff:

      Unable to find source-code formatter for language: ruby. Available languages are: actionscript, html, java, javascript, none, sql, xhtml, xml
      ENCODE62 = Marshal.load(File.open("./encode62_examples", "r"))
      

      I've attached the problem marshalled hash and it is also available in my radix62 repo: http://github.com/k33l0r/radix62/tree/master/spec/support/

        Activity

        Hide
        Matias Korhonen added a comment -

        I just realized there's a second corrupt hash key when loading the hash in JRuby:

        ENCODE62.each do |k,v|
          puts "#{k} => #{v}" if k < 0
        end
        
        # prints:
        # "-125 => fOH"
        # "-5987050 => 17ZoKG"
        
        Show
        Matias Korhonen added a comment - I just realized there's a second corrupt hash key when loading the hash in JRuby: ENCODE62.each do |k,v| puts "#{k} => #{v}" if k < 0 end # prints: # "-125 => fOH" # "-5987050 => 17ZoKG"
        Hide
        Hiroshi Nakamura added a comment -

        This patch should fix I think. Passes spec-short. I'll write a test and commit it later.

        Developers: any side effect?

        diff --git a/src/org/jruby/util/io/ChannelStream.java b/src/org/jruby/util/io/ChannelStream.java
        index 3939a09..f2f4b89 100644
        --- a/src/org/jruby/util/io/ChannelStream.java
        +++ b/src/org/jruby/util/io/ChannelStream.java
        @@ -1457,7 +1457,8 @@ public class ChannelStream implements Stream, Finalizable {
                     }
         
                     byte[] b = new byte[1];
        -            return read(b, 0, 1) == 1 ? b[0] : -1;
        +            // java.io.InputStream#read must return signed value;
        +            return read(b, 0, 1) == 1 ? b[0] & 0xff: -1;
                 }
         
                 @Override
        
        Show
        Hiroshi Nakamura added a comment - This patch should fix I think. Passes spec-short. I'll write a test and commit it later. Developers: any side effect? diff --git a/src/org/jruby/util/io/ChannelStream.java b/src/org/jruby/util/io/ChannelStream.java index 3939a09..f2f4b89 100644 --- a/src/org/jruby/util/io/ChannelStream.java +++ b/src/org/jruby/util/io/ChannelStream.java @@ -1457,7 +1457,8 @@ public class ChannelStream implements Stream, Finalizable { } byte[] b = new byte[1]; - return read(b, 0, 1) == 1 ? b[0] : -1; + // java.io.InputStream#read must return signed value; + return read(b, 0, 1) == 1 ? b[0] & 0xff: -1; } @Override
        Hide
        Hiroshi Nakamura added a comment -

        Wrong comment. Must be unsigned (0-255).

        For a workaround, you can use Marshal.load(File.read(...)) instead of File.open. It's memory consuming though.

        Show
        Hiroshi Nakamura added a comment - Wrong comment. Must be unsigned (0-255). For a workaround, you can use Marshal.load(File.read(...)) instead of File.open. It's memory consuming though.
        Hide
        Hiroshi Nakamura added a comment -

        Fixed in a806844f69225d97c2c2bb909743cdfaea27b721 at master branch.
        http://github.com/jruby/jruby/commit/a806844f69225d97c2c2bb909743cdfaea27b721

        JRUBY-5064: ChannelStream#read() should return an unsigned value.

        For InputStream compatibility. Reading int from buffered bytes works but
        reading from unbeffered bytes did not work.

        Matias, would you please try the next updated package at http://ci.jruby.org/job/jruby-dist/ ?

        Show
        Hiroshi Nakamura added a comment - Fixed in a806844f69225d97c2c2bb909743cdfaea27b721 at master branch. http://github.com/jruby/jruby/commit/a806844f69225d97c2c2bb909743cdfaea27b721 JRUBY-5064 : ChannelStream#read() should return an unsigned value. For InputStream compatibility. Reading int from buffered bytes works but reading from unbeffered bytes did not work. Matias, would you please try the next updated package at http://ci.jruby.org/job/jruby-dist/ ?
        Hide
        Hiroshi Nakamura added a comment -

        Still waiting for a response from the original reporter.

        And we should push this to jruby-1_5 before 1.5.4. It causes a serious and unforeseen bug when it fires.

        Show
        Hiroshi Nakamura added a comment - Still waiting for a response from the original reporter. And we should push this to jruby-1_5 before 1.5.4. It causes a serious and unforeseen bug when it fires.
        Hide
        Charles Oliver Nutter added a comment -

        Agreed this should go into 1.5.4, since it's an actual breakage in marshaling due to lack of signed/unsigned handling.

        Fixed on master in a806844 by Nahi and merged to jruby-1_5 by me in 6dd2bd8.

        Show
        Charles Oliver Nutter added a comment - Agreed this should go into 1.5.4, since it's an actual breakage in marshaling due to lack of signed/unsigned handling. Fixed on master in a806844 by Nahi and merged to jruby-1_5 by me in 6dd2bd8.

          People

          • Assignee:
            Hiroshi Nakamura
            Reporter:
            Matias Korhonen
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: