gfe-relnote: Deprecate gfe2_reloadable_flag_http2_varint_decode_64_bits. PiperOrigin-RevId: 230439632 Change-Id: I2a089106411cbe39527a7ff3e0c992867ec5bb84
diff --git a/http2/hpack/varint/hpack_varint_decoder.cc b/http2/hpack/varint/hpack_varint_decoder.cc index dd64025..ac85247 100644 --- a/http2/hpack/varint/hpack_varint_decoder.cc +++ b/http2/hpack/varint/hpack_varint_decoder.cc
@@ -4,7 +4,6 @@ #include "net/third_party/quiche/src/http2/hpack/varint/hpack_varint_decoder.h" -#include "net/third_party/quiche/src/http2/platform/api/http2_flag_utils.h" #include "net/third_party/quiche/src/http2/platform/api/http2_string_utils.h" namespace http2 { @@ -43,96 +42,67 @@ } DecodeStatus HpackVarintDecoder::Resume(DecodeBuffer* db) { - if (decode_64_bits_) { - HTTP2_RELOADABLE_FLAG_COUNT(http2_varint_decode_64_bits); - // There can be at most 10 continuation bytes. Offset is zero for the - // first one and increases by 7 for each subsequent one. - const uint8_t kMaxOffset = 63; - CheckNotDone(); - - // Process most extension bytes without the need for overflow checking. - while (offset_ < kMaxOffset) { - if (db->Empty()) { - return DecodeStatus::kDecodeInProgress; - } - - uint8_t byte = db->DecodeUInt8(); - uint64_t summand = byte & 0x7f; - - // Shifting a 7 bit value to the left by at most 56 places can never - // overflow on uint64_t. - DCHECK_LE(offset_, 56); - DCHECK_LE(summand, std::numeric_limits<uint64_t>::max() >> offset_); - - summand <<= offset_; - - // At this point, - // |value_| is at most (2^prefix_length - 1) + (2^49 - 1), and - // |summand| is at most 255 << 56 (which is smaller than 2^63), - // so adding them can never overflow on uint64_t. - DCHECK_LE(value_, std::numeric_limits<uint64_t>::max() - summand); - - value_ += summand; - - // Decoding ends if continuation flag is not set. - if ((byte & 0x80) == 0) { - MarkDone(); - return DecodeStatus::kDecodeDone; - } - - offset_ += 7; - } - - if (db->Empty()) { - return DecodeStatus::kDecodeInProgress; - } - - DCHECK_EQ(kMaxOffset, offset_); - - uint8_t byte = db->DecodeUInt8(); - // No more extension bytes are allowed after this. - if ((byte & 0x80) == 0) { - uint64_t summand = byte & 0x7f; - // Check for overflow in left shift. - if (summand <= std::numeric_limits<uint64_t>::max() >> offset_) { - summand <<= offset_; - // Check for overflow in addition. - if (value_ <= std::numeric_limits<uint64_t>::max() - summand) { - value_ += summand; - MarkDone(); - return DecodeStatus::kDecodeDone; - } - } - } - - // Signal error if value is too large or there are too many extension bytes. - DLOG(WARNING) << "Variable length int encoding is too large or too long. " - << DebugString(); - MarkDone(); - return DecodeStatus::kDecodeError; - } - - // Old code path. TODO(bnc): remove. - DCHECK(!decode_64_bits_); - const uint8_t kMaxOffset = 28; + // There can be at most 10 continuation bytes. Offset is zero for the + // first one and increases by 7 for each subsequent one. + const uint8_t kMaxOffset = 63; CheckNotDone(); - do { + + // Process most extension bytes without the need for overflow checking. + while (offset_ < kMaxOffset) { if (db->Empty()) { return DecodeStatus::kDecodeInProgress; } + uint8_t byte = db->DecodeUInt8(); - if (offset_ == kMaxOffset && byte != 0) - break; - DCHECK(offset_ <= kMaxOffset - 7 || byte == 0); - // Shifting a 7 bit value to the left by at most 21 places can never - // overflow on uint32_t. Shifting 0 to the left cannot overflow either. - value_ += (byte & 0x7f) << offset_; + uint64_t summand = byte & 0x7f; + + // Shifting a 7 bit value to the left by at most 56 places can never + // overflow on uint64_t. + DCHECK_LE(offset_, 56); + DCHECK_LE(summand, std::numeric_limits<uint64_t>::max() >> offset_); + + summand <<= offset_; + + // At this point, + // |value_| is at most (2^prefix_length - 1) + (2^49 - 1), and + // |summand| is at most 255 << 56 (which is smaller than 2^63), + // so adding them can never overflow on uint64_t. + DCHECK_LE(value_, std::numeric_limits<uint64_t>::max() - summand); + + value_ += summand; + + // Decoding ends if continuation flag is not set. if ((byte & 0x80) == 0) { MarkDone(); return DecodeStatus::kDecodeDone; } + offset_ += 7; - } while (offset_ <= kMaxOffset); + } + + if (db->Empty()) { + return DecodeStatus::kDecodeInProgress; + } + + DCHECK_EQ(kMaxOffset, offset_); + + uint8_t byte = db->DecodeUInt8(); + // No more extension bytes are allowed after this. + if ((byte & 0x80) == 0) { + uint64_t summand = byte & 0x7f; + // Check for overflow in left shift. + if (summand <= std::numeric_limits<uint64_t>::max() >> offset_) { + summand <<= offset_; + // Check for overflow in addition. + if (value_ <= std::numeric_limits<uint64_t>::max() - summand) { + value_ += summand; + MarkDone(); + return DecodeStatus::kDecodeDone; + } + } + } + + // Signal error if value is too large or there are too many extension bytes. DLOG(WARNING) << "Variable length int encoding is too large or too long. " << DebugString(); MarkDone();
diff --git a/http2/hpack/varint/hpack_varint_decoder.h b/http2/hpack/varint/hpack_varint_decoder.h index c793500..5c99b5c 100644 --- a/http2/hpack/varint/hpack_varint_decoder.h +++ b/http2/hpack/varint/hpack_varint_decoder.h
@@ -13,23 +13,16 @@ // For details of the encoding, see: // http://httpwg.org/specs/rfc7541.html#integer.representation // -// If GetHttp2ReloadableFlag(http2_varint_decode_64_bits) is true, then this -// decoder supports decoding any integer that can be represented on uint64_t, -// thereby exceeding the requirements for QPACK: "QPACK implementations MUST be -// able to decode integers up to 62 bits long." See +// HpackVarintDecoder supports decoding any integer that can be represented on +// uint64_t, thereby exceeding the requirements for QPACK: "QPACK +// implementations MUST be able to decode integers up to 62 bits long." See // https://quicwg.org/base-drafts/draft-ietf-quic-qpack.html#rfc.section.5.1.1 // -// If GetHttp2ReloadableFlag(http2_varint_decode_64_bits) is false, then this -// decoder supports decoding integers up to 2^28 + 2^prefix_length - 2. -// // This decoder supports at most 10 extension bytes (bytes following the prefix, -// also called continuation bytes) if -// GetHttp2ReloadableFlag(http2_varint_decode_64_bits) is true, and at most 5 -// extension bytes if GetHttp2ReloadableFlag(http2_varint_decode_64_bits) is -// false. An encoder is allowed to zero pad the encoded integer on the left, -// thereby increasing the number of extension bytes. If an encoder uses so much -// padding that the number of extension bytes exceeds the limit, then this -// decoder signals an error. +// also called continuation bytes). An encoder is allowed to zero pad the +// encoded integer on the left, thereby increasing the number of extension +// bytes. If an encoder uses so much padding that the number of extension bytes +// exceeds the limit, then this decoder signals an error. #ifndef QUICHE_HTTP2_HPACK_VARINT_HPACK_VARINT_DECODER_H_ #define QUICHE_HTTP2_HPACK_VARINT_HPACK_VARINT_DECODER_H_ @@ -41,7 +34,6 @@ #include "net/third_party/quiche/src/http2/decoder/decode_buffer.h" #include "net/third_party/quiche/src/http2/decoder/decode_status.h" #include "net/third_party/quiche/src/http2/platform/api/http2_export.h" -#include "net/third_party/quiche/src/http2/platform/api/http2_flags.h" #include "net/third_party/quiche/src/http2/platform/api/http2_string.h" namespace http2 { @@ -119,12 +111,6 @@ #endif } - // If true, decode integers up to 2^64 - 1, and accept at most 10 extension - // bytes (some of which might be padding). - // If false, decode integers up to 2^28 + 2^prefix_length - 2, and accept at - // most 5 extension bytes (some of which might be padding). - bool decode_64_bits_ = GetHttp2ReloadableFlag(http2_varint_decode_64_bits); - // These fields are initialized just to keep ASAN happy about reading // them from DebugString().
diff --git a/http2/hpack/varint/hpack_varint_decoder_test.cc b/http2/hpack/varint/hpack_varint_decoder_test.cc index e36ad07..32a4a30 100644 --- a/http2/hpack/varint/hpack_varint_decoder_test.cc +++ b/http2/hpack/varint/hpack_varint_decoder_test.cc
@@ -22,32 +22,13 @@ namespace test { namespace { -// Save previous value of flag and restore on destruction. -class FlagSaver { - public: - FlagSaver() = delete; - explicit FlagSaver(bool decode_64_bits) - : saved_value_(GetHttp2ReloadableFlag(http2_varint_decode_64_bits)) { - SetHttp2ReloadableFlag(http2_varint_decode_64_bits, decode_64_bits); - } - ~FlagSaver() { - SetHttp2ReloadableFlag(http2_varint_decode_64_bits, saved_value_); - } - - private: - const bool saved_value_; -}; - -class HpackVarintDecoderTest - : public RandomDecoderTest, - public ::testing::WithParamInterface< - ::testing::tuple<bool, uint8_t, const char*>> { +class HpackVarintDecoderTest : public RandomDecoderTest, + public ::testing::WithParamInterface< + ::testing::tuple<uint8_t, const char*>> { protected: HpackVarintDecoderTest() - : decode_64_bits_(::testing::get<0>(GetParam())), - high_bits_(::testing::get<1>(GetParam())), - suffix_(Http2HexDecode(::testing::get<2>(GetParam()))), - flag_saver_(decode_64_bits_), + : high_bits_(::testing::get<0>(GetParam())), + suffix_(Http2HexDecode(::testing::get<1>(GetParam()))), prefix_length_(0) {} void DecodeExpectSuccess(Http2StringPiece data, @@ -81,8 +62,6 @@ EXPECT_TRUE(Decode(data, prefix_length, validator)); } - bool decode_64_bits() const { return decode_64_bits_; } - private: AssertionResult Decode(Http2StringPiece data, uint32_t prefix_length, @@ -119,16 +98,11 @@ return decoder_.Resume(b); } - // Test new or old behavior. - const bool decode_64_bits_; // Bits of the first byte not part of the prefix. const uint8_t high_bits_; // Extra bytes appended to the input. const Http2String suffix_; - // |flag_saver_| must preceed |decoder_| so that the flag is already set when - // |decoder_| is constructed. - FlagSaver flag_saver_; HpackVarintDecoder decoder_; uint8_t prefix_length_; }; @@ -137,15 +111,11 @@ HpackVarintDecoderTest, HpackVarintDecoderTest, ::testing::Combine( - // Test both the new version (supporting 64 bit integers) and the old - // one (only supporting up to 2^28 + 2^prefix_length - 2. - ::testing::Bool(), // Bits of the first byte not part of the prefix should be ignored. ::testing::Values(0b00000000, 0b11111111, 0b10101010), // Extra bytes appended to the input should be ignored. ::testing::Values("", "00", "666f6f"))); -// Test data used when decode_64_bits() == true. struct { const char* data; uint32_t prefix_length; @@ -289,124 +259,14 @@ {"1f9a0a", 5, 1337}, }; -// Test data used when decode_64_bits() == false. -struct { - const char* data; - uint32_t prefix_length; - uint64_t expected_value; -} kSuccessTestDataOld[] = { - // Zero value with different prefix lengths. - {"00", 3, 0}, - {"00", 4, 0}, - {"00", 5, 0}, - {"00", 6, 0}, - {"00", 7, 0}, - // Small values that fit in the prefix. - {"06", 3, 6}, - {"0d", 4, 13}, - {"10", 5, 16}, - {"29", 6, 41}, - {"56", 7, 86}, - // Values of 2^n-1, which have an all-zero extension byte. - {"0700", 3, 7}, - {"0f00", 4, 15}, - {"1f00", 5, 31}, - {"3f00", 6, 63}, - {"7f00", 7, 127}, - // Values of 2^n-1, plus one extra byte of padding. - {"078000", 3, 7}, - {"0f8000", 4, 15}, - {"1f8000", 5, 31}, - {"3f8000", 6, 63}, - {"7f8000", 7, 127}, - // Values requiring one extension byte. - {"0760", 3, 103}, - {"0f2a", 4, 57}, - {"1f7f", 5, 158}, - {"3f02", 6, 65}, - {"7f49", 7, 200}, - // Values requiring one extension byte, plus one byte of padding. - {"07e000", 3, 103}, - {"0faa00", 4, 57}, - {"1fff00", 5, 158}, - {"3f8200", 6, 65}, - {"7fc900", 7, 200}, - // Values requiring one extension byte, plus two bytes of padding. - {"07e08000", 3, 103}, - {"0faa8000", 4, 57}, - {"1fff8000", 5, 158}, - {"3f828000", 6, 65}, - {"7fc98000", 7, 200}, - // Values requiring one extension byte, plus the maximum amount of padding. - {"07e080808000", 3, 103}, - {"0faa80808000", 4, 57}, - {"1fff80808000", 5, 158}, - {"3f8280808000", 6, 65}, - {"7fc980808000", 7, 200}, - // Values requiring two extension bytes. - {"07b260", 3, 12345}, - {"0f8a2a", 4, 5401}, - {"1fa87f", 5, 16327}, - {"3fd002", 6, 399}, - {"7fff49", 7, 9598}, - // Values requiring two extension bytes, plus one byte of padding. - {"07b2e000", 3, 12345}, - {"0f8aaa00", 4, 5401}, - {"1fa8ff00", 5, 16327}, - {"3fd08200", 6, 399}, - {"7fffc900", 7, 9598}, - // Values requiring two extension bytes, plus the maximum amount of padding. - {"07b2e0808000", 3, 12345}, - {"0f8aaa808000", 4, 5401}, - {"1fa8ff808000", 5, 16327}, - {"3fd082808000", 6, 399}, - {"7fffc9808000", 7, 9598}, - // Values requiring three extension bytes. - {"078ab260", 3, 1579281}, - {"0fc18a2a", 4, 689488}, - {"1fada87f", 5, 2085964}, - {"3fa0d002", 6, 43103}, - {"7ffeff49", 7, 1212541}, - // Values requiring three extension bytes, plus one byte of padding. - {"078ab2e000", 3, 1579281}, - {"0fc18aaa00", 4, 689488}, - {"1fada8ff00", 5, 2085964}, - {"3fa0d08200", 6, 43103}, - {"7ffeffc900", 7, 1212541}, - // Values requiring four extension bytes. - {"079f8ab260", 3, 202147110}, - {"0fa2c18a2a", 4, 88252593}, - {"1fd0ada87f", 5, 266999535}, - {"3ff9a0d002", 6, 5509304}, - {"7f9efeff49", 7, 155189149}, - // Values requiring four extension bytes, plus one byte of padding. - {"079f8ab2e000", 3, 202147110}, - {"0fa2c18aaa00", 4, 88252593}, - {"1fd0ada8ff00", 5, 266999535}, - {"3ff9a0d08200", 6, 5509304}, - {"7f9efeffc900", 7, 155189149}, - // Examples from RFC7541 C.1. - {"0a", 5, 10}, - {"1f9a0a", 5, 1337}, -}; - TEST_P(HpackVarintDecoderTest, Success) { - if (decode_64_bits()) { for (size_t i = 0; i < HTTP2_ARRAYSIZE(kSuccessTestData); ++i) { DecodeExpectSuccess(Http2HexDecode(kSuccessTestData[i].data), kSuccessTestData[i].prefix_length, kSuccessTestData[i].expected_value); } - } else { - for (size_t i = 0; i < HTTP2_ARRAYSIZE(kSuccessTestDataOld); ++i) { - DecodeExpectSuccess(Http2HexDecode(kSuccessTestDataOld[i].data), - kSuccessTestDataOld[i].prefix_length, - kSuccessTestDataOld[i].expected_value); - } - } } -// Test data used when decode_64_bits() == true. struct { const char* data; uint32_t prefix_length; @@ -440,45 +300,11 @@ {"7f80ffffffffffffffff8100", 7}, {"ff80feffffffffffffff8100", 8}}; -// Test data used when decode_64_bits() == false. -// In this mode, HpackVarintDecoder allows at most five extension bytes, -// and fifth extension byte must be zero. -struct { - const char* data; - uint32_t prefix_length; -} kErrorTestDataOld[] = { - // Maximum number of extension bytes but last byte is non-zero. - {"078080808001", 3}, - {"0f8080808001", 4}, - {"1f8080808001", 5}, - {"3f8080808001", 6}, - {"7f8080808001", 7}, - // Too many extension bytes, all 0s (except for extension bit in each byte). - {"078080808080", 3}, - {"0f8080808080", 4}, - {"1f8080808080", 5}, - {"3f8080808080", 6}, - {"7f8080808080", 7}, - // Too many extension bytes, all 1s. - {"07ffffffffff", 3}, - {"0fffffffffff", 4}, - {"1fffffffffff", 5}, - {"3fffffffffff", 6}, - {"7fffffffffff", 7}, -}; - TEST_P(HpackVarintDecoderTest, Error) { - if (decode_64_bits()) { for (size_t i = 0; i < HTTP2_ARRAYSIZE(kErrorTestData); ++i) { DecodeExpectError(Http2HexDecode(kErrorTestData[i].data), kErrorTestData[i].prefix_length); } - } else { - for (size_t i = 0; i < HTTP2_ARRAYSIZE(kErrorTestDataOld); ++i) { - DecodeExpectError(Http2HexDecode(kErrorTestDataOld[i].data), - kErrorTestDataOld[i].prefix_length); - } - } } } // namespace
diff --git a/http2/hpack/varint/hpack_varint_round_trip_test.cc b/http2/hpack/varint/hpack_varint_round_trip_test.cc index 3299d5e..cd26553 100644 --- a/http2/hpack/varint/hpack_varint_round_trip_test.cc +++ b/http2/hpack/varint/hpack_varint_round_trip_test.cc
@@ -22,29 +22,11 @@ using ::testing::AssertionFailure; using ::testing::AssertionSuccess; -using ::testing::Bool; -using ::testing::WithParamInterface; namespace http2 { namespace test { namespace { -// Save previous value of flag and restore on destruction. -class FlagSaver { - public: - FlagSaver() = delete; - explicit FlagSaver(bool decode_64_bits) - : saved_value_(GetHttp2ReloadableFlag(http2_varint_decode_64_bits)) { - SetHttp2ReloadableFlag(http2_varint_decode_64_bits, decode_64_bits); - } - ~FlagSaver() { - SetHttp2ReloadableFlag(http2_varint_decode_64_bits, saved_value_); - } - - private: - const bool saved_value_; -}; - // Returns the highest value with the specified number of extension bytes // and the specified prefix length (bits). uint64_t HiValueOfExtensionBytes(uint32_t extension_bytes, @@ -53,13 +35,9 @@ (extension_bytes == 0 ? 0 : (1LLU << (extension_bytes * 7))); } -class HpackVarintRoundTripTest : public RandomDecoderTest, - public WithParamInterface<bool> { +class HpackVarintRoundTripTest : public RandomDecoderTest { protected: - HpackVarintRoundTripTest() - : decode_64_bits_(GetParam()), - flag_saver_(decode_64_bits_), - prefix_length_(0) {} + HpackVarintRoundTripTest() : prefix_length_(0) {} DecodeStatus StartDecoding(DecodeBuffer* b) override { CHECK_LT(0u, b->Remaining()); @@ -260,22 +238,14 @@ EncodeAndDecodeValues(values, prefix_length, expected_bytes); } - // |flag_saver_| must preceed |decoder_| so that the flag is already set when - // |decoder_| is constructed. - const bool decode_64_bits_; - FlagSaver flag_saver_; HpackVarintDecoder decoder_; Http2String buffer_; uint8_t prefix_length_; }; -INSTANTIATE_TEST_CASE_P(HpackVarintRoundTripTest, - HpackVarintRoundTripTest, - Bool()); - // To help me and future debuggers of varint encodings, this LOGs out the // transition points where a new extension byte is added. -TEST_P(HpackVarintRoundTripTest, Encode) { +TEST_F(HpackVarintRoundTripTest, Encode) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t a = HiValueOfExtensionBytes(0, prefix_length); const uint64_t b = HiValueOfExtensionBytes(1, prefix_length); @@ -300,19 +270,13 @@ b - 1, b, b + 1, b + 2, b + 3, // Force line break. c - 1, c, c + 1, c + 2, c + 3, // Force line break. d - 1, d, d + 1, d + 2, d + 3, // Force line break. - e - 1, e, e + 1, e + 2, e + 3 // Force line break. + e - 1, e, e + 1, e + 2, e + 3, // Force line break. + f - 1, f, f + 1, f + 2, f + 3, // Force line break. + g - 1, g, g + 1, g + 2, g + 3, // Force line break. + h - 1, h, h + 1, h + 2, h + 3, // Force line break. + i - 1, i, i + 1, i + 2, i + 3, // Force line break. + j - 1, j, j + 1, j + 2, j + 3, // Force line break. }; - if (decode_64_bits_) { - for (auto value : { - f - 1, f, f + 1, f + 2, f + 3, // Force line break. - g - 1, g, g + 1, g + 2, g + 3, // Force line break. - h - 1, h, h + 1, h + 2, h + 3, // Force line break. - i - 1, i, i + 1, i + 2, i + 3, // Force line break. - j - 1, j, j + 1, j + 2, j + 3, // Force line break. - }) { - values.push_back(value); - } - } for (uint64_t value : values) { EncodeNoRandom(value, prefix_length); @@ -323,7 +287,7 @@ } } -TEST_P(HpackVarintRoundTripTest, FromSpec1337) { +TEST_F(HpackVarintRoundTripTest, FromSpec1337) { DecodeBuffer b(Http2StringPiece("\x1f\x9a\x0a")); uint32_t prefix_length = 5; uint8_t p = b.DecodeUInt8(); @@ -340,7 +304,7 @@ } // Test all the values that fit into the prefix (one less than the mask). -TEST_P(HpackVarintRoundTripTest, ValidatePrefixOnly) { +TEST_F(HpackVarintRoundTripTest, ValidatePrefixOnly) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint8_t prefix_mask = (1 << prefix_length) - 1; EncodeAndDecodeValuesInRange(0, prefix_mask, prefix_length, 1); @@ -348,7 +312,7 @@ } // Test all values that require exactly 1 extension byte. -TEST_P(HpackVarintRoundTripTest, ValidateOneExtensionByte) { +TEST_F(HpackVarintRoundTripTest, ValidateOneExtensionByte) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(0, prefix_length) + 1; EncodeAndDecodeValuesInRange(start, 128, prefix_length, 2); @@ -356,7 +320,7 @@ } // Test *some* values that require exactly 2 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateTwoExtensionBytes) { +TEST_F(HpackVarintRoundTripTest, ValidateTwoExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(1, prefix_length) + 1; const uint64_t range = 127 << 7; @@ -366,7 +330,7 @@ } // Test *some* values that require 3 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateThreeExtensionBytes) { +TEST_F(HpackVarintRoundTripTest, ValidateThreeExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(2, prefix_length) + 1; const uint64_t range = 127 << 14; @@ -376,7 +340,7 @@ } // Test *some* values that require 4 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateFourExtensionBytes) { +TEST_F(HpackVarintRoundTripTest, ValidateFourExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(3, prefix_length) + 1; const uint64_t range = 127 << 21; @@ -386,11 +350,7 @@ } // Test *some* values that require 5 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateFiveExtensionBytes) { - if (!decode_64_bits_) { - return; - } - +TEST_F(HpackVarintRoundTripTest, ValidateFiveExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(4, prefix_length) + 1; const uint64_t range = 127llu << 28; @@ -400,11 +360,7 @@ } // Test *some* values that require 6 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateSixExtensionBytes) { - if (!decode_64_bits_) { - return; - } - +TEST_F(HpackVarintRoundTripTest, ValidateSixExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(5, prefix_length) + 1; const uint64_t range = 127llu << 35; @@ -414,11 +370,7 @@ } // Test *some* values that require 7 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateSevenExtensionBytes) { - if (!decode_64_bits_) { - return; - } - +TEST_F(HpackVarintRoundTripTest, ValidateSevenExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(6, prefix_length) + 1; const uint64_t range = 127llu << 42; @@ -428,11 +380,7 @@ } // Test *some* values that require 8 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateEightExtensionBytes) { - if (!decode_64_bits_) { - return; - } - +TEST_F(HpackVarintRoundTripTest, ValidateEightExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(7, prefix_length) + 1; const uint64_t range = 127llu << 49; @@ -442,11 +390,7 @@ } // Test *some* values that require 9 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateNineExtensionBytes) { - if (!decode_64_bits_) { - return; - } - +TEST_F(HpackVarintRoundTripTest, ValidateNineExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(8, prefix_length) + 1; const uint64_t range = 127llu << 56; @@ -456,11 +400,7 @@ } // Test *some* values that require 10 extension bytes. -TEST_P(HpackVarintRoundTripTest, ValidateTenExtensionBytes) { - if (!decode_64_bits_) { - return; - } - +TEST_F(HpackVarintRoundTripTest, ValidateTenExtensionBytes) { for (int prefix_length = 3; prefix_length <= 8; ++prefix_length) { const uint64_t start = HiValueOfExtensionBytes(9, prefix_length) + 1; const uint64_t range = std::numeric_limits<uint64_t>::max() - start; @@ -469,45 +409,6 @@ } } -// Test the value one larger than the largest that can be decoded. -TEST_P(HpackVarintRoundTripTest, ValueTooLarge) { - // New implementation can decode any integer that HpackVarintEncoder can - // encode. - if (decode_64_bits_) { - return; - } - - for (prefix_length_ = 3; prefix_length_ <= 8; ++prefix_length_) { - const uint64_t too_large = (1 << 28) + (1 << prefix_length_) - 1; - const uint32_t expected_offset = 6; - HpackBlockBuilder bb; - bb.AppendHighBitsAndVarint(0, prefix_length_, too_large); - buffer_ = bb.buffer(); - - // The validator is called after each of the several times that the input - // DecodeBuffer is decoded, each with a different segmentation of the input. - // Validate that decoder_.value() matches the expected value. - bool validated = false; - Validator validator = [&validated, expected_offset]( - const DecodeBuffer& db, - DecodeStatus status) -> AssertionResult { - validated = true; - VERIFY_EQ(DecodeStatus::kDecodeError, status); - VERIFY_EQ(expected_offset, db.Offset()); - return AssertionSuccess(); - }; - - // StartDecoding, above, requires the DecodeBuffer be non-empty so that it - // can call Start with the prefix byte. - bool return_non_zero_on_first = true; - DecodeBuffer b(buffer_); - EXPECT_TRUE( - DecodeAndValidateSeveralWays(&b, return_non_zero_on_first, validator)); - EXPECT_EQ(expected_offset, b.Offset()); - EXPECT_TRUE(validated); - } -} - } // namespace } // namespace test } // namespace http2