Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/rb/lib/thrift/protocol/base_protocol.rb
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ def read_type(field_info)
end
end

def skip(type)
def skip(type, max_depth = 64)
raise ProtocolException.new(ProtocolException::DEPTH_LIMIT, 'Maximum skip depth exceeded') if max_depth <= 0
case type
when Types::BOOL
read_bool
Expand All @@ -365,27 +366,27 @@ def skip(type)
while true
name, type, id = read_field_begin
break if type == Types::STOP
skip(type)
skip(type, max_depth - 1)
read_field_end
end
read_struct_end
when Types::MAP
ktype, vtype, size = read_map_begin
size.times do
skip(ktype)
skip(vtype)
skip(ktype, max_depth - 1)
skip(vtype, max_depth - 1)
end
read_map_end
when Types::SET
etype, size = read_set_begin
size.times do
skip(etype)
skip(etype, max_depth - 1)
end
read_set_end
when Types::LIST
etype, size = read_list_begin
size.times do
skip(etype)
skip(etype, max_depth - 1)
end
read_list_end
else
Expand Down
11 changes: 11 additions & 0 deletions lib/rb/spec/base_protocol_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,17 @@
expect(@prot).to receive(:read_list_end)
real_skip.call(Thrift::Types::LIST)
end

it "should raise DEPTH_LIMIT when max_depth is exhausted" do
expect { @prot.skip(Thrift::Types::STRUCT, 0) }.to raise_error(Thrift::ProtocolException) do |e|
expect(e.type).to eq(Thrift::ProtocolException::DEPTH_LIMIT)
end
end

it "should skip at max_depth=1 without raising" do
expect(@prot).to receive(:read_bool).once
expect { @prot.skip(Thrift::Types::BOOL, 1) }.not_to raise_error
end
end

describe Thrift::BaseProtocolFactory do
Expand Down
Loading