From 0135e4051d5b68ee3318e57eaa324dabccf53f5c Mon Sep 17 00:00:00 2001 From: Herwin Date: Sun, 29 Sep 2024 17:15:32 +0200 Subject: [PATCH] Treat input of Marshal.load as binary --- spec/core/marshal/shared/load.rb | 8 +++----- src/marshal.rb | 6 +++--- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/spec/core/marshal/shared/load.rb b/spec/core/marshal/shared/load.rb index 379332edd..a05b81afd 100644 --- a/spec/core/marshal/shared/load.rb +++ b/spec/core/marshal/shared/load.rb @@ -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 diff --git a/src/marshal.rb b/src/marshal.rb index 5b01806c9..40a2d9cdb 100644 --- a/src/marshal.rb +++ b/src/marshal.rb @@ -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