kpumuk commented on code in PR #3701:
URL: https://github.com/apache/thrift/pull/3701#discussion_r3717386961


##########
lib/rb/spec/header_transport_spec.rb:
##########
@@ -393,6 +393,54 @@ def framed(message)
     end
 
     describe "header parsing protections" do
+      it "rejects frame sizes shorter than a protocol signature" do
+        (0..3).each do |frame_size|
+          frame = [frame_size].pack('N') + ("\x00" * frame_size)
+          read_trans = 
Thrift::HeaderTransport.new(Thrift::MemoryBufferTransport.new(frame))
+
+          expect { read_trans.read(1) }.to raise_error(
+            Thrift::TransportException,
+            "Frame size #{frame_size} is too small"
+          ) do |error|
+            expect(error.type).to eq(Thrift::TransportException::UNKNOWN)
+          end
+        end
+      end
+
+      it "reports EOF when the frame size is fragmented" do
+        (0..3).each do |available_size|
+          read_trans = Thrift::HeaderTransport.new(
+            Thrift::MemoryBufferTransport.new("\x00" * available_size)
+          )
+
+          expect { read_trans.read(1) }.to raise_error(
+            Thrift::TransportException,
+            "Unexpected EOF reading frame size"
+          ) do |error|
+            expect(error.type).to eq(Thrift::TransportException::END_OF_FILE)
+          end
+        end
+      end
+
+      it "reports EOF when the declared frame is fragmented" do
+        frame = [4].pack('N') + "\x80\x01\x00"
+        read_trans = 
Thrift::HeaderTransport.new(Thrift::MemoryBufferTransport.new(frame))

Review Comment:
   Unnecessary, but idiomatic and clear. Accepted



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to