From 84bf4c5362b09e3ac9f4753cf3dce4758582e755 Mon Sep 17 00:00:00 2001 From: Damian Jarek Date: Mon, 29 Jul 2019 20:05:50 +0200 Subject: [PATCH] Add failure test cases from zlib's inflate test suite Signed-off-by: Damian Jarek --- test/beast/zlib/inflate_stream.cpp | 52 ++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/test/beast/zlib/inflate_stream.cpp b/test/beast/zlib/inflate_stream.cpp index 932df67f..2e37decf 100644 --- a/test/beast/zlib/inflate_stream.cpp +++ b/test/beast/zlib/inflate_stream.cpp @@ -362,6 +362,57 @@ public: #endif } + void testInflateErrors() + { + + auto check = + [](std::initializer_list const& in, + error_code expected) + { + std::string out(1024, 0); + z_params zs; + zs.next_in = &*in.begin(); + zs.next_out = &out[0]; + zs.avail_in = in.size(); + zs.avail_out = out.size(); + inflate_stream is; + is.reset(15); + boost::system::error_code ec; + is.write(zs,Flush::sync, ec); + BEAST_EXPECT(ec == expected); + }; + check({0x00, 0x00, 0x00, 0x00, 0x00}, + error::invalid_stored_length); + check({0x03, 0x00}, + error::end_of_stream); + check({0x06}, + error::invalid_block_type); + check({0xfc, 0x00, 0x00}, + error::too_many_symbols); + check({0x04, 0x00, 0xfe, 0xff}, + error::incomplete_length_set); + check({0x04, 0x00, 0x24, 0x49, 0x00}, + error::invalid_bit_length_repeat); + check({0x04, 0x00, 0x24, 0xe9, 0xff, 0xff}, + error::invalid_bit_length_repeat); + check({0x04, 0x00, 0x24, 0xe9, 0xff, 0x6d}, + error::missing_eob); + check({0x04, 0x80, 0x49, 0x92, 0x24, 0x49, 0x92, 0x24, + 0x71, 0xff, 0xff, 0x93, 0x11, 0x00}, + error::over_subscribed_length); + check({0x04, 0x80, 0x49, 0x92, 0x24, 0x0f, 0xb4, 0xff, + 0xff, 0xc3, 0x84}, + error::incomplete_length_set); + check({0x04, 0xc0, 0x81, 0x08, 0x00, 0x00, 0x00, 0x00, + 0x20, 0x7f, 0xeb, 0x0b, 0x00, 0x00}, + error::invalid_literal_length); + check({0x02, 0x7e, 0xff, 0xff}, + error::invalid_distance_code); + check({0x0c, 0xc0, 0x81, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x90, 0xff, 0x6b, 0x04, 0x00}, + error::invalid_distance); + } + void run() override { @@ -369,6 +420,7 @@ public: "sizeof(inflate_stream) == " << sizeof(inflate_stream) << std::endl; testInflate(); + testInflateErrors(); } };