Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Gem::SafeMarshal::Reader#read_count
read_count
lib/rubygems/safe_marshal/reader.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/lib/rubygems/safe_marshal/reader.rb, line 103
def read_count
count = read_integer
raise NegativeLengthError if count < 0
remaining = @io.size - @io.pos
raise LengthTooLongError, "expected #{count} elements, but only #{remaining} bytes remain" if count > remaining
count
end
Reads an element count and validates it against the number of bytes remaining in the input, since each element to be read consumes at least one byte. This prevents allocating huge backing stores for maliciously crafted lengths that could never be satisfied.