Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/decompress/zstd_decompress.c
Original file line number Diff line number Diff line change
Expand Up @@ -429,10 +429,13 @@ static size_t ZSTD_frameHeaderSize_internal(const void* src, size_t srcSize, ZST

/** ZSTD_frameHeaderSize() :
* srcSize must be >= ZSTD_frameHeaderSize_prefix.
* @return : size of the Frame Header,
* @return : size of the Frame Header (ZSTD_SKIPPABLEHEADERSIZE for a skippable frame),
* or an error code (if srcSize is too small) */
size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize)
{
RETURN_ERROR_IF(srcSize < ZSTD_FRAMEHEADERSIZE_PREFIX(ZSTD_f_zstd1), srcSize_wrong, "");
if (ZSTD_isSkippableFrame(src, srcSize))
return ZSTD_SKIPPABLEHEADERSIZE; /* magic number + frame size */
return ZSTD_frameHeaderSize_internal(src, srcSize, ZSTD_f_zstd1);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/zstd.h
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size

/*! ZSTD_frameHeaderSize() :
* srcSize must be large enough, aka >= ZSTD_FRAMEHEADERSIZE_PREFIX.
* @return : size of the Frame Header,
* @return : size of the Frame Header (ZSTD_SKIPPABLEHEADERSIZE for a skippable frame),
* or an error code (if srcSize is too small) */
ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);

Expand Down
5 changes: 5 additions & 0 deletions tests/fuzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -4702,6 +4702,11 @@ static int basicUnitTests(U32 const seed, double compressibility)
CHECK(zfh.frameContentSize == skippableFrameSize - ZSTD_SKIPPABLEHEADERSIZE);
}
DISPLAYLEVEL(3, "OK \n");

DISPLAYLEVEL(3, "test%3i : ZSTD_frameHeaderSize on skippable frame : ", testNb++);
CHECK_EQ(ZSTD_frameHeaderSize(skippableFrame, skippableFrameSize), ZSTD_SKIPPABLEHEADERSIZE);
CHECK_EQ(ZSTD_frameHeaderSize(skippableFrame, ZSTD_FRAMEHEADERSIZE_PREFIX(ZSTD_f_zstd1)), ZSTD_SKIPPABLEHEADERSIZE);
DISPLAYLEVEL(3, "OK \n");
}

/* error string tests */
Expand Down