Fix test bug detected by quiche.ubsan. PiperOrigin-RevId: 421668427
diff --git a/http2/decoder/decode_buffer.h b/http2/decoder/decode_buffer.h index 4757c06..3d0f5d5 100644 --- a/http2/decoder/decode_buffer.h +++ b/http2/decoder/decode_buffer.h
@@ -26,13 +26,15 @@ class QUICHE_EXPORT_PRIVATE DecodeBuffer { public: + // We assume the decode buffers will typically be modest in size (i.e. often a + // few KB, perhaps as high as 100KB). Let's make sure during testing that we + // don't go very high, with 32MB selected rather arbitrarily. This is exposed + // to support testing. + static constexpr size_t kMaxDecodeBufferLength = 1 << 25; + DecodeBuffer(const char* buffer, size_t len) : buffer_(buffer), cursor_(buffer), beyond_(buffer + len) { QUICHE_DCHECK(buffer != nullptr); - // We assume the decode buffers will typically be modest in size (i.e. often - // a few KB, perhaps as high as 100KB). Let's make sure during testing that - // we don't go very high, with 32MB selected rather arbitrarily. - const size_t kMaxDecodeBufferLength = 1 << 25; QUICHE_DCHECK_LE(len, kMaxDecodeBufferLength); } explicit DecodeBuffer(absl::string_view s)
diff --git a/http2/decoder/decode_buffer_test.cc b/http2/decoder/decode_buffer_test.cc index 685107a..54c0fea 100644 --- a/http2/decoder/decode_buffer_test.cc +++ b/http2/decoder/decode_buffer_test.cc
@@ -132,9 +132,14 @@ TEST(DecodeBufferDeathTest, ModestBufferSizeRequired) { EXPECT_DEBUG_DEATH( { - const char data[] = "abc"; - size_t len = 0; - DecodeBuffer b(data, ~len); + // This depends on being able to allocate a fairly large array on the + // stack. If that fails, we can instead do this: + // + // std::string data(DecodeBuffer::kMaxDecodeBufferLength + 1, ' '); + // DecodeBuffer b(data.data(), data.size()); + + const char data[DecodeBuffer::kMaxDecodeBufferLength + 1] = {}; + DecodeBuffer b(data, sizeof data); }, "Max.*Length"); }