Skip to content

Commit

Permalink
Treat input of Marshal.load as binary
Browse files Browse the repository at this point in the history
  • Loading branch information
herwinw committed Sep 29, 2024
1 parent 620a905 commit 0135e40
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
8 changes: 3 additions & 5 deletions spec/core/marshal/shared/load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -798,11 +798,9 @@ def io.binmode; raise "binmode"; end
it "loads a String as BINARY if no encoding is specified at the end" do
str = "\xC3\xB8".dup.force_encoding("BINARY")
data = "\x04\b\"\a\xC3\xB8".dup.force_encoding("UTF-8")
NATFIXME 'loads a String as BINARY if no encoding is specified at the end', exception: ArgumentError, message: 'marshal data too short' do
result = Marshal.send(@method, data)
result.encoding.should == Encoding::BINARY
result.should == str
end
result = Marshal.send(@method, data)
result.encoding.should == Encoding::BINARY
result.should == str
end

it "raises ArgumentError when end of byte sequence reached before string characters end" do
Expand Down
6 changes: 3 additions & 3 deletions src/marshal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,10 +564,10 @@ def read_byte
end

def read_bytes(integer)
if @source.length - @offset >= integer
string = @source.slice(@offset, integer)
if @source.bytesize - @offset >= integer
string = @source.byteslice(@offset, integer)
@offset += integer
string
string.b
else
raise ArgumentError, 'marshal data too short'
end
Expand Down

0 comments on commit 0135e40

Please sign in to comment.