Skip to content

Commit 61c0a0f

Browse files
committed
Merge pull request #744 from estolfo/RUBY-1078-nil-msg-size
RUBY-1078 Use default max message size when value is nil
2 parents 080c2f9 + 0e6fd78 commit 61c0a0f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/mongo/protocol/message.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def self.deserialize(io, max_message_size = MAX_MESSAGE_SIZE)
114114

115115
# Protection from potential DOS man-in-the-middle attacks. See
116116
# DRIVERS-276.
117-
if length > max_message_size
117+
if length > (max_message_size || MAX_MESSAGE_SIZE)
118118
raise Error::MaxMessageSize.new(max_message_size)
119119
end
120120

spec/mongo/protocol/reply_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,19 @@
9797
end
9898
end
9999

100+
context 'when the max message size is nil' do
101+
102+
let(:reply) { described_class.deserialize(io, nil) }
103+
104+
let(:length) { Mongo::Protocol::Message::MAX_MESSAGE_SIZE + 1 }
105+
106+
it 'uses the default max message size for comparison' do
107+
expect {
108+
reply
109+
}.to raise_error(Mongo::Error::MaxMessageSize)
110+
end
111+
end
112+
100113
describe 'response flags' do
101114

102115
context 'no flags' do

0 commit comments

Comments
 (0)