Dmytro Shteflyuk created THRIFT-6102:
----------------------------------------

             Summary: Ruby CompactProtocol should report malformed headers 
consistently
                 Key: THRIFT-6102
                 URL: https://issues.apache.org/jira/browse/THRIFT-6102
             Project: Thrift
          Issue Type: Bug
            Reporter: Dmytro Shteflyuk
            Assignee: Dmytro Shteflyuk


h3. Problem

{{Thrift::CompactProtocol#read_message_begin}} reports malformed 
compact-protocol headers differently depending on whether {{thrift_native}} is 
loaded.

For an unexpected protocol identifier or version, the native implementation 
raises {{ProtocolException}} with type {{-1}} and a message. The pure-Ruby 
implementation passes its explanatory text as the first constructor argument, 
which is the exception type, leaving {{message}} empty.

Neither mode reports the documented {{ProtocolException::BAD_VERSION}} type, 
and the exception metadata differs between the two implementations.

h3. Client impact

Ruby clients that rescue {{ProtocolException}} and inspect {{type}} cannot 
reliably identify malformed compact-protocol headers. The diagnostic message is 
also unavailable in pure-Ruby mode, while native mode may produce a different 
message for an incompatible version.

This makes error handling and diagnostics depend on whether the native 
extension is installed.

h3. Reproduction

{code:ruby}
require "thrift"

transport = Thrift::MemoryBufferTransport.new([0x00].pack("C"))
protocol = Thrift::CompactProtocol.new(transport)

begin
  protocol.read_message_begin
rescue Thrift::ProtocolException => error
  p [error.type, error.message]
end
{code}

With {{thrift_native}} loaded, the result is a type of {{-1}} with a 
descriptive message. Without the native extension, the descriptive text is 
stored in {{type}} and {{message}} is {{nil}}.

h3. Expected behavior

Both implementations should raise {{ProtocolException}} with 
{{ProtocolException::BAD_VERSION}} for an invalid compact protocol identifier 
or version. They should also provide the same descriptive message, including 
the expected and received values.



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

Reply via email to