fix : correctly reset pledgedSrcSize to unknown status
when starting a new compression with an existing context
This commit is contained in:
@@ -309,6 +309,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
case ZSTD_p_contentSizeFlag :
|
case ZSTD_p_contentSizeFlag :
|
||||||
|
DEBUGLOG(2, "set content size flag = %u", (value>0));
|
||||||
/* Content size written in frame header _when known_ (default:1) */
|
/* Content size written in frame header _when known_ (default:1) */
|
||||||
cctx->requestedParams.fParams.contentSizeFlag = value>0;
|
cctx->requestedParams.fParams.contentSizeFlag = value>0;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -371,6 +372,7 @@ size_t ZSTD_CCtx_setParameter(ZSTD_CCtx* cctx, ZSTD_cParameter param, unsigned v
|
|||||||
|
|
||||||
ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize)
|
ZSTDLIB_API size_t ZSTD_CCtx_setPledgedSrcSize(ZSTD_CCtx* cctx, unsigned long long pledgedSrcSize)
|
||||||
{
|
{
|
||||||
|
DEBUGLOG(2, " setting pledgedSrcSize to %u", (U32)pledgedSrcSize);
|
||||||
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
if (cctx->streamStage != zcss_init) return ERROR(stage_wrong);
|
||||||
cctx->frameContentSize = pledgedSrcSize;
|
cctx->frameContentSize = pledgedSrcSize;
|
||||||
return 0;
|
return 0;
|
||||||
@@ -3198,9 +3200,12 @@ size_t ZSTD_compressEnd (ZSTD_CCtx* cctx,
|
|||||||
endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize);
|
endResult = ZSTD_writeEpilogue(cctx, (char*)dst + cSize, dstCapacity-cSize);
|
||||||
if (ZSTD_isError(endResult)) return endResult;
|
if (ZSTD_isError(endResult)) return endResult;
|
||||||
if (cctx->appliedParams.fParams.contentSizeFlag) { /* control src size */
|
if (cctx->appliedParams.fParams.contentSizeFlag) { /* control src size */
|
||||||
if (cctx->frameContentSize != cctx->consumedSrcSize)
|
DEBUGLOG(2, "end of frame : controlling src size");
|
||||||
|
if (cctx->frameContentSize != cctx->consumedSrcSize) {
|
||||||
|
DEBUGLOG(2, "error : pledgedSrcSize = %u, while realSrcSize = %u",
|
||||||
|
(U32)cctx->frameContentSize, (U32)cctx->consumedSrcSize);
|
||||||
return ERROR(srcSize_wrong);
|
return ERROR(srcSize_wrong);
|
||||||
}
|
} }
|
||||||
return cSize + endResult;
|
return cSize + endResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3685,6 +3690,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|||||||
DEBUGLOG(5, "Frame completed directly in outBuffer");
|
DEBUGLOG(5, "Frame completed directly in outBuffer");
|
||||||
someMoreWork = 0;
|
someMoreWork = 0;
|
||||||
zcs->streamStage = zcss_init;
|
zcs->streamStage = zcss_init;
|
||||||
|
zcs->frameContentSize = ZSTD_CONTENTSIZE_UNKNOWN;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -3711,6 +3717,7 @@ static size_t ZSTD_compressStream_generic(ZSTD_CStream* zcs,
|
|||||||
DEBUGLOG(5, "Frame completed on flush");
|
DEBUGLOG(5, "Frame completed on flush");
|
||||||
someMoreWork = 0;
|
someMoreWork = 0;
|
||||||
zcs->streamStage = zcss_init;
|
zcs->streamStage = zcss_init;
|
||||||
|
zcs->frameContentSize = ZSTD_CONTENTSIZE_UNKNOWN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
zcs->streamStage = zcss_load;
|
zcs->streamStage = zcss_load;
|
||||||
@@ -3786,8 +3793,10 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
|
|||||||
size_t const flushMin = ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp);
|
size_t const flushMin = ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp);
|
||||||
DEBUGLOG(5, "ZSTDMT result : %u", (U32)flushMin);
|
DEBUGLOG(5, "ZSTDMT result : %u", (U32)flushMin);
|
||||||
if (ZSTD_isError(flushMin)) cctx->streamStage = zcss_init;
|
if (ZSTD_isError(flushMin)) cctx->streamStage = zcss_init;
|
||||||
if (endOp == ZSTD_e_end && flushMin==0)
|
if (endOp == ZSTD_e_end && flushMin==0) {
|
||||||
cctx->streamStage = zcss_init; /* compression completed */
|
cctx->streamStage = zcss_init; /* compression completed */
|
||||||
|
cctx->frameContentSize = ZSTD_CONTENTSIZE_UNKNOWN;
|
||||||
|
}
|
||||||
return flushMin;
|
return flushMin;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user