UnmarshalStream: Fixed two off-by-one errors in unmarshalInt#1338
Merged
enebo merged 1 commit intojruby:jruby-1_7from Dec 15, 2013
Merged
UnmarshalStream: Fixed two off-by-one errors in unmarshalInt#1338enebo merged 1 commit intojruby:jruby-1_7from
enebo merged 1 commit intojruby:jruby-1_7from
Conversation
…ow consistent with r_long in marshal.c of MRI. This also means there are three different ways to marshal the number 0.
Contributor
Author
|
The Travis CI build seems to have failed because it had trouble connecting to rubyforge.org port 443 and I don't think my change would have caused that. |
enebo
added a commit
that referenced
this pull request
Dec 15, 2013
UnmarshalStream: Fixed two off-by-one errors in unmarshalInt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While working on fixing issue #1329, I discovered something tangentially related that I think is a tiny bug and can be easily fixed. MRI's
Marshal.loadrecognizes three different ways of encoding the integer 0 in a single byte, but JRuby 1.7.9 only handles one and raises the "marshal data too short" exception for the other two. This is because there are two off-by-one errors in JRuby'sunmarshalIntmethod.I think that
unmarshalIntis supposed to be a clone of MRI'sr_longfunction, so here is the source code ofr_long:https://github.com/ruby/ruby/blob/v2_0_0_352/marshal.c#L1114-1145
Here is the code I used to demonstrate the difference between MRI 2.0.0p0 and JRuby:
I suppose this isn't too important, because the number 0 will probably be marshaled as the 0x00 byte instead of 0xFB or 0x05, but if MRI treats those bytes as representing 0 then I don't think it is helpful for JRuby to raise an exception (or to try to construct an integer by reading 5 bytes from the stream).
I am happy to do any more investigating or documentation that is needed. Should I write a test for this? If so, where should I put it?