[
https://issues.apache.org/jira/browse/THRIFT-6100?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Dmytro Shteflyuk resolved THRIFT-6100.
--------------------------------------
Fix Version/s: 0.25.0
Resolution: Fixed
> Ruby MemoryBufferTransport should respect frozen destination buffers
> --------------------------------------------------------------------
>
> Key: THRIFT-6100
> URL: https://issues.apache.org/jira/browse/THRIFT-6100
> Project: Thrift
> Issue Type: Bug
> Components: Ruby - Library
> Reporter: Dmytro Shteflyuk
> Assignee: Dmytro Shteflyuk
> Priority: Major
> Fix For: 0.25.0
>
> Time Spent: 50m
> Remaining Estimate: 0h
>
> h3. Problem
> The native implementation of
> {{Thrift::MemoryBufferTransport#read_into_buffer}} writes directly into the
> destination string without first asking Ruby to make the string mutable.
> As a result, a frozen destination string can be modified when
> {{thrift_native}} is loaded. The pure-Ruby implementation follows normal Ruby
> string semantics and raises {{FrozenError}} instead.
> h3. Client impact
> This affects Ruby clients using {{MemoryBufferTransport}} with the native
> extension. Code that freezes a destination string can reasonably expect that
> object to remain unchanged, but a positive-length native read can currently
> overwrite it and consume input from the transport.
> The behavior also differs depending on whether the native extension is
> available.
> h3. Reproduction
> {code:ruby}
> require "thrift"
> transport = Thrift::MemoryBufferTransport.new("ab")
> destination = "xy".freeze
> transport.read_into_buffer(destination, 2)
> {code}
> With the native extension loaded, the call can succeed and change
> {{destination}} to {{"ab"}}. Without the extension, Ruby raises
> {{FrozenError}}.
> h3. Expected behavior
> A positive-length read into a frozen string should raise {{FrozenError}}
> before either the destination or the transport is modified.
> A zero-length read should remain a no-op: it should return zero without
> modifying the destination, consuming input, or raising {{FrozenError}}.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)