change compressedBound to ULL
This commit is contained in:
parent
8930c3c79b
commit
03026c3b1d
@ -435,12 +435,13 @@ static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx* dctx, const void* src, size_t he
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
* Contains the compressed frame size and an upper-bound for the decompressed frame size.
|
||||||
* Note: before using `compressedSize` or `decompressedBound`,
|
* Note: before using `compressedSize` you must check for errors using ZSTD_isError().
|
||||||
* you must check the field for errors using ZSTD_isError().
|
* similarly, before using `decompressedBound`, you must check for errors using:
|
||||||
|
* `decompressedBound` != ZSTD_CONTENTSIZE_UNKNOWN
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct {
|
||||||
size_t compressedSize;
|
size_t compressedSize;
|
||||||
size_t decompressedBound;
|
unsigned long long decompressedBound;
|
||||||
} ZSTD_frameSizeInfo;
|
} ZSTD_frameSizeInfo;
|
||||||
|
|
||||||
static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize)
|
static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize)
|
||||||
@ -451,7 +452,7 @@ static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize
|
|||||||
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
||||||
if (ZSTD_isLegacy(src, srcSize)) {
|
if (ZSTD_isLegacy(src, srcSize)) {
|
||||||
frameSizeInfo.compressedSize = ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
|
frameSizeInfo.compressedSize = ZSTD_findFrameCompressedSizeLegacy(src, srcSize);
|
||||||
frameSizeInfo.decompressedBound = ERROR(version_unsupported);
|
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||||
return frameSizeInfo;
|
return frameSizeInfo;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -477,7 +478,7 @@ static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize
|
|||||||
}
|
}
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
||||||
frameSizeInfo.decompressedBound = ERROR(srcSize_wrong);
|
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||||
return frameSizeInfo;
|
return frameSizeInfo;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -491,13 +492,13 @@ static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize
|
|||||||
size_t const cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
|
size_t const cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
|
||||||
if (ZSTD_isError(cBlockSize)) {
|
if (ZSTD_isError(cBlockSize)) {
|
||||||
frameSizeInfo.compressedSize = cBlockSize;
|
frameSizeInfo.compressedSize = cBlockSize;
|
||||||
frameSizeInfo.decompressedBound = cBlockSize;
|
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||||
return frameSizeInfo;
|
return frameSizeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ZSTD_blockHeaderSize + cBlockSize > remainingSize) {
|
if (ZSTD_blockHeaderSize + cBlockSize > remainingSize) {
|
||||||
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
||||||
frameSizeInfo.decompressedBound = ERROR(srcSize_wrong);
|
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||||
return frameSizeInfo;
|
return frameSizeInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,7 +513,7 @@ static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize
|
|||||||
if (zfh.checksumFlag) {
|
if (zfh.checksumFlag) {
|
||||||
if (remainingSize < 4) {
|
if (remainingSize < 4) {
|
||||||
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
|
||||||
frameSizeInfo.decompressedBound = ERROR(srcSize_wrong);
|
frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
|
||||||
return frameSizeInfo;
|
return frameSizeInfo;
|
||||||
}
|
}
|
||||||
ip += 4;
|
ip += 4;
|
||||||
@ -542,19 +543,19 @@ size_t ZSTD_findFrameCompressedSize(const void *src, size_t srcSize)
|
|||||||
* currently incompatible with legacy mode
|
* currently incompatible with legacy mode
|
||||||
* `src` must point to the start of a ZSTD frame or a skippeable frame
|
* `src` must point to the start of a ZSTD frame or a skippeable frame
|
||||||
* `srcSize` must be at least as large as the frame contained
|
* `srcSize` must be at least as large as the frame contained
|
||||||
* @return : maximum decompressed size of the compressed source
|
* @return : the maximum decompressed size of the compressed source
|
||||||
* or an error code which can be tested with ZSTD_isError()
|
|
||||||
*/
|
*/
|
||||||
size_t ZSTD_decompressBound(const void* src, size_t srcSize)
|
unsigned long long ZSTD_decompressBound(const void* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
size_t bound = 0;
|
unsigned long long bound = 0;
|
||||||
/* Iterate over each frame */
|
/* Iterate over each frame */
|
||||||
while (srcSize > 0) {
|
while (srcSize > 0) {
|
||||||
ZSTD_frameSizeInfo frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize);
|
ZSTD_frameSizeInfo frameSizeInfo = ZSTD_findFrameSizeInfo(src, srcSize);
|
||||||
size_t compressedSize = frameSizeInfo.compressedSize;
|
size_t compressedSize = frameSizeInfo.compressedSize;
|
||||||
size_t decompressedBound = frameSizeInfo.decompressedBound;
|
unsigned long long decompressedBound = frameSizeInfo.decompressedBound;
|
||||||
FORWARD_IF_ERROR(compressedSize);
|
if (ZSTD_isError(compressedSize) || decompressedBound == ZSTD_CONTENTSIZE_ERROR) {
|
||||||
FORWARD_IF_ERROR(decompressedBound);
|
return ZSTD_CONTENTSIZE_ERROR;
|
||||||
|
}
|
||||||
src = (const BYTE*)src + compressedSize;
|
src = (const BYTE*)src + compressedSize;
|
||||||
srcSize -= compressedSize;
|
srcSize -= compressedSize;
|
||||||
bound += decompressedBound;
|
bound += decompressedBound;
|
||||||
|
16
lib/zstd.h
16
lib/zstd.h
@ -1107,16 +1107,16 @@ ZSTDLIB_API unsigned long long ZSTD_findDecompressedSize(const void* src, size_t
|
|||||||
* currently incompatible with legacy mode
|
* currently incompatible with legacy mode
|
||||||
* `src` must point to the start of a ZSTD frame or a skippeable frame
|
* `src` must point to the start of a ZSTD frame or a skippeable frame
|
||||||
* `srcSize` must be at least as large as the frame contained
|
* `srcSize` must be at least as large as the frame contained
|
||||||
* @return : maximum decompressed size of the compressed source
|
* @return : - the maximum decompressed size of the compressed source
|
||||||
* or an error code which can be tested with ZSTD_isError()
|
* - if an error occured: ZSTD_CONTENTSIZE_ERROR
|
||||||
*
|
*
|
||||||
* note 1 : the bound is exact when Frame_Content_Size field is available in EVERY frame of `src`.
|
* note 1 : an error can occur if `src` points to a legacy frame or an invalid/incorrectly formatted frame.
|
||||||
* note 2 : when Frame_Content_Size isn't provided, the upper-bound for that frame is calculated by:
|
* note 2 : the bound is exact when Frame_Content_Size field is available in EVERY frame of `src`.
|
||||||
* upper-bound = min(128 KB, Window_Size)
|
* note 3 : when Frame_Content_Size isn't provided, the upper-bound for that frame is calculated by:
|
||||||
* note 3 : we always use Frame_Content_Size to bound the decompressed frame size if it's present.
|
* upper-bound = min(128 KB, Window_Size)
|
||||||
** the above formula is only used when Frame_Content_Size is missing.
|
* note 4 : we always use Frame_Content_Size to bound the decompressed frame size if it's present.
|
||||||
*/
|
*/
|
||||||
ZSTDLIB_API size_t ZSTD_decompressBound(const void* src, size_t srcSice);
|
ZSTDLIB_API unsigned long long ZSTD_decompressBound(const void* src, size_t srcSice);
|
||||||
|
|
||||||
/*! ZSTD_frameHeaderSize() :
|
/*! ZSTD_frameHeaderSize() :
|
||||||
* srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
|
* srcSize must be >= ZSTD_FRAMEHEADERSIZE_PREFIX.
|
||||||
|
@ -378,7 +378,7 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : tight ZSTD_decompressBound test : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : tight ZSTD_decompressBound test : ", testNb++);
|
||||||
{
|
{
|
||||||
size_t rSize = ZSTD_decompressBound(compressedBuffer, cSize);
|
unsigned long long rSize = ZSTD_decompressBound(compressedBuffer, cSize);
|
||||||
if (rSize != CNBuffSize) goto _output_error;
|
if (rSize != CNBuffSize) goto _output_error;
|
||||||
}
|
}
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
@ -909,8 +909,8 @@ static int basicUnitTests(U32 seed, double compressibility)
|
|||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : get tight decompressed bound of multiple frames : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : get tight decompressed bound of multiple frames : ", testNb++);
|
||||||
{ size_t const rSize = ZSTD_decompressBound(compressedBuffer, cSize);
|
{ unsigned long long const r = ZSTD_decompressBound(compressedBuffer, cSize);
|
||||||
if (rSize != CNBuffSize / 2) goto _output_error; }
|
if (r != CNBuffSize / 2) goto _output_error; }
|
||||||
DISPLAYLEVEL(3, "OK \n");
|
DISPLAYLEVEL(3, "OK \n");
|
||||||
|
|
||||||
DISPLAYLEVEL(3, "test%3i : decompress multiple frames : ", testNb++);
|
DISPLAYLEVEL(3, "test%3i : decompress multiple frames : ", testNb++);
|
||||||
|
Loading…
Reference in New Issue
Block a user