@@ -242,6 +242,54 @@ BOOST_AUTO_TEST_CASE(test_tthriftcompactprotocol_read_check_pass) {
242242 BOOST_CHECK_NO_THROW (protocol->readString (eleven));
243243}
244244
245+ BOOST_AUTO_TEST_CASE (test_tthriftbinaryprotocol_container_size_overflow) {
246+ std::shared_ptr<TConfiguration> config (new TConfiguration (1024 ));
247+ std::shared_ptr<TMemoryBuffer> transport (new TMemoryBuffer (config));
248+ std::shared_ptr<TBinaryProtocol> protocol (new TBinaryProtocol (transport));
249+
250+ uint32_t val = 0 ;
251+ TType elemType = apache::thrift::protocol::T_STOP ;
252+ // 0x40000000 elements of min size 4 require 4 GiB; the product wraps to 0 in
253+ // 32-bit math and used to slip past the MaxMessageSize check.
254+ TList list (T_I32 , 0x40000000 );
255+ protocol->writeListBegin (list.elemType_ , list.size_ );
256+ protocol->writeListEnd ();
257+ BOOST_CHECK_THROW (protocol->readListBegin (elemType, val), TTransportException);
258+ protocol->readListEnd ();
259+ }
260+
261+ BOOST_AUTO_TEST_CASE (test_tthriftcompactprotocol_container_size_overflow) {
262+ std::shared_ptr<TConfiguration> config (new TConfiguration (1024 ));
263+ std::shared_ptr<TMemoryBuffer> transport (new TMemoryBuffer (config));
264+ std::shared_ptr<TCompactProtocol> protocol (new TCompactProtocol (transport));
265+
266+ uint32_t val = 0 ;
267+ TType elemType = apache::thrift::protocol::T_STOP ;
268+ // 0x10000000 elements of min size 16 (UUID) require 4 GiB; the product wraps
269+ // to 0 in 32-bit math and used to slip past the MaxMessageSize check.
270+ TList list (T_UUID , 0x10000000 );
271+ protocol->writeListBegin (list.elemType_ , list.size_ );
272+ protocol->writeListEnd ();
273+ BOOST_CHECK_THROW (protocol->readListBegin (elemType, val), TTransportException);
274+ protocol->readListEnd ();
275+ }
276+
277+ BOOST_AUTO_TEST_CASE (test_tthriftjsonprotocol_container_size_overflow) {
278+ std::shared_ptr<TConfiguration> config (new TConfiguration (1024 ));
279+ std::shared_ptr<TMemoryBuffer> transport (new TMemoryBuffer (config));
280+ std::shared_ptr<TJSONProtocol> protocol (new TJSONProtocol (transport));
281+
282+ uint32_t val = 0 ;
283+ TType elemType = apache::thrift::protocol::T_STOP ;
284+ // 0x10000000 elements of min size 16 (UUID) require 4 GiB; the product wraps
285+ // to 0 in 32-bit math and used to slip past the MaxMessageSize check.
286+ TList list (T_UUID , 0x10000000 );
287+ protocol->writeListBegin (list.elemType_ , list.size_ );
288+ protocol->writeListEnd ();
289+ BOOST_CHECK_THROW (protocol->readListBegin (elemType, val), TTransportException);
290+ protocol->readListEnd ();
291+ }
292+
245293BOOST_AUTO_TEST_CASE (test_tthriftjsonprotocol_read_check_exception) {
246294 std::shared_ptr<TConfiguration> config (new TConfiguration (MAX_MESSAGE_SIZE ));
247295 std::shared_ptr<TMemoryBuffer> transport (new TMemoryBuffer (config));
0 commit comments