1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-29 11:21:22 +03:00

Streaming decompression can detect incorrect header ID sooner

Streaming decompression used to wait for a minimum of 5 bytes before attempting decoding.
This meant that, in the case that only a few bytes (<5) were provided,
and assuming these bytes are incorrect,
there would be no error reported.
The streaming API would simply request more data, waiting for at least 5 bytes.

This PR makes it possible to detect incorrect Frame IDs as soon as the first byte is provided.

Fix #3169
This commit is contained in:
Yann Collet
2022-06-21 18:14:11 -07:00
parent f6ef14329f
commit 91aeade735
2 changed files with 47 additions and 10 deletions

View File

@ -424,6 +424,15 @@ static int basicUnitTests(U32 seed, double compressibility)
} }
DISPLAYLEVEL(3, "OK \n");
/* check decompression fails early if first bytes are wrong */
DISPLAYLEVEL(3, "test%3i : early decompression error if first bytes are incorrect : ", testNb++);
{ const char buf[3] = { 0 }; /* too short, not enough to start decoding header */
ZSTD_inBuffer inb = { buf, sizeof(buf), 0 };
size_t const remaining = ZSTD_decompressStream(zd, &outBuff, &inb);
if (!ZSTD_isError(remaining)) goto _output_error; /* should have errored out immediately (note: this does not test the exact error code) */
}
DISPLAYLEVEL(3, "OK \n");
/* context size functions */
DISPLAYLEVEL(3, "test%3i : estimate DStream size : ", testNb++);
{ ZSTD_frameHeader fhi;