|
| 1 | +%% |
| 2 | +%% Licensed to the Apache Software Foundation (ASF) under one |
| 3 | +%% or more contributor license agreements. See the NOTICE file |
| 4 | +%% distributed with this work for additional information |
| 5 | +%% regarding copyright ownership. The ASF licenses this file |
| 6 | +%% to you under the Apache License, Version 2.0 (the |
| 7 | +%% "License"); you may not use this file except in compliance |
| 8 | +%% with the License. You may obtain a copy of the License at |
| 9 | +%% |
| 10 | +%% http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +%% |
| 12 | +%% Unless required by applicable law or agreed to in writing, |
| 13 | +%% software distributed under the License is distributed on an |
| 14 | +%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | +%% KIND, either express or implied. See the License for the |
| 16 | +%% specific language governing permissions and limitations |
| 17 | +%% under the License. |
| 18 | +%% |
| 19 | + |
| 20 | +-module(test_thrift_binary_protocol). |
| 21 | +-include_lib("eunit/include/eunit.hrl"). |
| 22 | +-include("thrift_protocol.hrl"). |
| 23 | + |
| 24 | +new(Buf) -> |
| 25 | + {ok, Transport} = thrift_membuffer_transport:new(Buf), |
| 26 | + {ok, Protocol} = thrift_binary_protocol:new(Transport), |
| 27 | + Protocol. |
| 28 | + |
| 29 | +read(This, Type) -> thrift_protocol:read(This, Type). |
| 30 | + |
| 31 | +negative_map_size_test() -> |
| 32 | + %% ktype=8 (I32), vtype=11 (STRING), size=-1 (0xffffffff big-endian) |
| 33 | + P = new(<<8, 11, 255, 255, 255, 255>>), |
| 34 | + ?assertError({protocol_error, negative_size}, read(P, map_begin)). |
| 35 | + |
| 36 | +negative_list_size_test() -> |
| 37 | + %% etype=11 (STRING), size=-1 |
| 38 | + P = new(<<11, 255, 255, 255, 255>>), |
| 39 | + ?assertError({protocol_error, negative_size}, read(P, list_begin)). |
| 40 | + |
| 41 | +negative_set_size_test() -> |
| 42 | + %% etype=11 (STRING), size=-1 |
| 43 | + P = new(<<11, 255, 255, 255, 255>>), |
| 44 | + ?assertError({protocol_error, negative_size}, read(P, set_begin)). |
| 45 | + |
| 46 | +negative_string_size_test() -> |
| 47 | + %% size=-1 |
| 48 | + P = new(<<255, 255, 255, 255>>), |
| 49 | + ?assertError({protocol_error, negative_size}, read(P, string)). |
0 commit comments