1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

Test new ZSTD_findFrameCompressedSize and update documentation

This commit is contained in:
shakeelrao
2019-03-15 18:04:19 -07:00
parent 8cd423a659
commit 19b75b6ecb
11 changed files with 73 additions and 48 deletions

View File

@ -242,6 +242,17 @@ typedef struct {
U32 longLengthPos; U32 longLengthPos;
} seqStore_t; } seqStore_t;
/**
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
* Note: before using `compressedSize` you must check for errors using ZSTD_isError().
* similarly, before using `decompressedBound`, you must check for errors using:
* `decompressedBound` != ZSTD_CONTENTSIZE_ERROR
*/
typedef struct {
size_t compressedSize;
unsigned long long decompressedBound;
} ZSTD_frameSizeInfo;
const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */ const seqStore_t* ZSTD_getSeqStore(const ZSTD_CCtx* ctx); /* compress & dictBuilder */
void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */ void ZSTD_seqToCodes(const seqStore_t* seqStorePtr); /* compress, dictBuilder, decodeCorpus (shouldn't get its definition from here) */

View File

@ -20,7 +20,7 @@ extern "C" {
***************************************/ ***************************************/
#include "mem.h" /* MEM_STATIC */ #include "mem.h" /* MEM_STATIC */
#include "error_private.h" /* ERROR */ #include "error_private.h" /* ERROR */
#include "zstd.h" /* ZSTD_inBuffer, ZSTD_outBuffer */ #include "zstd_internal.h" /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */
#if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0) #if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0)
# undef ZSTD_LEGACY_SUPPORT # undef ZSTD_LEGACY_SUPPORT
@ -178,12 +178,6 @@ MEM_STATIC size_t ZSTD_decompressLegacy(
} }
} }
MEM_STATIC void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
{
*cSize = ret;
*dBound = ZSTD_CONTENTSIZE_ERROR;
}
MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size_t srcSize) MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size_t srcSize)
{ {
U32 const version = ZSTD_isLegacy(src, srcSize); U32 const version = ZSTD_isLegacy(src, srcSize);
@ -234,8 +228,8 @@ MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size
break; break;
#endif #endif
default : default :
ZSTD_errorFrameSizeInfoLegacy(&frameSizeInfo.compressedSize, frameSizeInfo.compressedSize = ERROR(prefix_unknown);
&frameSizeInfo.decompressedBound, ERROR(prefix_unknown)); frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
break; break;
} }
return frameSizeInfo; return frameSizeInfo;

View File

@ -36,10 +36,12 @@ size_t ZSTDv01_decompress( void* dst, size_t maxOriginalSize,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/** /**
ZSTDv01_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.1.x format ZSTDv01_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.1.x format
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
return : the number of bytes that would be read to decompress this frame cSize (output parameter) : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv01_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/ */
void ZSTDv01_findFrameSizeInfoLegacy(const void *src, size_t srcSize, void ZSTDv01_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound); size_t* cSize, unsigned long long* dBound);

View File

@ -36,10 +36,12 @@ size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/** /**
ZSTDv02_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.2.x format ZSTDv02_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.2.x format
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
return : the number of bytes that would be read to decompress this frame cSize (output parameter) : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv02_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/ */
void ZSTDv02_findFrameSizeInfoLegacy(const void *src, size_t srcSize, void ZSTDv02_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound); size_t* cSize, unsigned long long* dBound);

View File

@ -36,10 +36,12 @@ size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/** /**
ZSTDv03_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.3.x format ZSTDv03_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.3.x format
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
return : the number of bytes that would be read to decompress this frame cSize (output parameter) : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv03_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/ */
void ZSTDv03_findFrameSizeInfoLegacy(const void *src, size_t srcSize, void ZSTDv03_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound); size_t* cSize, unsigned long long* dBound);

View File

@ -36,10 +36,12 @@ size_t ZSTDv04_decompress( void* dst, size_t maxOriginalSize,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/** /**
ZSTDv04_getFrameSrcSize() : get the source length of a ZSTD frame compliant with v0.4.x format ZSTDv04_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.4.x format
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
return : the number of bytes that would be read to decompress this frame cSize (output parameter) : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv04_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/ */
void ZSTDv04_findFrameSizeInfoLegacy(const void *src, size_t srcSize, void ZSTDv04_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound); size_t* cSize, unsigned long long* dBound);

