ext/zstdruby/libzstd/legacy/zstd_v04.c in zstd-ruby-0.1.2 vs ext/zstdruby/libzstd/legacy/zstd_v04.c in zstd-ruby-1.1.3.0
- old
+ new
@@ -3010,25 +3010,23 @@
const BYTE* const de = seqState->dumpsEnd;
/* Literal length */
litLength = FSE_decodeSymbol(&(seqState->stateLL), &(seqState->DStream));
prevOffset = litLength ? seq->offset : seqState->prevOffset;
- if (litLength == MaxLL)
- {
+ if (litLength == MaxLL) {
U32 add = *dumps++;
if (add < 255) litLength += add;
- else
- {
- litLength = MEM_readLE32(dumps) & 0xFFFFFF; /* no pb : dumps is always followed by seq tables > 1 byte */
+ else {
+ litLength = dumps[0] + (dumps[1]<<8) + (dumps[2]<<16);
dumps += 3;
}
- if (dumps >= de) dumps = de-1; /* late correction, to avoid read overflow (data is now corrupted anyway) */
+ if (dumps > de) { litLength = MaxLL+255; } /* late correction, to avoid using uninitialized memory */
+ if (dumps >= de) { dumps = de-1; } /* late correction, to avoid read overflow (data is now corrupted anyway) */
}
/* Offset */
- {
- static const U32 offsetPrefix[MaxOff+1] = {
+ { static const U32 offsetPrefix[MaxOff+1] = {
1 /*fake*/, 1, 2, 4, 8, 16, 32, 64, 128, 256,
512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144,
524288, 1048576, 2097152, 4194304, 8388608, 16777216, 33554432, /*fake*/ 1, 1, 1, 1, 1 };
U32 offsetCode, nbBits;
offsetCode = FSE_decodeSymbol(&(seqState->stateOffb), &(seqState->DStream)); /* <= maxOff, by table construction */
@@ -3041,20 +3039,19 @@
if (offsetCode | !litLength) seqState->prevOffset = seq->offset; /* cmove */
}
/* MatchLength */
matchLength = FSE_decodeSymbol(&(seqState->stateML), &(seqState->DStream));
- if (matchLength == MaxML)
- {
+ if (matchLength == MaxML) {
U32 add = *dumps++;
if (add < 255) matchLength += add;
- else
- {
- matchLength = MEM_readLE32(dumps) & 0xFFFFFF; /* no pb : dumps is always followed by seq tables > 1 byte */
+ else {
+ matchLength = dumps[0] + (dumps[1]<<8) + (dumps[2]<<16);
dumps += 3;
}
- if (dumps >= de) dumps = de-1; /* late correction, to avoid read overflow (data is now corrupted anyway) */
+ if (dumps > de) { matchLength = MaxML+255; } /* late correction, to avoid using uninitialized memory */
+ if (dumps >= de) { dumps = de-1; } /* late correction, to avoid read overflow (data is now corrupted anyway) */
}
matchLength += MINMATCH;
/* save result */
seq->litLength = litLength;
@@ -3114,23 +3111,20 @@
}
}
/* Requirement: op <= oend_8 */
/* match within prefix */
- if (sequence.offset < 8)
- {
+ if (sequence.offset < 8) {
/* close range match, overlap */
const int sub2 = dec64table[sequence.offset];
op[0] = match[0];
op[1] = match[1];
op[2] = match[2];
op[3] = match[3];
match += dec32table[sequence.offset];
ZSTD_copy4(op+4, match);
match -= sub2;
- }
- else
- {
+ } else {
ZSTD_copy8(op, match);
}
op += 8; match += 8;
if (oMatchEnd > oend-(16-MINMATCH))