Dmytro Shteflyuk created THRIFT-6105:
----------------------------------------

             Summary: Ruby native MemoryBufferTransport should retain partial 
read progress
                 Key: THRIFT-6105
                 URL: https://issues.apache.org/jira/browse/THRIFT-6105
             Project: Thrift
          Issue Type: Bug
          Components: Ruby - Library
            Reporter: Dmytro Shteflyuk
            Assignee: Dmytro Shteflyuk


h3. Problem

The native {{MemoryBufferTransport#read_into_buffer}} implementation keeps the 
read position in a local variable until the entire operation completes. If it 
raises after copying one or more bytes, the destination has been modified but 
the transport still reports those copied bytes as available. The pure-Ruby 
implementation records each successfully copied byte before a later failure.

h3. Client impact

Clients that recover from {{IndexError}} or {{EOFError}} can receive input a 
second time even though it was already copied into their destination buffer. 
The observable behavior also depends on whether {{thrift_native}} is loaded.

h3. Reproduction

{code:ruby}
transport = Thrift::MemoryBufferTransport.new("ab")
destination = +"x"

begin
  transport.read_into_buffer(destination, 2)
rescue IndexError
end

p [destination, transport.available]
# Pure Ruby: ["a", 1]
# Native extension before this change: ["a", 2]
{code}

The same mismatch occurs when input ends after a successful partial copy.

h3. Expected behavior

Once a byte has been copied to the destination, both implementations should 
treat it as consumed even if a later destination-boundary or input-availability 
check raises an exception.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to