mirror of
https://github.com/facebook/zstd.git
synced 2025-10-18 00:03:50 -04:00
Hardcode repcode safety check, fix cosmetic nits
This commit is contained in:
parent
809f652912
commit
518cb83833
@ -581,13 +581,13 @@ size_t ZSTD_compressBlock_fast_dictMatchState(
|
|||||||
|
|
||||||
static size_t ZSTD_compressBlock_fast_extDict_generic(
|
static size_t ZSTD_compressBlock_fast_extDict_generic(
|
||||||
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
||||||
void const* src, size_t srcSize, U32 const mls, U32 const hasStep)
|
void const* src, size_t srcSize, U32 const mls, U32 const commonScenario)
|
||||||
{
|
{
|
||||||
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
const ZSTD_compressionParameters* const cParams = &ms->cParams;
|
||||||
U32* const hashTable = ms->hashTable;
|
U32* const hashTable = ms->hashTable;
|
||||||
U32 const hlog = cParams->hashLog;
|
U32 const hlog = cParams->hashLog;
|
||||||
/* support stepSize of 0 */
|
/* support stepSize of 0 */
|
||||||
size_t const stepSize = hasStep ? (cParams->targetLength + !(cParams->targetLength) + 1) : 2;
|
size_t const stepSize = commonScenario ? 2 : (cParams->targetLength + !(cParams->targetLength) + 1);
|
||||||
const BYTE* const base = ms->window.base;
|
const BYTE* const base = ms->window.base;
|
||||||
const BYTE* const dictBase = ms->window.dictBase;
|
const BYTE* const dictBase = ms->window.dictBase;
|
||||||
const BYTE* const istart = (const BYTE*)src;
|
const BYTE* const istart = (const BYTE*)src;
|
||||||
@ -633,9 +633,13 @@ static size_t ZSTD_compressBlock_fast_extDict_generic(
|
|||||||
|
|
||||||
{ U32 const curr = (U32)(ip0 - base);
|
{ U32 const curr = (U32)(ip0 - base);
|
||||||
U32 const maxRep = curr - dictStartIndex;
|
U32 const maxRep = curr - dictStartIndex;
|
||||||
|
if (commonScenario) {
|
||||||
|
assert(offset_2 < maxRep);
|
||||||
|
assert(offset_1 < maxRep);
|
||||||
|
} else {
|
||||||
if (offset_2 >= maxRep) offset_2 = 0;
|
if (offset_2 >= maxRep) offset_2 = 0;
|
||||||
if (offset_1 >= maxRep) offset_1 = 0;
|
if (offset_1 >= maxRep) offset_1 = 0;
|
||||||
}
|
} }
|
||||||
|
|
||||||
/* start each op */
|
/* start each op */
|
||||||
_start: /* Requires: ip0 */
|
_start: /* Requires: ip0 */
|
||||||
@ -665,7 +669,7 @@ _start: /* Requires: ip0 */
|
|||||||
const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
|
const BYTE* const repBase = repIndex < prefixStartIndex ? dictBase : base;
|
||||||
U32 rval;
|
U32 rval;
|
||||||
if ( ((U32)(prefixStartIndex - repIndex) >= 4) /* intentional underflow */
|
if ( ((U32)(prefixStartIndex - repIndex) >= 4) /* intentional underflow */
|
||||||
& (offset_1 > 0) ) {
|
& (commonScenario | (offset_1 > 0)) ) {
|
||||||
rval = MEM_read32(repBase + repIndex);
|
rval = MEM_read32(repBase + repIndex);
|
||||||
} else {
|
} else {
|
||||||
rval = MEM_read32(ip2) ^ 1; /* guaranteed to not match. */
|
rval = MEM_read32(ip2) ^ 1; /* guaranteed to not match. */
|
||||||
@ -690,7 +694,9 @@ _start: /* Requires: ip0 */
|
|||||||
} }
|
} }
|
||||||
|
|
||||||
{ /* load match for ip[0] */
|
{ /* load match for ip[0] */
|
||||||
U32 const mval = idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
U32 const mval = idx >= dictStartIndex ?
|
||||||
|
MEM_read32(idxBase + idx) :
|
||||||
|
MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
||||||
|
|
||||||
/* check match at ip[0] */
|
/* check match at ip[0] */
|
||||||
if (MEM_read32(ip0) == mval) {
|
if (MEM_read32(ip0) == mval) {
|
||||||
@ -716,7 +722,9 @@ _start: /* Requires: ip0 */
|
|||||||
hashTable[hash0] = current0;
|
hashTable[hash0] = current0;
|
||||||
|
|
||||||
{ /* load match for ip[0] */
|
{ /* load match for ip[0] */
|
||||||
U32 const mval = idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
U32 const mval = idx >= dictStartIndex ?
|
||||||
|
MEM_read32(idxBase + idx) :
|
||||||
|
MEM_read32(ip0) ^ 1; /* guaranteed not to match */
|
||||||
|
|
||||||
/* check match at ip[0] */
|
/* check match at ip[0] */
|
||||||
if (MEM_read32(ip0) == mval) {
|
if (MEM_read32(ip0) == mval) {
|
||||||
@ -804,7 +812,7 @@ _match: /* Requires: ip0, match0, offcode, matchEnd */
|
|||||||
while (ip0 <= ilimit) {
|
while (ip0 <= ilimit) {
|
||||||
U32 const repIndex2 = (U32)(ip0-base) - offset_2;
|
U32 const repIndex2 = (U32)(ip0-base) - offset_2;
|
||||||
const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
|
const BYTE* const repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : base + repIndex2;
|
||||||
if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (offset_2 > 0)) /* intentional underflow */
|
if ( (((U32)((prefixStartIndex-1) - repIndex2) >= 3) & (commonScenario | (offset_2 > 0))) /* intentional underflow */
|
||||||
&& (MEM_read32(repMatch2) == MEM_read32(ip0)) ) {
|
&& (MEM_read32(repMatch2) == MEM_read32(ip0)) ) {
|
||||||
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
const BYTE* const repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend;
|
||||||
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
size_t const repLength2 = ZSTD_count_2segments(ip0+4, repMatch2+4, iend, repEnd2, prefixStart) + 4;
|
||||||
@ -836,8 +844,17 @@ size_t ZSTD_compressBlock_fast_extDict(
|
|||||||
void const* src, size_t srcSize)
|
void const* src, size_t srcSize)
|
||||||
{
|
{
|
||||||
U32 const mls = ms->cParams.minMatch;
|
U32 const mls = ms->cParams.minMatch;
|
||||||
|
const BYTE* const istart = (const BYTE*)src;
|
||||||
|
const BYTE* const base = ms->window.base;
|
||||||
|
const U32 endIndex = (U32)((size_t)(istart - base) + srcSize);
|
||||||
|
const U32 lowLimit = ZSTD_getLowestMatchIndex(ms, endIndex, ms->cParams.windowLog);
|
||||||
|
U32 const curr = (U32)(istart - base);
|
||||||
|
U32 const maxRep = curr - lowLimit;
|
||||||
|
U32 const repOffsetsAreValid = (rep[0] < maxRep) & (rep[1] < maxRep);
|
||||||
|
|
||||||
|
assert((rep[0] > 0) & (rep[1] > 0));
|
||||||
assert(ms->dictMatchState == NULL);
|
assert(ms->dictMatchState == NULL);
|
||||||
if (ms->cParams.targetLength > 1) {
|
if ((ms->cParams.targetLength <= 1) & repOffsetsAreValid) {
|
||||||
switch (mls) {
|
switch (mls) {
|
||||||
default: /* includes case 3 */
|
default: /* includes case 3 */
|
||||||
case 4 :
|
case 4 :
|
||||||
|
Loading…
x
Reference in New Issue
Block a user