Shrink Clean Table Area When Copying Table Contents into Context

The source matchState is potentially at a lower current index, which means
that any extra table space not overwritten by the copy may now contain
invalid indices. The simple solution is to unconditionally shrink the valid
table area to just the area overwritten.
dev
W. Felix Handte 2019-09-11 11:18:45 -04:00
parent edb3ad053e
commit 13e29a56de
1 changed files with 8 additions and 0 deletions

View File

@ -1643,6 +1643,8 @@ static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
assert(cctx->appliedParams.cParams.chainLog == cdict_cParams->chainLog); assert(cctx->appliedParams.cParams.chainLog == cdict_cParams->chainLog);
} }
ZSTD_cwksp_mark_tables_dirty(&cctx->workspace);
/* copy tables */ /* copy tables */
{ size_t const chainSize = (cdict_cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cdict_cParams->chainLog); { size_t const chainSize = (cdict_cParams->strategy == ZSTD_fast) ? 0 : ((size_t)1 << cdict_cParams->chainLog);
size_t const hSize = (size_t)1 << cdict_cParams->hashLog; size_t const hSize = (size_t)1 << cdict_cParams->hashLog;
@ -1660,6 +1662,8 @@ static size_t ZSTD_resetCCtx_byCopyingCDict(ZSTD_CCtx* cctx,
memset(cctx->blockState.matchState.hashTable3, 0, h3Size * sizeof(U32)); memset(cctx->blockState.matchState.hashTable3, 0, h3Size * sizeof(U32));
} }
ZSTD_cwksp_mark_tables_clean(&cctx->workspace);
/* copy dictionary offsets */ /* copy dictionary offsets */
{ ZSTD_matchState_t const* srcMatchState = &cdict->matchState; { ZSTD_matchState_t const* srcMatchState = &cdict->matchState;
ZSTD_matchState_t* dstMatchState = &cctx->blockState.matchState; ZSTD_matchState_t* dstMatchState = &cctx->blockState.matchState;
@ -1728,6 +1732,8 @@ static size_t ZSTD_copyCCtx_internal(ZSTD_CCtx* dstCCtx,
assert(dstCCtx->blockState.matchState.hashLog3 == srcCCtx->blockState.matchState.hashLog3); assert(dstCCtx->blockState.matchState.hashLog3 == srcCCtx->blockState.matchState.hashLog3);
} }
ZSTD_cwksp_mark_tables_dirty(&dstCCtx->workspace);
/* copy tables */ /* copy tables */
{ size_t const chainSize = (srcCCtx->appliedParams.cParams.strategy == ZSTD_fast) ? 0 : ((size_t)1 << srcCCtx->appliedParams.cParams.chainLog); { size_t const chainSize = (srcCCtx->appliedParams.cParams.strategy == ZSTD_fast) ? 0 : ((size_t)1 << srcCCtx->appliedParams.cParams.chainLog);
size_t const hSize = (size_t)1 << srcCCtx->appliedParams.cParams.hashLog; size_t const hSize = (size_t)1 << srcCCtx->appliedParams.cParams.hashLog;
@ -1738,6 +1744,8 @@ static size_t ZSTD_copyCCtx_internal(ZSTD_CCtx* dstCCtx,
memcpy(dstCCtx->blockState.matchState.hashTable, srcCCtx->blockState.matchState.hashTable, tableSpace); /* presumes all tables follow each other */ memcpy(dstCCtx->blockState.matchState.hashTable, srcCCtx->blockState.matchState.hashTable, tableSpace); /* presumes all tables follow each other */
} }
ZSTD_cwksp_mark_tables_clean(&dstCCtx->workspace);
/* copy dictionary offsets */ /* copy dictionary offsets */
{ {
const ZSTD_matchState_t* srcMatchState = &srcCCtx->blockState.matchState; const ZSTD_matchState_t* srcMatchState = &srcCCtx->blockState.matchState;