-
Notifications
You must be signed in to change notification settings - Fork 4.1k
THRIFT-5909: Raise an error when nil is sent to binary protocol write operations #3252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kpumuk
wants to merge
1
commit into
apache:master
Choose a base branch
from
kpumuk:binary-nil
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+18
−7
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Currently, when accelerated binary protocol is used, and nil is passed to write operations like write_byte, write_i16, write_i32, write_i64, write_double, write_string, or write_binary, the code raises a StandardError with 'nil argument not allowed!' message. Ruby version (non-accelerated) instead raises random exceptions like NoMethodError or TypeError. This behavior is inconsistent with the expectation that a StandardError with the message 'nil argument not allowed!' should be raised.
1) BinaryProtocol it should behave like a binary protocol should error gracefully when trying to write a nil byte
Failure/Error: expect { @prot.write_byte(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
expected StandardError with "nil argument not allowed!", got #<NoMethodError: undefined method '<' for nil> with backtrace:
# ./lib/thrift/protocol/binary_protocol.rb:85:in 'Thrift::BinaryProtocol#write_byte'
# ./spec/binary_protocol_spec_shared.rb:125:in 'block (3 levels) in <top (required)>'
# ./spec/binary_protocol_spec_shared.rb:125:in 'block (2 levels) in <top (required)>'
Shared Example Group: "a binary protocol" called from ./spec/binary_protocol_spec.rb:25
# ./spec/binary_protocol_spec_shared.rb:125:in 'block (2 levels) in <top (required)>'
2) BinaryProtocol it should behave like a binary protocol should error gracefully when trying to write a nil i16
Failure/Error: expect { @prot.write_i16(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
expected StandardError with "nil argument not allowed!", got #<TypeError: no implicit conversion of nil into Integer> with backtrace:
# ./lib/thrift/protocol/binary_protocol.rb:90:in 'Thrift::BinaryProtocol#write_i16'
# ./spec/binary_protocol_spec_shared.rb:144:in 'block (3 levels) in <top (required)>'
# ./spec/binary_protocol_spec_shared.rb:144:in 'block (2 levels) in <top (required)>'
Shared Example Group: "a binary protocol" called from ./spec/binary_protocol_spec.rb:25
# ./spec/binary_protocol_spec_shared.rb:144:in 'block (2 levels) in <top (required)>'
3) BinaryProtocol it should behave like a binary protocol should error gracefully when trying to write a nil i32
Failure/Error: expect { @prot.write_i32(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
expected StandardError with "nil argument not allowed!", got #<NoMethodError: undefined method '<' for nil> with backtrace:
# ./lib/thrift/protocol/binary_protocol.rb:94:in 'Thrift::BinaryProtocol#write_i32'
# ./spec/binary_protocol_spec_shared.rb:161:in 'block (3 levels) in <top (required)>'
# ./spec/binary_protocol_spec_shared.rb:161:in 'block (2 levels) in <top (required)>'
Shared Example Group: "a binary protocol" called from ./spec/binary_protocol_spec.rb:25
# ./spec/binary_protocol_spec_shared.rb:161:in 'block (2 levels) in <top (required)>'
4) BinaryProtocol it should behave like a binary protocol should error gracefully when trying to write a nil i64
Failure/Error: expect { @prot.write_i64(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
expected StandardError with "nil argument not allowed!", got #<NoMethodError: undefined method '<' for nil> with backtrace:
# ./lib/thrift/protocol/binary_protocol.rb:99:in 'Thrift::BinaryProtocol#write_i64'
# ./spec/binary_protocol_spec_shared.rb:184:in 'block (3 levels) in <top (required)>'
# ./spec/binary_protocol_spec_shared.rb:184:in 'block (2 levels) in <top (required)>'
Shared Example Group: "a binary protocol" called from ./spec/binary_protocol_spec.rb:25
# ./spec/binary_protocol_spec_shared.rb:184:in 'block (2 levels) in <top (required)>'
5) BinaryProtocol it should behave like a binary protocol should error gracefully when trying to write a nil double
Failure/Error: expect { @prot.write_double(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
expected StandardError with "nil argument not allowed!", got #<TypeError: can't convert nil into Float> with backtrace:
# ./lib/thrift/protocol/binary_protocol.rb:106:in 'Thrift::BinaryProtocol#write_double'
# ./spec/binary_protocol_spec_shared.rb:197:in 'block (3 levels) in <top (required)>'
# ./spec/binary_protocol_spec_shared.rb:197:in 'block (2 levels) in <top (required)>'
Shared Example Group: "a binary protocol" called from ./spec/binary_protocol_spec.rb:25
# ./spec/binary_protocol_spec_shared.rb:197:in 'block (2 levels) in <top (required)>'
6) BinaryProtocol it should behave like a binary protocol should error gracefully when trying to write a nil string
Failure/Error: expect { @prot.write_string(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
expected StandardError with "nil argument not allowed!", got #<NoMethodError: undefined method 'encoding' for nil> with backtrace:
# ./lib/thrift/bytes.rb:79:in 'Thrift::Bytes.convert_to_utf8_byte_buffer'
# ./lib/thrift/protocol/binary_protocol.rb:110:in 'Thrift::BinaryProtocol#write_string'
# ./spec/binary_protocol_spec_shared.rb:250:in 'block (3 levels) in <top (required)>'
# ./spec/binary_protocol_spec_shared.rb:250:in 'block (2 levels) in <top (required)>'
Shared Example Group: "a binary protocol" called from ./spec/binary_protocol_spec.rb:25
# ./spec/binary_protocol_spec_shared.rb:250:in 'block (2 levels) in <top (required)>'
7) BinaryProtocol it should behave like a binary protocol should error gracefully when trying to write a nil binary
Failure/Error: expect { @prot.write_binary(nil) }.to raise_error(StandardError, 'nil argument not allowed!')
expected StandardError with "nil argument not allowed!", got #<NoMethodError: undefined method 'bytesize' for nil> with backtrace:
# ./lib/thrift/protocol/binary_protocol.rb:115:in 'Thrift::BinaryProtocol#write_binary'
# ./spec/binary_protocol_spec_shared.rb:254:in 'block (3 levels) in <top (required)>'
# ./spec/binary_protocol_spec_shared.rb:254:in 'block (2 levels) in <top (required)>'
Shared Example Group: "a binary protocol" called from ./spec/binary_protocol_spec.rb:25
# ./spec/binary_protocol_spec_shared.rb:254:in 'block (2 levels) in <top (required)>'
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently, when accelerated binary protocol is used, and nil is passed to write operations like write_byte, write_i16, write_i32, write_i64, write_double, write_string, or write_binary, the code raises a StandardError with 'nil argument not allowed!' message. Ruby version (non-accelerated) instead raises random exceptions like NoMethodError or TypeError. This behavior is inconsistent with the expectation that a StandardError with the message 'nil argument not allowed!' should be raised.
Specs passed before because any exception was considered ok, even if it was not graceful.
[skip ci]anywhere in the commit message to free up build resources.