Merge pull request #4228 from facebook/skippableMagicVariant
ZSTD_getFrameHeader() for skippable frames
This commit is contained in:
@@ -465,7 +465,7 @@ void zstd_register_sequence_producer(
|
|||||||
*
|
*
|
||||||
* See zstd_lib.h.
|
* See zstd_lib.h.
|
||||||
*/
|
*/
|
||||||
typedef ZSTD_frameHeader zstd_frame_header;
|
typedef ZSTD_FrameHeader zstd_frame_header;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* zstd_get_frame_header() - extracts parameters from a zstd or skippable frame
|
* zstd_get_frame_header() - extracts parameters from a zstd or skippable frame
|
||||||
|
|||||||
@@ -1244,13 +1244,13 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|||||||
or an error code (if srcSize is too small)
|
or an error code (if srcSize is too small)
|
||||||
</p></pre><BR>
|
</p></pre><BR>
|
||||||
|
|
||||||
<pre><b>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
|
<pre><b>typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_FrameType_e;
|
||||||
</b></pre><BR>
|
</b></pre><BR>
|
||||||
<pre><b>typedef struct {
|
<pre><b>typedef struct {
|
||||||
unsigned long long frameContentSize; </b>/* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */<b>
|
unsigned long long frameContentSize; </b>/* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */<b>
|
||||||
unsigned long long windowSize; </b>/* can be very large, up to <= frameContentSize */<b>
|
unsigned long long windowSize; </b>/* can be very large, up to <= frameContentSize */<b>
|
||||||
unsigned blockSizeMax;
|
unsigned blockSizeMax;
|
||||||
ZSTD_frameType_e frameType; </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
|
ZSTD_FrameType_e frameType; </b>/* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */<b>
|
||||||
unsigned headerSize;
|
unsigned headerSize;
|
||||||
unsigned dictID;
|
unsigned dictID;
|
||||||
unsigned checksumFlag;
|
unsigned checksumFlag;
|
||||||
@@ -1258,11 +1258,11 @@ size_t ZSTD_sizeof_DDict(const ZSTD_DDict* ddict);
|
|||||||
unsigned _reserved2;
|
unsigned _reserved2;
|
||||||
} ZSTD_frameHeader;
|
} ZSTD_frameHeader;
|
||||||
</b></pre><BR>
|
</b></pre><BR>
|
||||||
<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); </b>/**< doesn't consume input */<b>
|
<pre><b>ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize); </b>/**< doesn't consume input */<b>
|
||||||
</b>/*! ZSTD_getFrameHeader_advanced() :<b>
|
</b>/*! ZSTD_getFrameHeader_advanced() :<b>
|
||||||
* same as ZSTD_getFrameHeader(),
|
* same as ZSTD_getFrameHeader(),
|
||||||
* with added capability to select a format (like ZSTD_f_zstd1_magicless) */
|
* with added capability to select a format (like ZSTD_f_zstd1_magicless) */
|
||||||
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
||||||
</b><p> decode Frame Header, or requires larger `srcSize`.
|
</b><p> decode Frame Header, or requires larger `srcSize`.
|
||||||
@return : 0, `zfhPtr` is correctly filled,
|
@return : 0, `zfhPtr` is correctly filled,
|
||||||
>0, `srcSize` is too small, value is wanted `srcSize` amount,
|
>0, `srcSize` is too small, value is wanted `srcSize` amount,
|
||||||
@@ -2124,7 +2124,7 @@ ZSTDLIB_STATIC_API size_t ZSTD_compressBegin_usingCDict(ZSTD_CCtx* cctx, const Z
|
|||||||
>0 : `srcSize` is too small, please provide at least result bytes on next attempt.
|
>0 : `srcSize` is too small, please provide at least result bytes on next attempt.
|
||||||
errorCode, which can be tested using ZSTD_isError().
|
errorCode, which can be tested using ZSTD_isError().
|
||||||
|
|
||||||
It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
|
It fills a ZSTD_FrameHeader structure with important information to correctly decode the frame,
|
||||||
such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
|
such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
|
||||||
Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
|
Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
|
||||||
As a consequence, check that values remain within valid application range.
|
As a consequence, check that values remain within valid application range.
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ typedef struct {
|
|||||||
* Is the dictionary cold?
|
* Is the dictionary cold?
|
||||||
* Only set on decompression.
|
* Only set on decompression.
|
||||||
*/
|
*/
|
||||||
unsigned dictionaryIsCold;
|
int dictionaryIsCold;
|
||||||
/**
|
/**
|
||||||
* The dictionary size or zero if no dictionary.
|
* The dictionary size or zero if no dictionary.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -444,7 +444,7 @@ size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize)
|
|||||||
* @return : 0, `zfhPtr` is correctly filled,
|
* @return : 0, `zfhPtr` is correctly filled,
|
||||||
* >0, `srcSize` is too small, value is wanted `srcSize` amount,
|
* >0, `srcSize` is too small, value is wanted `srcSize` amount,
|
||||||
** or an error code, which can be tested using ZSTD_isError() */
|
** or an error code, which can be tested using ZSTD_isError() */
|
||||||
size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format)
|
size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format)
|
||||||
{
|
{
|
||||||
const BYTE* ip = (const BYTE*)src;
|
const BYTE* ip = (const BYTE*)src;
|
||||||
size_t const minInputSize = ZSTD_startingInputLength(format);
|
size_t const minInputSize = ZSTD_startingInputLength(format);
|
||||||
@@ -484,8 +484,10 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
|
|||||||
if (srcSize < ZSTD_SKIPPABLEHEADERSIZE)
|
if (srcSize < ZSTD_SKIPPABLEHEADERSIZE)
|
||||||
return ZSTD_SKIPPABLEHEADERSIZE; /* magic number + frame length */
|
return ZSTD_SKIPPABLEHEADERSIZE; /* magic number + frame length */
|
||||||
ZSTD_memset(zfhPtr, 0, sizeof(*zfhPtr));
|
ZSTD_memset(zfhPtr, 0, sizeof(*zfhPtr));
|
||||||
zfhPtr->frameContentSize = MEM_readLE32((const char *)src + ZSTD_FRAMEIDSIZE);
|
|
||||||
zfhPtr->frameType = ZSTD_skippableFrame;
|
zfhPtr->frameType = ZSTD_skippableFrame;
|
||||||
|
zfhPtr->dictID = MEM_readLE32(src) - ZSTD_MAGIC_SKIPPABLE_START;
|
||||||
|
zfhPtr->headerSize = ZSTD_SKIPPABLEHEADERSIZE;
|
||||||
|
zfhPtr->frameContentSize = MEM_readLE32((const char *)src + ZSTD_FRAMEIDSIZE);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
RETURN_ERROR(prefix_unknown, "");
|
RETURN_ERROR(prefix_unknown, "");
|
||||||
@@ -554,7 +556,7 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
|
|||||||
* @return : 0, `zfhPtr` is correctly filled,
|
* @return : 0, `zfhPtr` is correctly filled,
|
||||||
* >0, `srcSize` is too small, value is wanted `srcSize` amount,
|
* >0, `srcSize` is too small, value is wanted `srcSize` amount,
|
||||||
* or an error code, which can be tested using ZSTD_isError() */
|
* or an error code, which can be tested using ZSTD_isError() */
|
||||||
size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize)
|
size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
return ZSTD_getFrameHeader_advanced(zfhPtr, src, srcSize, ZSTD_f_zstd1);
|
return ZSTD_getFrameHeader_advanced(zfhPtr, src, srcSize, ZSTD_f_zstd1);
|
||||||
}
|
}
|
||||||
@@ -572,7 +574,7 @@ unsigned long long ZSTD_getFrameContentSize(const void *src, size_t srcSize)
|
|||||||
return ret == 0 ? ZSTD_CONTENTSIZE_UNKNOWN : ret;
|
return ret == 0 ? ZSTD_CONTENTSIZE_UNKNOWN : ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
{ ZSTD_frameHeader zfh;
|
{ ZSTD_FrameHeader zfh;
|
||||||
if (ZSTD_getFrameHeader(&zfh, src, srcSize) != 0)
|
if (ZSTD_getFrameHeader(&zfh, src, srcSize) != 0)
|
||||||
return ZSTD_CONTENTSIZE_ERROR;
|
return ZSTD_CONTENTSIZE_ERROR;
|
||||||
if (zfh.frameType == ZSTD_skippableFrame) {
|
if (zfh.frameType == ZSTD_skippableFrame) {
|
||||||
@@ -750,7 +752,7 @@ static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize
|
|||||||
const BYTE* const ipstart = ip;
|
const BYTE* const ipstart = ip;
|
||||||
size_t remainingSize = srcSize;
|
size_t remainingSize = srcSize;
|
||||||
size_t nbBlocks = 0;
|
size_t nbBlocks = 0;
|
||||||
ZSTD_frameHeader zfh;
|
ZSTD_FrameHeader zfh;
|
||||||
|
|
||||||
/* Extract Frame Header */
|
/* Extract Frame Header */
|
||||||
{ size_t const ret = ZSTD_getFrameHeader_advanced(&zfh, src, srcSize, format);
|
{ size_t const ret = ZSTD_getFrameHeader_advanced(&zfh, src, srcSize, format);
|
||||||
@@ -843,7 +845,7 @@ size_t ZSTD_decompressionMargin(void const* src, size_t srcSize)
|
|||||||
ZSTD_frameSizeInfo const frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize, ZSTD_f_zstd1);
|
ZSTD_frameSizeInfo const frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize, ZSTD_f_zstd1);
|
||||||
size_t const compressedSize = frameSizeInfo.compressedSize;
|
size_t const compressedSize = frameSizeInfo.compressedSize;
|
||||||
unsigned long long const decompressedBound = frameSizeInfo.decompressedBound;
|
unsigned long long const decompressedBound = frameSizeInfo.decompressedBound;
|
||||||
ZSTD_frameHeader zfh;
|
ZSTD_FrameHeader zfh;
|
||||||
|
|
||||||
FORWARD_IF_ERROR(ZSTD_getFrameHeader(&zfh, src, srcSize), "");
|
FORWARD_IF_ERROR(ZSTD_getFrameHeader(&zfh, src, srcSize), "");
|
||||||
if (ZSTD_isError(compressedSize) || decompressedBound == ZSTD_CONTENTSIZE_ERROR)
|
if (ZSTD_isError(compressedSize) || decompressedBound == ZSTD_CONTENTSIZE_ERROR)
|
||||||
@@ -917,7 +919,7 @@ static size_t ZSTD_setRleBlock(void* dst, size_t dstCapacity,
|
|||||||
return regenSize;
|
return regenSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ZSTD_DCtx_trace_end(ZSTD_DCtx const* dctx, U64 uncompressedSize, U64 compressedSize, unsigned streaming)
|
static void ZSTD_DCtx_trace_end(ZSTD_DCtx const* dctx, U64 uncompressedSize, U64 compressedSize, int streaming)
|
||||||
{
|
{
|
||||||
#if ZSTD_TRACE
|
#if ZSTD_TRACE
|
||||||
if (dctx->traceCtx && ZSTD_trace_decompress_end != NULL) {
|
if (dctx->traceCtx && ZSTD_trace_decompress_end != NULL) {
|
||||||
@@ -1641,7 +1643,7 @@ unsigned ZSTD_getDictID_fromDict(const void* dict, size_t dictSize)
|
|||||||
* ZSTD_getFrameHeader(), which will provide a more precise error code. */
|
* ZSTD_getFrameHeader(), which will provide a more precise error code. */
|
||||||
unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize)
|
unsigned ZSTD_getDictID_fromFrame(const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
ZSTD_frameHeader zfp = { 0, 0, 0, ZSTD_frame, 0, 0, 0, 0, 0 };
|
ZSTD_FrameHeader zfp = { 0, 0, 0, ZSTD_frame, 0, 0, 0, 0, 0 };
|
||||||
size_t const hError = ZSTD_getFrameHeader(&zfp, src, srcSize);
|
size_t const hError = ZSTD_getFrameHeader(&zfp, src, srcSize);
|
||||||
if (ZSTD_isError(hError)) return 0;
|
if (ZSTD_isError(hError)) return 0;
|
||||||
return zfp.dictID;
|
return zfp.dictID;
|
||||||
@@ -1999,7 +2001,7 @@ size_t ZSTD_estimateDStreamSize(size_t windowSize)
|
|||||||
size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize)
|
size_t ZSTD_estimateDStreamSize_fromFrame(const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
U32 const windowSizeMax = 1U << ZSTD_WINDOWLOG_MAX; /* note : should be user-selectable, but requires an additional parameter (or a dctx) */
|
U32 const windowSizeMax = 1U << ZSTD_WINDOWLOG_MAX; /* note : should be user-selectable, but requires an additional parameter (or a dctx) */
|
||||||
ZSTD_frameHeader zfh;
|
ZSTD_FrameHeader zfh;
|
||||||
size_t const err = ZSTD_getFrameHeader(&zfh, src, srcSize);
|
size_t const err = ZSTD_getFrameHeader(&zfh, src, srcSize);
|
||||||
if (ZSTD_isError(err)) return err;
|
if (ZSTD_isError(err)) return err;
|
||||||
RETURN_ERROR_IF(err>0, srcSize_wrong, "");
|
RETURN_ERROR_IF(err>0, srcSize_wrong, "");
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ struct ZSTD_DCtx_s
|
|||||||
const void* virtualStart; /* virtual start of previous segment if it was just before current one */
|
const void* virtualStart; /* virtual start of previous segment if it was just before current one */
|
||||||
const void* dictEnd; /* end of previous segment */
|
const void* dictEnd; /* end of previous segment */
|
||||||
size_t expected;
|
size_t expected;
|
||||||
ZSTD_frameHeader fParams;
|
ZSTD_FrameHeader fParams;
|
||||||
U64 processedCSize;
|
U64 processedCSize;
|
||||||
U64 decodedSize;
|
U64 decodedSize;
|
||||||
blockType_e bType; /* used in ZSTD_decompressContinue(), store blockType between block header decoding and block decompression stages */
|
blockType_e bType; /* used in ZSTD_decompressContinue(), store blockType between block header decoding and block decompression stages */
|
||||||
|
|||||||
+13
-11
@@ -1491,34 +1491,36 @@ ZSTDLIB_STATIC_API unsigned long long ZSTD_findDecompressedSize(const void* src,
|
|||||||
ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
|
ZSTDLIB_STATIC_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize);
|
||||||
|
|
||||||
/*! ZSTD_frameHeaderSize() :
|
/*! ZSTD_frameHeaderSize() :
|
||||||
* srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
|
* srcSize must be large enough, aka >= ZSTD_FRAMEHEADERSIZE_PREFIX.
|
||||||
* @return : size of the Frame Header,
|
* @return : size of the Frame Header,
|
||||||
* or an error code (if srcSize is too small) */
|
* or an error code (if srcSize is too small) */
|
||||||
ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
|
ZSTDLIB_STATIC_API size_t ZSTD_frameHeaderSize(const void* src, size_t srcSize);
|
||||||
|
|
||||||
typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_frameType_e;
|
typedef enum { ZSTD_frame, ZSTD_skippableFrame } ZSTD_FrameType_e;
|
||||||
|
#define ZSTD_frameType_e ZSTD_FrameType_e /* old name */
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */
|
unsigned long long frameContentSize; /* if == ZSTD_CONTENTSIZE_UNKNOWN, it means this field is not available. 0 means "empty" */
|
||||||
unsigned long long windowSize; /* can be very large, up to <= frameContentSize */
|
unsigned long long windowSize; /* can be very large, up to <= frameContentSize */
|
||||||
unsigned blockSizeMax;
|
unsigned blockSizeMax;
|
||||||
ZSTD_frameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */
|
ZSTD_FrameType_e frameType; /* if == ZSTD_skippableFrame, frameContentSize is the size of skippable content */
|
||||||
unsigned headerSize;
|
unsigned headerSize;
|
||||||
unsigned dictID;
|
unsigned dictID; /* for ZSTD_skippableFrame, contains the skippable magic variant [0-15] */
|
||||||
unsigned checksumFlag;
|
unsigned checksumFlag;
|
||||||
unsigned _reserved1;
|
unsigned _reserved1;
|
||||||
unsigned _reserved2;
|
unsigned _reserved2;
|
||||||
} ZSTD_frameHeader;
|
} ZSTD_FrameHeader;
|
||||||
|
#define ZSTD_frameHeader ZSTD_FrameHeader /* old name */
|
||||||
|
|
||||||
/*! ZSTD_getFrameHeader() :
|
/*! ZSTD_getFrameHeader() :
|
||||||
* decode Frame Header, or requires larger `srcSize`.
|
* decode Frame Header into `zfhPtr`, or requires larger `srcSize`.
|
||||||
* @return : 0, `zfhPtr` is correctly filled,
|
* @return : 0 => header is complete, `zfhPtr` is correctly filled,
|
||||||
* >0, `srcSize` is too small, @return value is the wanted `srcSize` amount,
|
* >0 => `srcSize` is too small, @return value is the wanted `srcSize` amount, `zfhPtr` is not filled,
|
||||||
* or an error code, which can be tested using ZSTD_isError() */
|
* or an error code, which can be tested using ZSTD_isError() */
|
||||||
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize); /**< doesn't consume input */
|
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize);
|
||||||
/*! ZSTD_getFrameHeader_advanced() :
|
/*! ZSTD_getFrameHeader_advanced() :
|
||||||
* same as ZSTD_getFrameHeader(),
|
* same as ZSTD_getFrameHeader(),
|
||||||
* with added capability to select a format (like ZSTD_f_zstd1_magicless) */
|
* with added capability to select a format (like ZSTD_f_zstd1_magicless) */
|
||||||
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
ZSTDLIB_STATIC_API size_t ZSTD_getFrameHeader_advanced(ZSTD_FrameHeader* zfhPtr, const void* src, size_t srcSize, ZSTD_format_e format);
|
||||||
|
|
||||||
/*! ZSTD_decompressionMargin() :
|
/*! ZSTD_decompressionMargin() :
|
||||||
* Zstd supports in-place decompression, where the input and output buffers overlap.
|
* Zstd supports in-place decompression, where the input and output buffers overlap.
|
||||||
@@ -3047,7 +3049,7 @@ size_t ZSTD_compressBegin_usingCDict_advanced(ZSTD_CCtx* const cctx, const ZSTD_
|
|||||||
>0 : `srcSize` is too small, please provide at least result bytes on next attempt.
|
>0 : `srcSize` is too small, please provide at least result bytes on next attempt.
|
||||||
errorCode, which can be tested using ZSTD_isError().
|
errorCode, which can be tested using ZSTD_isError().
|
||||||
|
|
||||||
It fills a ZSTD_frameHeader structure with important information to correctly decode the frame,
|
It fills a ZSTD_FrameHeader structure with important information to correctly decode the frame,
|
||||||
such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
|
such as the dictionary ID, content size, or maximum back-reference distance (`windowSize`).
|
||||||
Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
|
Note that these values could be wrong, either because of data corruption, or because a 3rd party deliberately spoofs false information.
|
||||||
As a consequence, check that values remain within valid application range.
|
As a consequence, check that values remain within valid application range.
|
||||||
|
|||||||
+2
-2
@@ -2401,7 +2401,7 @@ FIO_zstdErrorHelp(const FIO_prefs_t* const prefs,
|
|||||||
size_t err,
|
size_t err,
|
||||||
const char* srcFileName)
|
const char* srcFileName)
|
||||||
{
|
{
|
||||||
ZSTD_frameHeader header;
|
ZSTD_FrameHeader header;
|
||||||
|
|
||||||
/* Help message only for one specific error */
|
/* Help message only for one specific error */
|
||||||
if (ZSTD_getErrorCode(err) != ZSTD_error_frameParameter_windowTooLarge)
|
if (ZSTD_getErrorCode(err) != ZSTD_error_frameParameter_windowTooLarge)
|
||||||
@@ -3201,7 +3201,7 @@ FIO_analyzeFrames(fileInfo_t* info, FILE* const srcFile)
|
|||||||
{ U32 const magicNumber = MEM_readLE32(headerBuffer);
|
{ U32 const magicNumber = MEM_readLE32(headerBuffer);
|
||||||
/* Zstandard frame */
|
/* Zstandard frame */
|
||||||
if (magicNumber == ZSTD_MAGICNUMBER) {
|
if (magicNumber == ZSTD_MAGICNUMBER) {
|
||||||
ZSTD_frameHeader header;
|
ZSTD_FrameHeader header;
|
||||||
U64 const frameContentSize = ZSTD_getFrameContentSize(headerBuffer, numBytesRead);
|
U64 const frameContentSize = ZSTD_getFrameContentSize(headerBuffer, numBytesRead);
|
||||||
if ( frameContentSize == ZSTD_CONTENTSIZE_ERROR
|
if ( frameContentSize == ZSTD_CONTENTSIZE_ERROR
|
||||||
|| frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN ) {
|
|| frameContentSize == ZSTD_CONTENTSIZE_UNKNOWN ) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ static size_t getDecompressionMargin(void const* compressed, size_t cSize, size_
|
|||||||
/* The macro should be correct in this case, but it may be smaller
|
/* The macro should be correct in this case, but it may be smaller
|
||||||
* because of e.g. block splitting, so take the smaller of the two.
|
* because of e.g. block splitting, so take the smaller of the two.
|
||||||
*/
|
*/
|
||||||
ZSTD_frameHeader zfh;
|
ZSTD_FrameHeader zfh;
|
||||||
size_t marginM;
|
size_t marginM;
|
||||||
FUZZ_ZASSERT(ZSTD_getFrameHeader(&zfh, compressed, cSize));
|
FUZZ_ZASSERT(ZSTD_getFrameHeader(&zfh, compressed, cSize));
|
||||||
if (maxBlockSize == 0) {
|
if (maxBlockSize == 0) {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
int LLVMFuzzerTestOneInput(const uint8_t *src, size_t size)
|
||||||
{
|
{
|
||||||
ZSTD_frameHeader zfh;
|
ZSTD_FrameHeader zfh;
|
||||||
if (size == 0) {
|
if (size == 0) {
|
||||||
src = NULL;
|
src = NULL;
|
||||||
}
|
}
|
||||||
|
|||||||
+25
-12
@@ -955,7 +955,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
ZSTD_freeCCtx(cctx);
|
ZSTD_freeCCtx(cctx);
|
||||||
}
|
}
|
||||||
{ /* ensure frame content size is missing */
|
{ /* ensure frame content size is missing */
|
||||||
ZSTD_frameHeader zfh;
|
ZSTD_FrameHeader zfh;
|
||||||
size_t const ret = ZSTD_getFrameHeader(&zfh, compressedBuffer, compressedBufferSize);
|
size_t const ret = ZSTD_getFrameHeader(&zfh, compressedBuffer, compressedBufferSize);
|
||||||
if (ret != 0 || zfh.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN) goto _output_error;
|
if (ret != 0 || zfh.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN) goto _output_error;
|
||||||
}
|
}
|
||||||
@@ -2512,7 +2512,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
|
|
||||||
CHECK_VAR(cSize, ZSTD_compressEnd(ctxDuplicated, compressedBuffer, ZSTD_compressBound(testSize),
|
CHECK_VAR(cSize, ZSTD_compressEnd(ctxDuplicated, compressedBuffer, ZSTD_compressBound(testSize),
|
||||||
(const char*)CNBuffer + dictSize, testSize) );
|
(const char*)CNBuffer + dictSize, testSize) );
|
||||||
{ ZSTD_frameHeader zfh;
|
{ ZSTD_FrameHeader zfh;
|
||||||
if (ZSTD_getFrameHeader(&zfh, compressedBuffer, cSize)) goto _output_error;
|
if (ZSTD_getFrameHeader(&zfh, compressedBuffer, cSize)) goto _output_error;
|
||||||
if ((zfh.frameContentSize != testSize) && (zfh.frameContentSize != 0)) goto _output_error;
|
if ((zfh.frameContentSize != testSize) && (zfh.frameContentSize != 0)) goto _output_error;
|
||||||
} }
|
} }
|
||||||
@@ -3585,7 +3585,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
DISPLAYLEVEL(3, "test%3i : decompress of magic-less frame : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : decompress of magic-less frame : ", testNb++);
|
||||||
ZSTD_DCtx_reset(dctx, ZSTD_reset_session_and_parameters);
|
ZSTD_DCtx_reset(dctx, ZSTD_reset_session_and_parameters);
|
||||||
CHECK_Z( ZSTD_DCtx_setParameter(dctx, ZSTD_d_format, ZSTD_f_zstd1_magicless) );
|
CHECK_Z( ZSTD_DCtx_setParameter(dctx, ZSTD_d_format, ZSTD_f_zstd1_magicless) );
|
||||||
{ ZSTD_frameHeader zfh;
|
{ ZSTD_FrameHeader zfh;
|
||||||
size_t const zfhrt = ZSTD_getFrameHeader_advanced(&zfh, compressedBuffer, cSize, ZSTD_f_zstd1_magicless);
|
size_t const zfhrt = ZSTD_getFrameHeader_advanced(&zfh, compressedBuffer, cSize, ZSTD_f_zstd1_magicless);
|
||||||
if (zfhrt != 0) goto _output_error;
|
if (zfhrt != 0) goto _output_error;
|
||||||
}
|
}
|
||||||
@@ -3943,7 +3943,7 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
goto _output_error;
|
goto _output_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
{ ZSTD_frameHeader zfh;
|
{ ZSTD_FrameHeader zfh;
|
||||||
size_t const zfhStatus = ZSTD_getFrameHeader(&zfh, dst, compressedSize);
|
size_t const zfhStatus = ZSTD_getFrameHeader(&zfh, dst, compressedSize);
|
||||||
if (zfhStatus != 0) {
|
if (zfhStatus != 0) {
|
||||||
DISPLAY("Error reading frame header\n");
|
DISPLAY("Error reading frame header\n");
|
||||||
@@ -4111,15 +4111,28 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
|
|
||||||
|
|
||||||
/* frame operations on skippable frames */
|
/* frame operations on skippable frames */
|
||||||
{ const char skippableFrame[] = "\x50\x2a\x4d\x18\x05\x0\x0\0abcde";
|
{ const char skippableFrame[] = "\x52\x2a\x4d\x18\x05\x0\x0\0abcde";
|
||||||
size_t const skippableFrameSize = sizeof(skippableFrame) - 1 /* remove final /0 */;
|
size_t const skippableFrameSize = sizeof(skippableFrame) - 1 /* remove the terminating /0 */;
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : ZSTD_findFrameCompressedSize on skippable frame : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : ZSTD_findFrameCompressedSize on skippable frame : ", testNb++);
|
||||||
if (ZSTD_findFrameCompressedSize(skippableFrame, skippableFrameSize) != skippableFrameSize) goto _output_error;
|
CHECK(ZSTD_findFrameCompressedSize(skippableFrame, skippableFrameSize) == skippableFrameSize);
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : ZSTD_getFrameContentSize on skippable frame : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : ZSTD_getFrameContentSize on skippable frame : ", testNb++);
|
||||||
if (ZSTD_getFrameContentSize(skippableFrame, skippableFrameSize) != 0) goto _output_error;
|
CHECK(ZSTD_getFrameContentSize(skippableFrame, skippableFrameSize) == 0);
|
||||||
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
|
DISPLAYLEVEL(3, "test%3i : ZSTD_getFrameHeader on skippable frame : ", testNb++);
|
||||||
|
{ ZSTD_FrameHeader zfh;
|
||||||
|
size_t const s = ZSTD_getFrameHeader(&zfh, skippableFrame, skippableFrameSize);
|
||||||
|
CHECK_Z(s);
|
||||||
|
CHECK(s == 0); /* success */
|
||||||
|
CHECK(zfh.frameType == ZSTD_skippableFrame);
|
||||||
|
CHECK(zfh.headerSize == ZSTD_SKIPPABLEHEADERSIZE);
|
||||||
|
CHECK(zfh.dictID == 2); /* magic variant */
|
||||||
|
assert(skippableFrameSize >= ZSTD_SKIPPABLEHEADERSIZE);
|
||||||
|
CHECK(zfh.frameContentSize == skippableFrameSize - ZSTD_SKIPPABLEHEADERSIZE);
|
||||||
|
}
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4140,8 +4153,8 @@ static int basicUnitTests(U32 const seed, double compressibility)
|
|||||||
ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
ZSTD_CCtx* const cctx = ZSTD_createCCtx();
|
||||||
ZSTD_CDict* const lgCDict = ZSTD_createCDict(CNBuffer, size, 1);
|
ZSTD_CDict* const lgCDict = ZSTD_createCDict(CNBuffer, size, 1);
|
||||||
ZSTD_CDict* const smCDict = ZSTD_createCDict(CNBuffer, 1 KB, 1);
|
ZSTD_CDict* const smCDict = ZSTD_createCDict(CNBuffer, 1 KB, 1);
|
||||||
ZSTD_frameHeader lgHeader;
|
ZSTD_FrameHeader lgHeader;
|
||||||
ZSTD_frameHeader smHeader;
|
ZSTD_FrameHeader smHeader;
|
||||||
|
|
||||||
CHECK_Z(ZSTD_compress_usingCDict(cctx, compressedBuffer, compressedBufferSize, CNBuffer, size, lgCDict));
|
CHECK_Z(ZSTD_compress_usingCDict(cctx, compressedBuffer, compressedBufferSize, CNBuffer, size, lgCDict));
|
||||||
CHECK_Z(ZSTD_getFrameHeader(&lgHeader, compressedBuffer, compressedBufferSize));
|
CHECK_Z(ZSTD_getFrameHeader(&lgHeader, compressedBuffer, compressedBufferSize));
|
||||||
@@ -4760,7 +4773,7 @@ static int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, U32 const
|
|||||||
} }
|
} }
|
||||||
|
|
||||||
/* frame header decompression test */
|
/* frame header decompression test */
|
||||||
{ ZSTD_frameHeader zfh;
|
{ ZSTD_FrameHeader zfh;
|
||||||
CHECK_Z( ZSTD_getFrameHeader(&zfh, cBuffer, cSize) );
|
CHECK_Z( ZSTD_getFrameHeader(&zfh, cBuffer, cSize) );
|
||||||
CHECK(zfh.frameContentSize != sampleSize, "Frame content size incorrect");
|
CHECK(zfh.frameContentSize != sampleSize, "Frame content size incorrect");
|
||||||
}
|
}
|
||||||
@@ -4902,7 +4915,7 @@ static int fuzzerTests(U32 seed, unsigned nbTests, unsigned startTest, U32 const
|
|||||||
/* streaming decompression test */
|
/* streaming decompression test */
|
||||||
DISPLAYLEVEL(5, "fuzzer t%u: Bufferless streaming decompression test \n", testNb);
|
DISPLAYLEVEL(5, "fuzzer t%u: Bufferless streaming decompression test \n", testNb);
|
||||||
/* ensure memory requirement is good enough (should always be true) */
|
/* ensure memory requirement is good enough (should always be true) */
|
||||||
{ ZSTD_frameHeader zfh;
|
{ ZSTD_FrameHeader zfh;
|
||||||
CHECK( ZSTD_getFrameHeader(&zfh, cBuffer, ZSTD_FRAMEHEADERSIZE_MAX),
|
CHECK( ZSTD_getFrameHeader(&zfh, cBuffer, ZSTD_FRAMEHEADERSIZE_MAX),
|
||||||
"ZSTD_getFrameHeader(): error retrieving frame information");
|
"ZSTD_getFrameHeader(): error retrieving frame information");
|
||||||
{ size_t const roundBuffSize = ZSTD_decodingBufferSize_min(zfh.windowSize, zfh.frameContentSize);
|
{ size_t const roundBuffSize = ZSTD_decodingBufferSize_min(zfh.windowSize, zfh.frameContentSize);
|
||||||
|
|||||||
+2
-2
@@ -436,7 +436,7 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
|
|||||||
|
|
||||||
/* context size functions */
|
/* context size functions */
|
||||||
DISPLAYLEVEL(3, "test%3i : estimate DStream size : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : estimate DStream size : ", testNb++);
|
||||||
{ ZSTD_frameHeader fhi;
|
{ ZSTD_FrameHeader fhi;
|
||||||
const void* cStart = (char*)compressedBuffer + (skippableFrameSize + 8);
|
const void* cStart = (char*)compressedBuffer + (skippableFrameSize + 8);
|
||||||
size_t const gfhError = ZSTD_getFrameHeader(&fhi, cStart, cSize);
|
size_t const gfhError = ZSTD_getFrameHeader(&fhi, cStart, cSize);
|
||||||
if (gfhError!=0) goto _output_error;
|
if (gfhError!=0) goto _output_error;
|
||||||
@@ -1530,7 +1530,7 @@ static int basicUnitTests(U32 seed, double compressibility, int bigTests)
|
|||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : decompress large frame created from multiple threads + dictionary : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : decompress large frame created from multiple threads + dictionary : ", testNb++);
|
||||||
{ ZSTD_DStream* const dstream = ZSTD_createDCtx();
|
{ ZSTD_DStream* const dstream = ZSTD_createDCtx();
|
||||||
ZSTD_frameHeader zfh;
|
ZSTD_FrameHeader zfh;
|
||||||
ZSTD_getFrameHeader(&zfh, compressedBuffer, cSize);
|
ZSTD_getFrameHeader(&zfh, compressedBuffer, cSize);
|
||||||
DISPLAYLEVEL(5, "frame windowsize = %u : ", (unsigned)zfh.windowSize);
|
DISPLAYLEVEL(5, "frame windowsize = %u : ", (unsigned)zfh.windowSize);
|
||||||
outBuff.dst = decodedBuffer;
|
outBuff.dst = decodedBuffer;
|
||||||
|
|||||||
Reference in New Issue
Block a user