Dmytro Shteflyuk created THRIFT-6142:
----------------------------------------

             Summary: Ruby HeaderTransport does not limit unframed messages
                 Key: THRIFT-6142
                 URL: https://issues.apache.org/jira/browse/THRIFT-6142
             Project: Thrift
          Issue Type: Bug
          Components: Ruby - Library
            Reporter: Dmytro Shteflyuk
            Assignee: Dmytro Shteflyuk


h3. Problem

Ruby HeaderTransport supports unframed Binary and Compact clients by passing 
reads directly to the underlying transport after detecting the protocol. The 
configured max_frame_size is enforced for Header and framed clients, but it is 
not applied to these supported unframed messages.

h3. Client impact

Applications configuring max_frame_size can still receive an unframed Binary or 
Compact message larger than that limit. The setting therefore behaves 
differently depending on the automatically detected client transport type.

h3. Reproduction

Testing on master commit {{a9663bc6661a5dd1d99d629e1f269c1907592a1a}} produces:

{code:ruby}
require "thrift"

{
  "binary" => Thrift::BinaryProtocol,
  "compact" => Thrift::CompactProtocol
}.each do |label, protocol_class|
  buffer = Thrift::MemoryBufferTransport.new
  writer = protocol_class.new(buffer)
  writer.write_message_begin("legacy", Thrift::MessageTypes::CALL, 1)
  writer.write_struct_begin("Args")
  writer.write_field_stop
  writer.write_struct_end
  writer.write_message_end
  payload = buffer.read(buffer.available)

  transport = Thrift::HeaderTransport.new(
    Thrift::MemoryBufferTransport.new(payload)
  )
  limit = payload.bytesize - 1
  transport.set_max_frame_size(limit)

  reader = protocol_class.new(transport)
  name = reader.read_message_begin.first
  reader.skip(Thrift::Types::STRUCT)
  reader.read_message_end

  puts "#{label}: decoded=#{name.inspect} " \
       "bytes=#{payload.bytesize} max_frame_size=#{limit}"
end
{code}

{noformat}
binary: decoded="legacy" bytes=19 max_frame_size=18
compact: decoded="legacy" bytes=11 max_frame_size=10
{noformat}

h3. Expected behavior

HeaderTransport should apply max_frame_size to each unframed Binary or Compact 
protocol message. Messages at or below the configured limit should remain 
supported, messages above it should raise TransportException::SIZE_LIMIT, and 
the budget should reset between sequential messages.




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

Reply via email to