View File

@ -34,10 +34,12 @@ size_t ZSTDv05_decompress( void* dst, size_t dstCapacity,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/** /**
ZSTDv05_getFrameSrcSize() : get the source length of a ZSTD frame ZSTDv05_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.5.x format
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
return : the number of bytes that would be read to decompress this frame cSize (output parameter) : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv05_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/ */
void ZSTDv05_findFrameSizeInfoLegacy(const void *src, size_t srcSize, void ZSTDv05_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound); size_t* cSize, unsigned long long* dBound);

View File

@ -43,10 +43,12 @@ ZSTDLIBv06_API size_t ZSTDv06_decompress( void* dst, size_t dstCapacity,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/** /**
ZSTDv06_getFrameSrcSize() : get the source length of a ZSTD frame ZSTDv06_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.6.x format
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
return : the number of bytes that would be read to decompress this frame cSize (output parameter) : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv06_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/ */
void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize, void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound); size_t* cSize, unsigned long long* dBound);

View File

@ -50,10 +50,12 @@ ZSTDLIBv07_API size_t ZSTDv07_decompress( void* dst, size_t dstCapacity,
const void* src, size_t compressedSize); const void* src, size_t compressedSize);
/** /**
ZSTDv07_getFrameSrcSize() : get the source length of a ZSTD frame ZSTDv07_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.7.x format
compressedSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src' srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
return : the number of bytes that would be read to decompress this frame cSize (output parameter) : the number of bytes that would be read to decompress this frame
or an errorCode if it fails (which can be tested using ZSTDv07_isError()) or an errorCode if it fails (which can be tested using ZSTDv01_isError())
dBound (output paramter) : an upper-bound for the decompressed size of the data in the frame
or ZSTD_CONTENTSIZE_ERROR if an error occurs
*/ */
void ZSTDv07_findFrameSizeInfoLegacy(const void *src, size_t srcSize, void ZSTDv07_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
size_t* cSize, unsigned long long* dBound); size_t* cSize, unsigned long long* dBound);

View File

@ -1085,17 +1085,6 @@ typedef enum {
* Frame size functions * Frame size functions
***************************************/ ***************************************/
/**
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
* Note: before using `compressedSize` you must check for errors using ZSTD_isError().
* similarly, before using `decompressedBound`, you must check for errors using:
* `decompressedBound` != ZSTD_CONTENTSIZE_ERROR
*/
typedef struct {
size_t compressedSize;
unsigned long long decompressedBound;
} ZSTD_frameSizeInfo;
/*! ZSTD_findDecompressedSize() : /*! ZSTD_findDecompressedSize() :
* `src` should point to the start of a series of ZSTD encoded and/or skippable frames * `src` should point to the start of a series of ZSTD encoded and/or skippable frames
* `srcSize` must be the _exact_ size of this series * `srcSize` must be the _exact_ size of this series

View File

@ -137,6 +137,23 @@ static int testFrameDecoding(void)
DISPLAY("ERROR: ZSTD_decompressBound: decompressed bound too small\n"); DISPLAY("ERROR: ZSTD_decompressBound: decompressed bound too small\n");
return 1; return 1;
} }
{ const char* ip = COMPRESSED;
size_t remainingSize = COMPRESSED_SIZE;
while (1) {
size_t frameSize = ZSTD_findFrameCompressedSize(ip, remainingSize);
if (ZSTD_isError(frameSize)) {
DISPLAY("ERROR: ZSTD_findFrameCompressedSize: %s\n", ZSTD_getErrorName(frameSize));
return 1;
}
if (frameSize > remainingSize) {
DISPLAY("ERROR: ZSTD_findFrameCompressedSize: expected frameSize to align with src buffer");
return 1;
}
ip += frameSize;
remainingSize -= frameSize;
if (remainingSize == 0) break;
}
}
DISPLAY("Frame Decoding OK\n"); DISPLAY("Frame Decoding OK\n");
return 0; return 0;
} }