mirror of
https://github.com/facebook/zstd.git
synced 2025-11-28 00:04:28 -05:00
Merge pull request #2869 from felixhandte/oss-fuzz-fix-41005
Determinism: Avoid Mapping Window into Reserved Indices during Reduction
This commit is contained in:
commit
c2c6a4ab40
@ -982,7 +982,9 @@ MEM_STATIC U32 ZSTD_window_canOverflowCorrect(ZSTD_window_t const window,
|
|||||||
{
|
{
|
||||||
U32 const cycleSize = 1u << cycleLog;
|
U32 const cycleSize = 1u << cycleLog;
|
||||||
U32 const curr = (U32)((BYTE const*)src - window.base);
|
U32 const curr = (U32)((BYTE const*)src - window.base);
|
||||||
U32 const minIndexToOverflowCorrect = cycleSize + MAX(maxDist, cycleSize);
|
U32 const minIndexToOverflowCorrect = cycleSize
|
||||||
|
+ MAX(maxDist, cycleSize)
|
||||||
|
+ ZSTD_WINDOW_START_INDEX;
|
||||||
|
|
||||||
/* Adjust the min index to backoff the overflow correction frequency,
|
/* Adjust the min index to backoff the overflow correction frequency,
|
||||||
* so we don't waste too much CPU in overflow correction. If this
|
* so we don't waste too much CPU in overflow correction. If this
|
||||||
@ -1057,10 +1059,14 @@ MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
|
|||||||
U32 const cycleSize = 1u << cycleLog;
|
U32 const cycleSize = 1u << cycleLog;
|
||||||
U32 const cycleMask = cycleSize - 1;
|
U32 const cycleMask = cycleSize - 1;
|
||||||
U32 const curr = (U32)((BYTE const*)src - window->base);
|
U32 const curr = (U32)((BYTE const*)src - window->base);
|
||||||
U32 const currentCycle0 = curr & cycleMask;
|
U32 const currentCycle = curr & cycleMask;
|
||||||
/* Exclude zero so that newCurrent - maxDist >= 1. */
|
/* Ensure newCurrent - maxDist >= ZSTD_WINDOW_START_INDEX. */
|
||||||
U32 const currentCycle1 = currentCycle0 == 0 ? cycleSize : currentCycle0;
|
U32 const currentCycleCorrection = currentCycle < ZSTD_WINDOW_START_INDEX
|
||||||
U32 const newCurrent = currentCycle1 + MAX(maxDist, cycleSize);
|
? MAX(cycleSize, ZSTD_WINDOW_START_INDEX)
|
||||||
|
: 0;
|
||||||
|
U32 const newCurrent = currentCycle
|
||||||
|
+ currentCycleCorrection
|
||||||
|
+ MAX(maxDist, cycleSize);
|
||||||
U32 const correction = curr - newCurrent;
|
U32 const correction = curr - newCurrent;
|
||||||
/* maxDist must be a power of two so that:
|
/* maxDist must be a power of two so that:
|
||||||
* (newCurrent & cycleMask) == (curr & cycleMask)
|
* (newCurrent & cycleMask) == (curr & cycleMask)
|
||||||
@ -1076,14 +1082,20 @@ MEM_STATIC U32 ZSTD_window_correctOverflow(ZSTD_window_t* window, U32 cycleLog,
|
|||||||
|
|
||||||
window->base += correction;
|
window->base += correction;
|
||||||
window->dictBase += correction;
|
window->dictBase += correction;
|
||||||
if (window->lowLimit <= correction) window->lowLimit = 1;
|
if (window->lowLimit < correction + ZSTD_WINDOW_START_INDEX) {
|
||||||
else window->lowLimit -= correction;
|
window->lowLimit = ZSTD_WINDOW_START_INDEX;
|
||||||
if (window->dictLimit <= correction) window->dictLimit = 1;
|
} else {
|
||||||
else window->dictLimit -= correction;
|
window->lowLimit -= correction;
|
||||||
|
}
|
||||||
|
if (window->dictLimit < correction + ZSTD_WINDOW_START_INDEX) {
|
||||||
|
window->dictLimit = ZSTD_WINDOW_START_INDEX;
|
||||||
|
} else {
|
||||||
|
window->dictLimit -= correction;
|
||||||
|
}
|
||||||
|
|
||||||
/* Ensure we can still reference the full window. */
|
/* Ensure we can still reference the full window. */
|
||||||
assert(newCurrent >= maxDist);
|
assert(newCurrent >= maxDist);
|
||||||
assert(newCurrent - maxDist >= 1);
|
assert(newCurrent - maxDist >= ZSTD_WINDOW_START_INDEX);
|
||||||
/* Ensure that lowLimit and dictLimit didn't underflow. */
|
/* Ensure that lowLimit and dictLimit didn't underflow. */
|
||||||
assert(window->lowLimit <= newCurrent);
|
assert(window->lowLimit <= newCurrent);
|
||||||
assert(window->dictLimit <= newCurrent);
|
assert(window->dictLimit <= newCurrent);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user