Skip to content

Commit b6ea2dc

Browse files
committed
Add a disabled test for the length check in process_zlib()
1 parent 6822c15 commit b6ea2dc

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/unittest.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,29 @@ TEST(KaitaiStreamTest, process_zlib_ok)
225225
EXPECT_EQ(kaitai::kstream::process_zlib(ks.read_bytes_full()), "Hi");
226226
}
227227

228+
// It's probably not a good idea to run this test in CI because it has to allocate 4 GiB of memory.
229+
// That's why it is disabled (see
230+
// https://google.github.io/googletest/advanced.html#temporarily-disabling-tests). You can still run
231+
// it locally using `.build/run-unittest --valgrind -- --gtest_also_run_disabled_tests` or
232+
// `.build\run-unittest.ps1 --gtest_also_run_disabled_tests`.
233+
TEST(KaitaiStreamTest, DISABLED_process_zlib_input_too_long)
234+
{
235+
try {
236+
kaitai::kstream::process_zlib(
237+
std::string(
238+
static_cast<std::string::size_type>(std::numeric_limits<unsigned>::max()) + 1,
239+
'\x00'
240+
)
241+
);
242+
FAIL() << "Expected runtime_error exception";
243+
} catch (const std::length_error& e) {
244+
EXPECT_EQ(e.what(), std::string(
245+
"process_zlib: input is 4294967296 bytes long, which exceeds"
246+
" the maximum supported length of 4294967295 bytes"
247+
));
248+
}
249+
}
250+
228251
// Tests a failed zlib decompression due to the `inflate()` function returning `Z_BUF_ERROR`.
229252
TEST(KaitaiStreamTest, process_zlib_z_buf_error)
230253
{

0 commit comments

Comments
 (0)