|
10 | 10 | #include <folly/Format.h> |
11 | 11 | #include <folly/portability/GTest.h> |
12 | 12 | #include <glog/logging.h> |
| 13 | +#include <limits> |
13 | 14 | #include <memory> |
| 15 | +#include <proxygen/lib/http/codec/compress/HPACKEncodeBuffer.h> |
14 | 16 | #include <proxygen/lib/http/codec/compress/Logging.h> |
15 | 17 | #include <proxygen/lib/http/codec/compress/QPACKDecoder.h> |
16 | 18 | #include <proxygen/lib/http/codec/compress/QPACKEncoder.h> |
@@ -858,6 +860,28 @@ void checkQError(QPACKDecoder& decoder, |
858 | 860 | EXPECT_EQ(cb->error, err); |
859 | 861 | } |
860 | 862 |
|
| 863 | +TEST(QPACKContextTests, RejectsOverflowingRequiredInsertCount) { |
| 864 | + QPACKDecoder decoder; |
| 865 | + HPACKEncodeBuffer insertStream(128, false); |
| 866 | + const uint32_t maxEntries = HPACK::kTableSize / HPACKHeader::kMinLength; |
| 867 | + // Prime insertCount so RIC reconstruction uses a non-zero maxWrapped value. |
| 868 | + for (uint32_t i = 0; i < maxEntries; i++) { |
| 869 | + insertStream.encodeLiteral(HPACK::Q_INSERT_NO_NAME_REF.code, |
| 870 | + HPACK::Q_INSERT_NO_NAME_REF.prefixLength, |
| 871 | + folly::to<string>("x-overflow-", i)); |
| 872 | + insertStream.encodeLiteral("v"); |
| 873 | + } |
| 874 | + EXPECT_EQ(decoder.decodeEncoderStream(insertStream.release()), |
| 875 | + HPACK::DecodeError::NONE); |
| 876 | + |
| 877 | + HPACKEncodeBuffer headerBlock(128, false); |
| 878 | + // This value used to overflow maxWrapped + wireRIC - 1 before validation. |
| 879 | + headerBlock.encodeInteger(std::numeric_limits<uint64_t>::max() - 154); |
| 880 | + headerBlock.encodeInteger(0, HPACK::Q_DELTA_BASE); |
| 881 | + checkQError( |
| 882 | + decoder, headerBlock.release(), HPACK::DecodeError::INVALID_INDEX); |
| 883 | +} |
| 884 | + |
861 | 885 | TEST(QPACKContextTests, DecodeErrors) { |
862 | 886 | QPACKDecoder decoder(128); |
863 | 887 | unique_ptr<IOBuf> buf = IOBuf::create(128); |
|
0 commit comments