From: Yann Collet Date: Fri, 4 Mar 2016 13:45:31 +0000 (+0100) Subject: Support for nbSeq > 32767 X-Git-Tag: v0.6.0^2~17^2~90 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d409db68d3091d7f47563ec1894cbc3211ef13c1;p=thirdparty%2Fzstd.git Support for nbSeq > 32767 tamed -Wstrict-aliasing warning --- diff --git a/lib/zstd_compress.c b/lib/zstd_compress.c index 50fa2fdc2..0c6ee8814 100644 --- a/lib/zstd_compress.c +++ b/lib/zstd_compress.c @@ -212,8 +212,8 @@ static size_t ZSTD_resetCCtx_advanced (ZSTD_CCtx* zc, zc->seqStore.litLengthFreq = zc->seqStore.litFreq + (1<seqStore.matchLengthFreq = zc->seqStore.litLengthFreq + (1<seqStore.offCodeFreq = zc->seqStore.matchLengthFreq + (1<seqStore.matchTable = (ZSTD_match_t*)(zc->seqStore.offCodeFreq + (1<seqStore.priceTable = (ZSTD_optimal_t*)(zc->seqStore.matchTable + ZSTD_OPT_NUM+1); + zc->seqStore.matchTable = (ZSTD_match_t*)(void*)(zc->seqStore.offCodeFreq + (1<seqStore.priceTable = (ZSTD_optimal_t*)(void*)(zc->seqStore.matchTable + ZSTD_OPT_NUM+1); zc->seqStore.litLengthSum = 0; zc->hbSize = 0; @@ -232,7 +232,7 @@ size_t ZSTD_copyCCtx(ZSTD_CCtx* dstCCtx, const ZSTD_CCtx* srcCCtx) { const U32 contentLog = (srcCCtx->params.strategy == ZSTD_fast) ? 1 : srcCCtx->params.contentLog; const size_t tableSpace = ((1 << contentLog) + (1 << srcCCtx->params.hashLog) + (1 << srcCCtx->params.hashLog3)) * sizeof(U32); - + if (srcCCtx->stage!=0) return ERROR(stage_wrong); ZSTD_resetCCtx_advanced(dstCCtx, srcCCtx->params); @@ -546,17 +546,11 @@ size_t ZSTD_compressSequences(ZSTD_CCtx* zc, op += cSize; } -#if ZSTD_OPT_DEBUG >= 5 - if (nbSeq >= 32768) - printf("ERROR: nbSeq=%d\n", (int)nbSeq); -#endif - /* Sequences Header */ if ((oend-op) < MIN_SEQUENCES_SIZE) return ERROR(dstSize_tooSmall); - if (nbSeq < 128) *op++ = (BYTE)nbSeq; - else { - op[0] = (BYTE)((nbSeq>>8) + 128); op[1] = (BYTE)nbSeq; op+=2; - } + if (nbSeq < 0x7F) *op++ = (BYTE)nbSeq; + else if (nbSeq < LONGNBSEQ) op[0] = (BYTE)((nbSeq>>8) + 0x80), op[1] = (BYTE)nbSeq, op+=2; + else op[0]=0xFF, MEM_writeLE16(op+1, (U16)(nbSeq - LONGNBSEQ)), op+=3; if (nbSeq==0) goto _check_compressibility; /* dumps : contains rests of large lengths */ diff --git a/lib/zstd_decompress.c b/lib/zstd_decompress.c index e9d3bdb69..c4338bcc2 100644 --- a/lib/zstd_decompress.c +++ b/lib/zstd_decompress.c @@ -496,9 +496,14 @@ size_t ZSTD_decodeSeqHeaders(int* nbSeq, const BYTE** dumpsPtr, size_t* dumpsLen /* SeqHead */ *nbSeq = *ip++; if (*nbSeq==0) return 1; - if (*nbSeq >= 128) - *nbSeq = ((nbSeq[0]-128)<<8) + *ip++; + if (*nbSeq >= 0x7F) { + if (*nbSeq == 0xFF) + *nbSeq = MEM_readLE16(ip) + LONGNBSEQ, ip+=2; + else + *nbSeq = ((nbSeq[0]-0x80)<<8) + *ip++; + } + /* FSE table descriptors */ LLtype = *ip >> 6; Offtype = (*ip >> 4) & 3; MLtype = (*ip >> 2) & 3; diff --git a/lib/zstd_internal.h b/lib/zstd_internal.h index 4948e2397..bbd19b004 100644 --- a/lib/zstd_internal.h +++ b/lib/zstd_internal.h @@ -105,12 +105,13 @@ static const size_t ZSTD_frameHeaderSize_min = 5; #define OffFSELog 9 #define MaxSeq MAX(MaxLL, MaxML) +#define LONGNBSEQ 0xFF00 + #define FSE_ENCODING_RAW 0 #define FSE_ENCODING_RLE 1 #define FSE_ENCODING_STATIC 2 #define FSE_ENCODING_DYNAMIC 3 - #define HufLog 12 #define MIN_SEQUENCES_SIZE 1 /* nbSeq==0 */