mirror of
https://github.com/facebook/zstd.git
synced 2025-08-10 04:43:07 +03:00
fixed skippable frame
This commit is contained in:
@@ -224,13 +224,7 @@ size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd,
|
|||||||
ip, neededInSize);
|
ip, neededInSize);
|
||||||
if (ZSTD_isError(decodedSize)) return decodedSize;
|
if (ZSTD_isError(decodedSize)) return decodedSize;
|
||||||
ip += neededInSize;
|
ip += neededInSize;
|
||||||
if (!decodedSize) {
|
if (!decodedSize && !isSkipFrame) break; /* this was just a header */
|
||||||
if (isSkipFrame) {
|
|
||||||
zbd->stage = ZBUFFds_loadHeader;
|
|
||||||
zbd->lhSize = 0;
|
|
||||||
}
|
|
||||||
break; /* this was just a header */
|
|
||||||
}
|
|
||||||
zbd->outEnd = zbd->outStart + decodedSize;
|
zbd->outEnd = zbd->outStart + decodedSize;
|
||||||
zbd->stage = ZBUFFds_flush;
|
zbd->stage = ZBUFFds_flush;
|
||||||
break;
|
break;
|
||||||
@@ -256,15 +250,7 @@ size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd,
|
|||||||
zbd->inBuff, neededInSize);
|
zbd->inBuff, neededInSize);
|
||||||
if (ZSTD_isError(decodedSize)) return decodedSize;
|
if (ZSTD_isError(decodedSize)) return decodedSize;
|
||||||
zbd->inPos = 0; /* input is consumed */
|
zbd->inPos = 0; /* input is consumed */
|
||||||
if (!decodedSize) {
|
if (!decodedSize && !isSkipFrame) { zbd->stage = ZBUFFds_read; break; } /* this was just a header */
|
||||||
if (isSkipFrame) {
|
|
||||||
zbd->stage = ZBUFFds_loadHeader;
|
|
||||||
zbd->lhSize = 0;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
zbd->stage = ZBUFFds_read; /* this was just a header */
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
zbd->outEnd = zbd->outStart + decodedSize;
|
zbd->outEnd = zbd->outStart + decodedSize;
|
||||||
zbd->stage = ZBUFFds_flush;
|
zbd->stage = ZBUFFds_flush;
|
||||||
// break; /* ZBUFFds_flush follows */
|
// break; /* ZBUFFds_flush follows */
|
||||||
@@ -292,7 +278,7 @@ size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbd,
|
|||||||
*srcSizePtr = ip-istart;
|
*srcSizePtr = ip-istart;
|
||||||
*dstCapacityPtr = op-ostart;
|
*dstCapacityPtr = op-ostart;
|
||||||
{ size_t nextSrcSizeHint = ZSTD_nextSrcSizeToDecompress(zbd->zd);
|
{ size_t nextSrcSizeHint = ZSTD_nextSrcSizeToDecompress(zbd->zd);
|
||||||
if (nextSrcSizeHint > ZSTD_blockHeaderSize) nextSrcSizeHint+= ZSTD_blockHeaderSize; /* get following block header too */
|
// if (nextSrcSizeHint > ZSTD_blockHeaderSize) nextSrcSizeHint+= ZSTD_blockHeaderSize; /* get following block header too */
|
||||||
nextSrcSizeHint -= zbd->inPos; /* already loaded*/
|
nextSrcSizeHint -= zbd->inPos; /* already loaded*/
|
||||||
return nextSrcSizeHint;
|
return nextSrcSizeHint;
|
||||||
}
|
}
|
||||||
|
@@ -1090,7 +1090,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case ZSTDds_skipFrame:
|
case ZSTDds_skipFrame:
|
||||||
{ dctx->expected = ZSTD_frameHeaderSize_min;
|
{ dctx->expected = 0;
|
||||||
dctx->stage = ZSTDds_getFrameHeaderSize;
|
dctx->stage = ZSTDds_getFrameHeaderSize;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -151,7 +151,7 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
|
|||||||
void* compressedBuffer = malloc(compressedBufferSize);
|
void* compressedBuffer = malloc(compressedBufferSize);
|
||||||
size_t const decodedBufferSize = CNBufferSize;
|
size_t const decodedBufferSize = CNBufferSize;
|
||||||
void* decodedBuffer = malloc(decodedBufferSize);
|
void* decodedBuffer = malloc(decodedBufferSize);
|
||||||
size_t result, cSize, readSize, genSize;
|
size_t result, cSize, readSize, readSkipSize, genSize;
|
||||||
U32 testNb=0;
|
U32 testNb=0;
|
||||||
ZBUFF_CCtx* zc = ZBUFF_createCCtx_advanced(customMem);
|
ZBUFF_CCtx* zc = ZBUFF_createCCtx_advanced(customMem);
|
||||||
ZBUFF_DCtx* zd = ZBUFF_createDCtx_advanced(customMem);
|
ZBUFF_DCtx* zd = ZBUFF_createDCtx_advanced(customMem);
|
||||||
@@ -185,12 +185,17 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
|
|||||||
/* Basic decompression test */
|
/* Basic decompression test */
|
||||||
DISPLAYLEVEL(4, "test%3i : decompress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
|
DISPLAYLEVEL(4, "test%3i : decompress %u bytes : ", testNb++, COMPRESSIBLE_NOISE_LENGTH);
|
||||||
ZBUFF_decompressInitDictionary(zd, CNBuffer, 128 KB);
|
ZBUFF_decompressInitDictionary(zd, CNBuffer, 128 KB);
|
||||||
readSize = cSize;
|
readSkipSize = cSize;
|
||||||
genSize = CNBufferSize;
|
genSize = CNBufferSize;
|
||||||
result = ZBUFF_decompressContinue(zd, decodedBuffer, &genSize, compressedBuffer, &readSize);
|
result = ZBUFF_decompressContinue(zd, decodedBuffer, &genSize, compressedBuffer, &readSkipSize);
|
||||||
|
if (genSize != 0) goto _output_error; /* skippable frame */
|
||||||
|
ZBUFF_decompressInitDictionary(zd, CNBuffer, 128 KB);
|
||||||
|
readSize = cSize - readSkipSize;
|
||||||
|
genSize = CNBufferSize;
|
||||||
|
result = ZBUFF_decompressContinue(zd, decodedBuffer, &genSize, compressedBuffer+readSkipSize, &readSize);
|
||||||
if (result != 0) goto _output_error; /* should reach end of frame == 0; otherwise, some data left, or an error */
|
if (result != 0) goto _output_error; /* should reach end of frame == 0; otherwise, some data left, or an error */
|
||||||
if (genSize != CNBufferSize) goto _output_error; /* should regenerate the same amount */
|
if (genSize != CNBufferSize) goto _output_error; /* should regenerate the same amount */
|
||||||
if (readSize != cSize) goto _output_error; /* should have read the entire frame */
|
if (readSize+readSkipSize != cSize) goto _output_error; /* should have read the entire frame */
|
||||||
DISPLAYLEVEL(4, "OK \n");
|
DISPLAYLEVEL(4, "OK \n");
|
||||||
|
|
||||||
/* check regenerated data is byte exact */
|
/* check regenerated data is byte exact */
|
||||||
@@ -204,17 +209,20 @@ static int basicUnitTests(U32 seed, double compressibility, ZSTD_customMem custo
|
|||||||
|
|
||||||
/* Byte-by-byte decompression test */
|
/* Byte-by-byte decompression test */
|
||||||
DISPLAYLEVEL(4, "test%3i : decompress byte-by-byte : ", testNb++);
|
DISPLAYLEVEL(4, "test%3i : decompress byte-by-byte : ", testNb++);
|
||||||
ZBUFF_decompressInitDictionary(zd, CNBuffer, 128 KB);
|
{ size_t r, pIn=0, pOut=0;
|
||||||
{ size_t r = 1, pIn=0, pOut=0;
|
do
|
||||||
while (r) {
|
{ ZBUFF_decompressInitDictionary(zd, CNBuffer, 128 KB);
|
||||||
size_t inS = 1;
|
r = 1;
|
||||||
size_t outS = 1;
|
while (r) {
|
||||||
r = ZBUFF_decompressContinue(zd, ((BYTE*)decodedBuffer)+pOut, &outS, ((BYTE*)compressedBuffer)+pIn, &inS);
|
size_t inS = 1;
|
||||||
pIn += inS;
|
size_t outS = 1;
|
||||||
pOut += outS;
|
r = ZBUFF_decompressContinue(zd, ((BYTE*)decodedBuffer)+pOut, &outS, ((BYTE*)compressedBuffer)+pIn, &inS);
|
||||||
}
|
pIn += inS;
|
||||||
readSize = pIn;
|
pOut += outS;
|
||||||
genSize = pOut;
|
}
|
||||||
|
readSize = pIn;
|
||||||
|
genSize = pOut;
|
||||||
|
} while (genSize==0);
|
||||||
}
|
}
|
||||||
if (genSize != CNBufferSize) goto _output_error; /* should regenerate the same amount */
|
if (genSize != CNBufferSize) goto _output_error; /* should regenerate the same amount */
|
||||||
if (readSize != cSize) goto _output_error; /* should have read the entire frame */
|
if (readSize != cSize) goto _output_error; /* should have read the entire frame */
|
||||||
|
Reference in New Issue
Block a user