Add failure test cases from zlib's inflate test suite

Signed-off-by: Damian Jarek <damian.jarek93@gmail.com>
This commit is contained in:
Damian Jarek
2019-07-29 20:05:50 +02:00
committed by Vinnie Falco
parent 7dbb3bd417
commit 84bf4c5362

View File

@@ -362,6 +362,57 @@ public:
#endif
}
void testInflateErrors()
{
auto check =
[](std::initializer_list<std::uint8_t> 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();
}
};