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


##########
lib/rb/lib/thrift/transport/header_transport.rb:
##########
@@ -268,7 +268,11 @@ def read_frame(req_sz)
       @read_headers = {}
 
       # Read first 4 bytes - could be frame length or protocol magic
-      first_word = @transport.read_all(4)
+      begin
+        first_word = @transport.read_all(4)
+      rescue EOFError
+        raise TransportException.new(TransportException::END_OF_FILE, 
"Unexpected EOF reading frame size")
+      end

Review Comment:
   Ruby automatically assigns the active rescued exception as Exception#cause 
when another exception is raised inside the rescue clause. The resulting 
TransportException therefore already retains the original EOFError; I verified 
that wrapped.cause.equal?(original) is true. Explicit cause: is needed 
elsewhere when an exception is saved and raised later, but would be redundant 
here.



##########
lib/rb/lib/thrift/transport/header_transport.rb:
##########
@@ -292,9 +296,16 @@ def read_frame(req_sz)
       if frame_size > @max_frame_size
         raise TransportException.new(TransportException::UNKNOWN, "Frame size 
#{frame_size} exceeds maximum #{@max_frame_size}")
       end
+      if frame_size < 4
+        raise TransportException.new(TransportException::UNKNOWN, "Frame size 
#{frame_size} is too small")
+      end
 
       # Read the complete frame
-      frame_data = @transport.read_all(frame_size)
+      begin
+        frame_data = @transport.read_all(frame_size)
+      rescue EOFError
+        raise TransportException.new(TransportException::END_OF_FILE, 
"Unexpected EOF reading frame")
+      end

Review Comment:
   Ruby automatically assigns the active rescued exception as Exception#cause 
when another exception is raised inside the rescue clause. The resulting 
TransportException therefore already retains the original EOFError; I verified 
that wrapped.cause.equal?(original) is true. Explicit cause: is needed 
elsewhere when an exception is saved and raised later, but would be redundant 
here.



-- 
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