multi_compress 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/GET_STARTED.md +4 -2
- data/README.md +1 -1
- data/THIRD_PARTY_NOTICES.md +2 -2
- data/ext/multi_compress/exports.darwin +1 -0
- data/ext/multi_compress/exports.map +4 -0
- data/ext/multi_compress/extconf.rb +20 -0
- data/ext/multi_compress/multi_compress.c +123 -73
- data/ext/multi_compress/vendor/.vendored +1 -1
- data/ext/multi_compress/vendor/zstd/lib/BUCK +10 -5
- data/ext/multi_compress/vendor/zstd/lib/README.md +25 -5
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +6 -2
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +3 -3
- data/ext/multi_compress/vendor/zstd/lib/common/bmi2.h +40 -0
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +37 -11
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +7 -6
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +4 -3
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +16 -19
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +31 -0
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +16 -2
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +9 -0
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +4 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +300 -3
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +4 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +4 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +775 -214
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +35 -6
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +9 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +14 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +2 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +2 -2
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +49 -5
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +11 -11
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +11 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +16 -18
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +3 -3
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +64 -39
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +30 -2
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +78 -64
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +182 -18
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +59 -27
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +11 -0
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +194 -93
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +225 -85
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +19 -2
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +136 -91
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.c +77 -77
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +48 -42
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +18 -14
- data/ext/multi_compress/vendor/zstd/lib/dll/example/build_package.bat +66 -20
- data/ext/multi_compress/vendor/zstd/lib/dll/example/fullbench-dll.vcxproj +10 -6
- data/ext/multi_compress/vendor/zstd/lib/install_oses.mk +17 -0
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +10 -8
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +5 -364
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +4 -5
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +7 -3
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +8 -5
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +3 -3
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +1 -0
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +8 -7
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +1 -0
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +0 -21
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +209 -112
- data/lib/multi_compress/reader/read_operations.rb +2 -0
- data/lib/multi_compress/version.rb +1 -1
- data/multi_compress.gemspec +2 -0
- data/mysql_udf/Makefile +12 -5
- data/mysql_udf/multi_compress_mysql.exports +6 -0
- data/postgres_extension/Makefile +2 -1
- data/postgres_extension/test/run_e2e.sh +28 -10
- metadata +6 -5
- data/ext/multi_compress/vendor/lz4/lib/Makefile +0 -244
- data/ext/multi_compress/vendor/lz4/lib/dll/example/Makefile +0 -63
- data/ext/multi_compress/vendor/zstd/lib/Makefile +0 -389
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +0 -48
|
@@ -749,7 +749,6 @@ extern "C" {
|
|
|
749
749
|
******************************************/
|
|
750
750
|
static size_t HUF_decompress4X2 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* single-symbol decoder */
|
|
751
751
|
static size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* double-symbols decoder */
|
|
752
|
-
static size_t HUF_decompress4X6 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize); /* quad-symbols decoder */
|
|
753
752
|
|
|
754
753
|
|
|
755
754
|
#if defined (__cplusplus)
|
|
@@ -2127,363 +2126,6 @@ static size_t HUF_decompress4X4 (void* dst, size_t dstSize, const void* cSrc, si
|
|
|
2127
2126
|
}
|
|
2128
2127
|
|
|
2129
2128
|
|
|
2130
|
-
/**********************************/
|
|
2131
|
-
/* quad-symbol decoding */
|
|
2132
|
-
/**********************************/
|
|
2133
|
-
typedef struct { BYTE nbBits; BYTE nbBytes; } HUF_DDescX6;
|
|
2134
|
-
typedef union { BYTE byte[4]; U32 sequence; } HUF_DSeqX6;
|
|
2135
|
-
|
|
2136
|
-
/* recursive, up to level 3; may benefit from <template>-like strategy to nest each level inline */
|
|
2137
|
-
static void HUF_fillDTableX6LevelN(HUF_DDescX6* DDescription, HUF_DSeqX6* DSequence, int sizeLog,
|
|
2138
|
-
const rankVal_t rankValOrigin, const U32 consumed, const int minWeight, const U32 maxWeight,
|
|
2139
|
-
const sortedSymbol_t* sortedSymbols, const U32 sortedListSize, const U32* rankStart,
|
|
2140
|
-
const U32 nbBitsBaseline, HUF_DSeqX6 baseSeq, HUF_DDescX6 DDesc)
|
|
2141
|
-
{
|
|
2142
|
-
const int scaleLog = nbBitsBaseline - sizeLog; /* note : targetLog >= (nbBitsBaseline-1), hence scaleLog <= 1 */
|
|
2143
|
-
const int minBits = nbBitsBaseline - maxWeight;
|
|
2144
|
-
const U32 level = DDesc.nbBytes;
|
|
2145
|
-
U32 rankVal[HUF_ABSOLUTEMAX_TABLELOG + 1];
|
|
2146
|
-
U32 symbolStartPos, s;
|
|
2147
|
-
|
|
2148
|
-
/* local rankVal, will be modified */
|
|
2149
|
-
memcpy(rankVal, rankValOrigin[consumed], sizeof(rankVal));
|
|
2150
|
-
|
|
2151
|
-
/* fill skipped values */
|
|
2152
|
-
if (minWeight>1)
|
|
2153
|
-
{
|
|
2154
|
-
U32 i;
|
|
2155
|
-
const U32 skipSize = rankVal[minWeight];
|
|
2156
|
-
for (i = 0; i < skipSize; i++)
|
|
2157
|
-
{
|
|
2158
|
-
DSequence[i] = baseSeq;
|
|
2159
|
-
DDescription[i] = DDesc;
|
|
2160
|
-
}
|
|
2161
|
-
}
|
|
2162
|
-
|
|
2163
|
-
/* fill DTable */
|
|
2164
|
-
DDesc.nbBytes++;
|
|
2165
|
-
symbolStartPos = rankStart[minWeight];
|
|
2166
|
-
for (s=symbolStartPos; s<sortedListSize; s++)
|
|
2167
|
-
{
|
|
2168
|
-
const BYTE symbol = sortedSymbols[s].symbol;
|
|
2169
|
-
const U32 weight = sortedSymbols[s].weight; /* >= 1 (sorted) */
|
|
2170
|
-
const int nbBits = nbBitsBaseline - weight; /* >= 1 (by construction) */
|
|
2171
|
-
const int totalBits = consumed+nbBits;
|
|
2172
|
-
const U32 start = rankVal[weight];
|
|
2173
|
-
const U32 length = 1 << (sizeLog-nbBits);
|
|
2174
|
-
baseSeq.byte[level] = symbol;
|
|
2175
|
-
DDesc.nbBits = (BYTE)totalBits;
|
|
2176
|
-
|
|
2177
|
-
if ((level<3) && (sizeLog-totalBits >= minBits)) /* enough room for another symbol */
|
|
2178
|
-
{
|
|
2179
|
-
int nextMinWeight = totalBits + scaleLog;
|
|
2180
|
-
if (nextMinWeight < 1) nextMinWeight = 1;
|
|
2181
|
-
HUF_fillDTableX6LevelN(DDescription+start, DSequence+start, sizeLog-nbBits,
|
|
2182
|
-
rankValOrigin, totalBits, nextMinWeight, maxWeight,
|
|
2183
|
-
sortedSymbols, sortedListSize, rankStart,
|
|
2184
|
-
nbBitsBaseline, baseSeq, DDesc); /* recursive (max : level 3) */
|
|
2185
|
-
}
|
|
2186
|
-
else
|
|
2187
|
-
{
|
|
2188
|
-
U32 i;
|
|
2189
|
-
const U32 end = start + length;
|
|
2190
|
-
for (i = start; i < end; i++)
|
|
2191
|
-
{
|
|
2192
|
-
DDescription[i] = DDesc;
|
|
2193
|
-
DSequence[i] = baseSeq;
|
|
2194
|
-
}
|
|
2195
|
-
}
|
|
2196
|
-
rankVal[weight] += length;
|
|
2197
|
-
}
|
|
2198
|
-
}
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
/* note : same preparation as X4 */
|
|
2202
|
-
static size_t HUF_readDTableX6 (U32* DTable, const void* src, size_t srcSize)
|
|
2203
|
-
{
|
|
2204
|
-
BYTE weightList[HUF_MAX_SYMBOL_VALUE + 1];
|
|
2205
|
-
sortedSymbol_t sortedSymbol[HUF_MAX_SYMBOL_VALUE + 1];
|
|
2206
|
-
U32 rankStats[HUF_ABSOLUTEMAX_TABLELOG + 1] = { 0 };
|
|
2207
|
-
U32 rankStart0[HUF_ABSOLUTEMAX_TABLELOG + 2] = { 0 };
|
|
2208
|
-
U32* const rankStart = rankStart0+1;
|
|
2209
|
-
U32 tableLog, maxW, sizeOfSort, nbSymbols;
|
|
2210
|
-
rankVal_t rankVal;
|
|
2211
|
-
const U32 memLog = DTable[0];
|
|
2212
|
-
const BYTE* ip = (const BYTE*) src;
|
|
2213
|
-
size_t iSize = ip[0];
|
|
2214
|
-
|
|
2215
|
-
if (memLog > HUF_ABSOLUTEMAX_TABLELOG) return ERROR(tableLog_tooLarge);
|
|
2216
|
-
//memset(weightList, 0, sizeof(weightList)); /* is not necessary, even though some analyzer complain ... */
|
|
2217
|
-
|
|
2218
|
-
iSize = HUF_readStats(weightList, HUF_MAX_SYMBOL_VALUE + 1, rankStats, &nbSymbols, &tableLog, src, srcSize);
|
|
2219
|
-
if (HUF_isError(iSize)) return iSize;
|
|
2220
|
-
|
|
2221
|
-
/* check result */
|
|
2222
|
-
if (tableLog > memLog) return ERROR(tableLog_tooLarge); /* DTable is too small */
|
|
2223
|
-
|
|
2224
|
-
/* find maxWeight */
|
|
2225
|
-
for (maxW = tableLog; rankStats[maxW]==0; maxW--)
|
|
2226
|
-
{ if (!maxW) return ERROR(GENERIC); } /* necessarily finds a solution before maxW==0 */
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
/* Get start index of each weight */
|
|
2230
|
-
{
|
|
2231
|
-
U32 w, nextRankStart = 0;
|
|
2232
|
-
for (w=1; w<=maxW; w++)
|
|
2233
|
-
{
|
|
2234
|
-
U32 current = nextRankStart;
|
|
2235
|
-
nextRankStart += rankStats[w];
|
|
2236
|
-
rankStart[w] = current;
|
|
2237
|
-
}
|
|
2238
|
-
rankStart[0] = nextRankStart; /* put all 0w symbols at the end of sorted list*/
|
|
2239
|
-
sizeOfSort = nextRankStart;
|
|
2240
|
-
}
|
|
2241
|
-
|
|
2242
|
-
/* sort symbols by weight */
|
|
2243
|
-
{
|
|
2244
|
-
U32 s;
|
|
2245
|
-
for (s=0; s<nbSymbols; s++)
|
|
2246
|
-
{
|
|
2247
|
-
U32 w = weightList[s];
|
|
2248
|
-
U32 r = rankStart[w]++;
|
|
2249
|
-
sortedSymbol[r].symbol = (BYTE)s;
|
|
2250
|
-
sortedSymbol[r].weight = (BYTE)w;
|
|
2251
|
-
}
|
|
2252
|
-
rankStart[0] = 0; /* forget 0w symbols; this is beginning of weight(1) */
|
|
2253
|
-
}
|
|
2254
|
-
|
|
2255
|
-
/* Build rankVal */
|
|
2256
|
-
{
|
|
2257
|
-
const U32 minBits = tableLog+1 - maxW;
|
|
2258
|
-
U32 nextRankVal = 0;
|
|
2259
|
-
U32 w, consumed;
|
|
2260
|
-
const int rescale = (memLog-tableLog) - 1; /* tableLog <= memLog */
|
|
2261
|
-
U32* rankVal0 = rankVal[0];
|
|
2262
|
-
for (w=1; w<=maxW; w++)
|
|
2263
|
-
{
|
|
2264
|
-
U32 current = nextRankVal;
|
|
2265
|
-
nextRankVal += rankStats[w] << (w+rescale);
|
|
2266
|
-
rankVal0[w] = current;
|
|
2267
|
-
}
|
|
2268
|
-
for (consumed = minBits; consumed <= memLog - minBits; consumed++)
|
|
2269
|
-
{
|
|
2270
|
-
U32* rankValPtr = rankVal[consumed];
|
|
2271
|
-
for (w = 1; w <= maxW; w++)
|
|
2272
|
-
{
|
|
2273
|
-
rankValPtr[w] = rankVal0[w] >> consumed;
|
|
2274
|
-
}
|
|
2275
|
-
}
|
|
2276
|
-
}
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
/* fill tables */
|
|
2280
|
-
{
|
|
2281
|
-
void* ptr = DTable+1;
|
|
2282
|
-
HUF_DDescX6* DDescription = (HUF_DDescX6*)(ptr);
|
|
2283
|
-
void* dSeqStart = DTable + 1 + ((size_t)1<<(memLog-1));
|
|
2284
|
-
HUF_DSeqX6* DSequence = (HUF_DSeqX6*)(dSeqStart);
|
|
2285
|
-
HUF_DSeqX6 DSeq;
|
|
2286
|
-
HUF_DDescX6 DDesc;
|
|
2287
|
-
DSeq.sequence = 0;
|
|
2288
|
-
DDesc.nbBits = 0;
|
|
2289
|
-
DDesc.nbBytes = 0;
|
|
2290
|
-
HUF_fillDTableX6LevelN(DDescription, DSequence, memLog,
|
|
2291
|
-
(const U32 (*)[HUF_ABSOLUTEMAX_TABLELOG + 1])rankVal, 0, 1, maxW,
|
|
2292
|
-
sortedSymbol, sizeOfSort, rankStart0,
|
|
2293
|
-
tableLog+1, DSeq, DDesc);
|
|
2294
|
-
}
|
|
2295
|
-
|
|
2296
|
-
return iSize;
|
|
2297
|
-
}
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
static U32 HUF_decodeSymbolX6(void* op, BIT_DStream_t* DStream, const HUF_DDescX6* dd, const HUF_DSeqX6* ds, const U32 dtLog)
|
|
2301
|
-
{
|
|
2302
|
-
const size_t val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */
|
|
2303
|
-
memcpy(op, ds+val, sizeof(HUF_DSeqX6));
|
|
2304
|
-
BIT_skipBits(DStream, dd[val].nbBits);
|
|
2305
|
-
return dd[val].nbBytes;
|
|
2306
|
-
}
|
|
2307
|
-
|
|
2308
|
-
static U32 HUF_decodeLastSymbolsX6(void* op, const U32 maxL, BIT_DStream_t* DStream,
|
|
2309
|
-
const HUF_DDescX6* dd, const HUF_DSeqX6* ds, const U32 dtLog)
|
|
2310
|
-
{
|
|
2311
|
-
const size_t val = BIT_lookBitsFast(DStream, dtLog); /* note : dtLog >= 1 */
|
|
2312
|
-
U32 length = dd[val].nbBytes;
|
|
2313
|
-
if (length <= maxL)
|
|
2314
|
-
{
|
|
2315
|
-
memcpy(op, ds+val, length);
|
|
2316
|
-
BIT_skipBits(DStream, dd[val].nbBits);
|
|
2317
|
-
return length;
|
|
2318
|
-
}
|
|
2319
|
-
memcpy(op, ds+val, maxL);
|
|
2320
|
-
if (DStream->bitsConsumed < (sizeof(DStream->bitContainer)*8))
|
|
2321
|
-
{
|
|
2322
|
-
BIT_skipBits(DStream, dd[val].nbBits);
|
|
2323
|
-
if (DStream->bitsConsumed > (sizeof(DStream->bitContainer)*8))
|
|
2324
|
-
DStream->bitsConsumed = (sizeof(DStream->bitContainer)*8); /* ugly hack; works only because it's the last symbol. Note : can't easily extract nbBits from just this symbol */
|
|
2325
|
-
}
|
|
2326
|
-
return maxL;
|
|
2327
|
-
}
|
|
2328
|
-
|
|
2329
|
-
|
|
2330
|
-
#define HUF_DECODE_SYMBOLX6_0(ptr, DStreamPtr) \
|
|
2331
|
-
ptr += HUF_decodeSymbolX6(ptr, DStreamPtr, dd, ds, dtLog)
|
|
2332
|
-
|
|
2333
|
-
#define HUF_DECODE_SYMBOLX6_1(ptr, DStreamPtr) \
|
|
2334
|
-
if (MEM_64bits() || (HUF_MAX_TABLELOG<=12)) \
|
|
2335
|
-
HUF_DECODE_SYMBOLX6_0(ptr, DStreamPtr)
|
|
2336
|
-
|
|
2337
|
-
#define HUF_DECODE_SYMBOLX6_2(ptr, DStreamPtr) \
|
|
2338
|
-
if (MEM_64bits()) \
|
|
2339
|
-
HUF_DECODE_SYMBOLX6_0(ptr, DStreamPtr)
|
|
2340
|
-
|
|
2341
|
-
static inline size_t HUF_decodeStreamX6(BYTE* p, BIT_DStream_t* bitDPtr, BYTE* const pEnd, const U32* DTable, const U32 dtLog)
|
|
2342
|
-
{
|
|
2343
|
-
const void* ddPtr = DTable+1;
|
|
2344
|
-
const HUF_DDescX6* dd = (const HUF_DDescX6*)(ddPtr);
|
|
2345
|
-
const void* dsPtr = DTable + 1 + ((size_t)1<<(dtLog-1));
|
|
2346
|
-
const HUF_DSeqX6* ds = (const HUF_DSeqX6*)(dsPtr);
|
|
2347
|
-
BYTE* const pStart = p;
|
|
2348
|
-
|
|
2349
|
-
/* up to 16 symbols at a time */
|
|
2350
|
-
while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) && (p <= pEnd-16))
|
|
2351
|
-
{
|
|
2352
|
-
HUF_DECODE_SYMBOLX6_2(p, bitDPtr);
|
|
2353
|
-
HUF_DECODE_SYMBOLX6_1(p, bitDPtr);
|
|
2354
|
-
HUF_DECODE_SYMBOLX6_2(p, bitDPtr);
|
|
2355
|
-
HUF_DECODE_SYMBOLX6_0(p, bitDPtr);
|
|
2356
|
-
}
|
|
2357
|
-
|
|
2358
|
-
/* closer to the end, up to 4 symbols at a time */
|
|
2359
|
-
while ((BIT_reloadDStream(bitDPtr) == BIT_DStream_unfinished) && (p <= pEnd-4))
|
|
2360
|
-
HUF_DECODE_SYMBOLX6_0(p, bitDPtr);
|
|
2361
|
-
|
|
2362
|
-
while (p <= pEnd-4)
|
|
2363
|
-
HUF_DECODE_SYMBOLX6_0(p, bitDPtr); /* no need to reload : reached the end of DStream */
|
|
2364
|
-
|
|
2365
|
-
while (p < pEnd)
|
|
2366
|
-
p += HUF_decodeLastSymbolsX6(p, (U32)(pEnd-p), bitDPtr, dd, ds, dtLog);
|
|
2367
|
-
|
|
2368
|
-
return p-pStart;
|
|
2369
|
-
}
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
static size_t HUF_decompress4X6_usingDTable(
|
|
2374
|
-
void* dst, size_t dstSize,
|
|
2375
|
-
const void* cSrc, size_t cSrcSize,
|
|
2376
|
-
const U32* DTable)
|
|
2377
|
-
{
|
|
2378
|
-
if (cSrcSize < 10) return ERROR(corruption_detected); /* strict minimum : jump table + 1 byte per stream */
|
|
2379
|
-
|
|
2380
|
-
{
|
|
2381
|
-
const BYTE* const istart = (const BYTE*) cSrc;
|
|
2382
|
-
BYTE* const ostart = (BYTE*) dst;
|
|
2383
|
-
BYTE* const oend = ostart + dstSize;
|
|
2384
|
-
|
|
2385
|
-
const U32 dtLog = DTable[0];
|
|
2386
|
-
const void* ddPtr = DTable+1;
|
|
2387
|
-
const HUF_DDescX6* dd = (const HUF_DDescX6*)(ddPtr);
|
|
2388
|
-
const void* dsPtr = DTable + 1 + ((size_t)1<<(dtLog-1));
|
|
2389
|
-
const HUF_DSeqX6* ds = (const HUF_DSeqX6*)(dsPtr);
|
|
2390
|
-
size_t errorCode;
|
|
2391
|
-
|
|
2392
|
-
/* Init */
|
|
2393
|
-
BIT_DStream_t bitD1;
|
|
2394
|
-
BIT_DStream_t bitD2;
|
|
2395
|
-
BIT_DStream_t bitD3;
|
|
2396
|
-
BIT_DStream_t bitD4;
|
|
2397
|
-
const size_t length1 = MEM_readLE16(istart);
|
|
2398
|
-
const size_t length2 = MEM_readLE16(istart+2);
|
|
2399
|
-
const size_t length3 = MEM_readLE16(istart+4);
|
|
2400
|
-
size_t length4;
|
|
2401
|
-
const BYTE* const istart1 = istart + 6; /* jumpTable */
|
|
2402
|
-
const BYTE* const istart2 = istart1 + length1;
|
|
2403
|
-
const BYTE* const istart3 = istart2 + length2;
|
|
2404
|
-
const BYTE* const istart4 = istart3 + length3;
|
|
2405
|
-
const size_t segmentSize = (dstSize+3) / 4;
|
|
2406
|
-
BYTE* const opStart2 = ostart + segmentSize;
|
|
2407
|
-
BYTE* const opStart3 = opStart2 + segmentSize;
|
|
2408
|
-
BYTE* const opStart4 = opStart3 + segmentSize;
|
|
2409
|
-
BYTE* op1 = ostart;
|
|
2410
|
-
BYTE* op2 = opStart2;
|
|
2411
|
-
BYTE* op3 = opStart3;
|
|
2412
|
-
BYTE* op4 = opStart4;
|
|
2413
|
-
U32 endSignal;
|
|
2414
|
-
|
|
2415
|
-
length4 = cSrcSize - (length1 + length2 + length3 + 6);
|
|
2416
|
-
if (length4 > cSrcSize) return ERROR(corruption_detected); /* overflow */
|
|
2417
|
-
errorCode = BIT_initDStream(&bitD1, istart1, length1);
|
|
2418
|
-
if (HUF_isError(errorCode)) return errorCode;
|
|
2419
|
-
errorCode = BIT_initDStream(&bitD2, istart2, length2);
|
|
2420
|
-
if (HUF_isError(errorCode)) return errorCode;
|
|
2421
|
-
errorCode = BIT_initDStream(&bitD3, istart3, length3);
|
|
2422
|
-
if (HUF_isError(errorCode)) return errorCode;
|
|
2423
|
-
errorCode = BIT_initDStream(&bitD4, istart4, length4);
|
|
2424
|
-
if (HUF_isError(errorCode)) return errorCode;
|
|
2425
|
-
|
|
2426
|
-
/* 16-64 symbols per loop (4-16 symbols per stream) */
|
|
2427
|
-
endSignal = BIT_reloadDStream(&bitD1) | BIT_reloadDStream(&bitD2) | BIT_reloadDStream(&bitD3) | BIT_reloadDStream(&bitD4);
|
|
2428
|
-
for ( ; (op3 <= opStart4) && (endSignal==BIT_DStream_unfinished) && (op4<=(oend-16)) ; )
|
|
2429
|
-
{
|
|
2430
|
-
HUF_DECODE_SYMBOLX6_2(op1, &bitD1);
|
|
2431
|
-
HUF_DECODE_SYMBOLX6_2(op2, &bitD2);
|
|
2432
|
-
HUF_DECODE_SYMBOLX6_2(op3, &bitD3);
|
|
2433
|
-
HUF_DECODE_SYMBOLX6_2(op4, &bitD4);
|
|
2434
|
-
HUF_DECODE_SYMBOLX6_1(op1, &bitD1);
|
|
2435
|
-
HUF_DECODE_SYMBOLX6_1(op2, &bitD2);
|
|
2436
|
-
HUF_DECODE_SYMBOLX6_1(op3, &bitD3);
|
|
2437
|
-
HUF_DECODE_SYMBOLX6_1(op4, &bitD4);
|
|
2438
|
-
HUF_DECODE_SYMBOLX6_2(op1, &bitD1);
|
|
2439
|
-
HUF_DECODE_SYMBOLX6_2(op2, &bitD2);
|
|
2440
|
-
HUF_DECODE_SYMBOLX6_2(op3, &bitD3);
|
|
2441
|
-
HUF_DECODE_SYMBOLX6_2(op4, &bitD4);
|
|
2442
|
-
HUF_DECODE_SYMBOLX6_0(op1, &bitD1);
|
|
2443
|
-
HUF_DECODE_SYMBOLX6_0(op2, &bitD2);
|
|
2444
|
-
HUF_DECODE_SYMBOLX6_0(op3, &bitD3);
|
|
2445
|
-
HUF_DECODE_SYMBOLX6_0(op4, &bitD4);
|
|
2446
|
-
|
|
2447
|
-
endSignal = BIT_reloadDStream(&bitD1) | BIT_reloadDStream(&bitD2) | BIT_reloadDStream(&bitD3) | BIT_reloadDStream(&bitD4);
|
|
2448
|
-
}
|
|
2449
|
-
|
|
2450
|
-
/* check corruption */
|
|
2451
|
-
if (op1 > opStart2) return ERROR(corruption_detected);
|
|
2452
|
-
if (op2 > opStart3) return ERROR(corruption_detected);
|
|
2453
|
-
if (op3 > opStart4) return ERROR(corruption_detected);
|
|
2454
|
-
/* note : op4 supposed already verified within main loop */
|
|
2455
|
-
|
|
2456
|
-
/* finish bitStreams one by one */
|
|
2457
|
-
HUF_decodeStreamX6(op1, &bitD1, opStart2, DTable, dtLog);
|
|
2458
|
-
HUF_decodeStreamX6(op2, &bitD2, opStart3, DTable, dtLog);
|
|
2459
|
-
HUF_decodeStreamX6(op3, &bitD3, opStart4, DTable, dtLog);
|
|
2460
|
-
HUF_decodeStreamX6(op4, &bitD4, oend, DTable, dtLog);
|
|
2461
|
-
|
|
2462
|
-
/* check */
|
|
2463
|
-
endSignal = BIT_endOfDStream(&bitD1) & BIT_endOfDStream(&bitD2) & BIT_endOfDStream(&bitD3) & BIT_endOfDStream(&bitD4);
|
|
2464
|
-
if (!endSignal) return ERROR(corruption_detected);
|
|
2465
|
-
|
|
2466
|
-
/* decoded size */
|
|
2467
|
-
return dstSize;
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
static size_t HUF_decompress4X6 (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
|
2473
|
-
{
|
|
2474
|
-
HUF_CREATE_STATIC_DTABLEX6(DTable, HUF_MAX_TABLELOG);
|
|
2475
|
-
const BYTE* ip = (const BYTE*) cSrc;
|
|
2476
|
-
|
|
2477
|
-
size_t hSize = HUF_readDTableX6 (DTable, cSrc, cSrcSize);
|
|
2478
|
-
if (HUF_isError(hSize)) return hSize;
|
|
2479
|
-
if (hSize >= cSrcSize) return ERROR(srcSize_wrong);
|
|
2480
|
-
ip += hSize;
|
|
2481
|
-
cSrcSize -= hSize;
|
|
2482
|
-
|
|
2483
|
-
return HUF_decompress4X6_usingDTable (dst, dstSize, ip, cSrcSize, DTable);
|
|
2484
|
-
}
|
|
2485
|
-
|
|
2486
|
-
|
|
2487
2129
|
/**********************************/
|
|
2488
2130
|
/* Generic decompression selector */
|
|
2489
2131
|
/**********************************/
|
|
@@ -2514,7 +2156,7 @@ typedef size_t (*decompressionAlgo)(void* dst, size_t dstSize, const void* cSrc,
|
|
|
2514
2156
|
|
|
2515
2157
|
static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_t cSrcSize)
|
|
2516
2158
|
{
|
|
2517
|
-
static const decompressionAlgo decompress[
|
|
2159
|
+
static const decompressionAlgo decompress[2] = { HUF_decompress4X2, HUF_decompress4X4 };
|
|
2518
2160
|
/* estimate decompression time */
|
|
2519
2161
|
U32 Q;
|
|
2520
2162
|
const U32 D256 = (U32)(dstSize >> 8);
|
|
@@ -2536,7 +2178,6 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
|
|
|
2536
2178
|
Dtime[1] += Dtime[1] >> 4; Dtime[2] += Dtime[2] >> 3; /* advantage to algorithms using less memory, for cache eviction */
|
|
2537
2179
|
|
|
2538
2180
|
if (Dtime[1] < Dtime[0]) algoNb = 1;
|
|
2539
|
-
if (Dtime[2] < Dtime[algoNb]) algoNb = 2;
|
|
2540
2181
|
|
|
2541
2182
|
return decompress[algoNb](dst, dstSize, cSrc, cSrcSize);
|
|
2542
2183
|
|
|
@@ -2768,6 +2409,7 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
|
|
|
2768
2409
|
bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0;
|
|
2769
2410
|
|
|
2770
2411
|
if (bpPtr->blockType == bt_end) return 0;
|
|
2412
|
+
if (cSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
2771
2413
|
if (bpPtr->blockType == bt_rle) return 1;
|
|
2772
2414
|
return cSize;
|
|
2773
2415
|
}
|
|
@@ -2832,7 +2474,7 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
|
|
|
2832
2474
|
{
|
|
2833
2475
|
if (litSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
2834
2476
|
if (litSize > srcSize-3) return ERROR(corruption_detected);
|
|
2835
|
-
memcpy(dctx->litBuffer, istart, litSize);
|
|
2477
|
+
memcpy(dctx->litBuffer, istart+3, litSize);
|
|
2836
2478
|
dctx->litPtr = dctx->litBuffer;
|
|
2837
2479
|
dctx->litSize = litSize;
|
|
2838
2480
|
memset(dctx->litBuffer + dctx->litSize, 0, 8);
|
|
@@ -3055,11 +2697,12 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
|
3055
2697
|
/* checks */
|
|
3056
2698
|
size_t const seqLength = sequence.litLength + sequence.matchLength;
|
|
3057
2699
|
|
|
2700
|
+
if (sequence.offset == 0) return ERROR(corruption_detected);
|
|
3058
2701
|
if (seqLength > (size_t)(oend - op)) return ERROR(dstSize_tooSmall);
|
|
3059
2702
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
|
3060
2703
|
/* Now we know there are no overflow in literal nor match lengths, can use the pointer check */
|
|
3061
2704
|
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
|
|
3062
|
-
if (sequence.offset > (
|
|
2705
|
+
if (sequence.offset > (size_t)(oLitEnd - base)) return ERROR(corruption_detected);
|
|
3063
2706
|
|
|
3064
2707
|
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
|
3065
2708
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
|
@@ -3074,8 +2717,6 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
|
3074
2717
|
const BYTE* match = op - sequence.offset;
|
|
3075
2718
|
|
|
3076
2719
|
/* check */
|
|
3077
|
-
if (sequence.offset > (size_t)op) return ERROR(corruption_detected); /* address space overflow test (this test seems kept by clang optimizer) */
|
|
3078
|
-
//if (match > op) return ERROR(corruption_detected); /* address space overflow test (is clang optimizer removing this test ?) */
|
|
3079
2720
|
if (match < base) return ERROR(corruption_detected);
|
|
3080
2721
|
|
|
3081
2722
|
/* close range match, overlap */
|
|
@@ -1111,7 +1111,7 @@ static unsigned FSE_isError(size_t code) { return ERR_isError(code); }
|
|
|
1111
1111
|
****************************************************************/
|
|
1112
1112
|
static short FSE_abs(short a)
|
|
1113
1113
|
{
|
|
1114
|
-
return a<0 ? -a : a;
|
|
1114
|
+
return a<0 ? (short)-a : a;
|
|
1115
1115
|
}
|
|
1116
1116
|
|
|
1117
1117
|
static size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
|
@@ -2408,6 +2408,7 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
|
|
|
2408
2408
|
bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0;
|
|
2409
2409
|
|
|
2410
2410
|
if (bpPtr->blockType == bt_end) return 0;
|
|
2411
|
+
if (cSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
2411
2412
|
if (bpPtr->blockType == bt_rle) return 1;
|
|
2412
2413
|
return cSize;
|
|
2413
2414
|
}
|
|
@@ -2472,7 +2473,7 @@ static size_t ZSTD_decodeLiteralsBlock(void* ctx,
|
|
|
2472
2473
|
{
|
|
2473
2474
|
if (litSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
2474
2475
|
if (litSize > srcSize-3) return ERROR(corruption_detected);
|
|
2475
|
-
memcpy(dctx->litBuffer, istart, litSize);
|
|
2476
|
+
memcpy(dctx->litBuffer, istart+3, litSize);
|
|
2476
2477
|
dctx->litPtr = dctx->litBuffer;
|
|
2477
2478
|
dctx->litSize = litSize;
|
|
2478
2479
|
memset(dctx->litBuffer + dctx->litSize, 0, 8);
|
|
@@ -2699,7 +2700,7 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
|
2699
2700
|
if (sequence.litLength > (size_t)(litLimit - *litPtr)) return ERROR(corruption_detected);
|
|
2700
2701
|
/* Now we know there are no overflow in literal nor match lengths, can use pointer checks */
|
|
2701
2702
|
if (oLitEnd > oend_8) return ERROR(dstSize_tooSmall);
|
|
2702
|
-
if (sequence.offset > (
|
|
2703
|
+
if (sequence.offset > (size_t)(oLitEnd - base)) return ERROR(corruption_detected);
|
|
2703
2704
|
|
|
2704
2705
|
if (oMatchEnd > oend) return ERROR(dstSize_tooSmall); /* overwrite beyond dst buffer */
|
|
2705
2706
|
if (litEnd > litLimit) return ERROR(corruption_detected); /* overRead beyond lit buffer */
|
|
@@ -2713,8 +2714,6 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
|
2713
2714
|
{ const BYTE* match = op - sequence.offset;
|
|
2714
2715
|
|
|
2715
2716
|
/* check */
|
|
2716
|
-
if (sequence.offset > (size_t)op) return ERROR(corruption_detected); /* address space overflow test (this test seems kept by clang optimizer) */
|
|
2717
|
-
//if (match > op) return ERROR(corruption_detected); /* address space overflow test (is clang optimizer removing this test ?) */
|
|
2718
2717
|
if (match < base) return ERROR(corruption_detected);
|
|
2719
2718
|
|
|
2720
2719
|
/* close range match, overlap */
|
|
@@ -1094,7 +1094,7 @@ static unsigned FSE_isError(size_t code) { return ERR_isError(code); }
|
|
|
1094
1094
|
****************************************************************/
|
|
1095
1095
|
static short FSE_abs(short a)
|
|
1096
1096
|
{
|
|
1097
|
-
return a<0 ? -a : a;
|
|
1097
|
+
return a<0 ? (short)-a : a;
|
|
1098
1098
|
}
|
|
1099
1099
|
|
|
1100
1100
|
static size_t FSE_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
|
@@ -2540,6 +2540,7 @@ static size_t ZSTD_getcBlockSize(const void* src, size_t srcSize, blockPropertie
|
|
|
2540
2540
|
bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0;
|
|
2541
2541
|
|
|
2542
2542
|
if (bpPtr->blockType == bt_end) return 0;
|
|
2543
|
+
if (cSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
2543
2544
|
if (bpPtr->blockType == bt_rle) return 1;
|
|
2544
2545
|
return cSize;
|
|
2545
2546
|
}
|
|
@@ -2603,7 +2604,7 @@ static size_t ZSTD_decodeLiteralsBlock(ZSTD_DCtx* dctx,
|
|
|
2603
2604
|
{
|
|
2604
2605
|
if (litSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
2605
2606
|
if (litSize > srcSize-3) return ERROR(corruption_detected);
|
|
2606
|
-
memcpy(dctx->litBuffer, istart, litSize);
|
|
2607
|
+
memcpy(dctx->litBuffer, istart+3, litSize);
|
|
2607
2608
|
dctx->litPtr = dctx->litBuffer;
|
|
2608
2609
|
dctx->litSize = litSize;
|
|
2609
2610
|
memset(dctx->litBuffer + dctx->litSize, 0, 8);
|
|
@@ -3424,7 +3425,10 @@ static size_t ZBUFF_decompressContinue(ZBUFF_DCtx* zbc, void* dst, size_t* maxDs
|
|
|
3424
3425
|
|
|
3425
3426
|
case ZBUFFds_decodeHeader:
|
|
3426
3427
|
/* apply header to create / resize buffers */
|
|
3427
|
-
|
|
3428
|
+
/* note : also provide space for one full block, so that the
|
|
3429
|
+
* output buffer never needs to wrap while a block decodes,
|
|
3430
|
+
* keeping match sources valid (see v0.6 decoder). */
|
|
3431
|
+
{ size_t const neededOutSize = ((size_t)1 << zbc->params.windowLog) + BLOCKSIZE;
|
|
3428
3432
|
size_t const neededInSize = BLOCKSIZE; /* a block is never > BLOCKSIZE */
|
|
3429
3433
|
if (zbc->inBuffSize < neededInSize) {
|
|
3430
3434
|
free(zbc->inBuff);
|
|
@@ -1224,7 +1224,7 @@ const char* FSEv05_getErrorName(size_t code) { return ERR_getErrorName(code); }
|
|
|
1224
1224
|
/*-**************************************************************
|
|
1225
1225
|
* FSEv05 NCount encoding-decoding
|
|
1226
1226
|
****************************************************************/
|
|
1227
|
-
static short FSEv05_abs(short a) { return a<0 ? -a : a; }
|
|
1227
|
+
static short FSEv05_abs(short a) { return a<0 ? (short)-a : a; }
|
|
1228
1228
|
|
|
1229
1229
|
|
|
1230
1230
|
size_t FSEv05_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
|
@@ -2791,6 +2791,7 @@ static size_t ZSTDv05_getcBlockSize(const void* src, size_t srcSize, blockProper
|
|
|
2791
2791
|
bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0;
|
|
2792
2792
|
|
|
2793
2793
|
if (bpPtr->blockType == bt_end) return 0;
|
|
2794
|
+
if (cSize > BLOCKSIZE) return ERROR(corruption_detected);
|
|
2794
2795
|
if (bpPtr->blockType == bt_rle) return 1;
|
|
2795
2796
|
return cSize;
|
|
2796
2797
|
}
|
|
@@ -3650,8 +3651,8 @@ static size_t ZSTDv05_loadEntropy(ZSTDv05_DCtx* dctx, const void* dict, size_t d
|
|
|
3650
3651
|
dictSize -= matchlengthHeaderSize;
|
|
3651
3652
|
|
|
3652
3653
|
litlengthHeaderSize = FSEv05_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dict, dictSize);
|
|
3653
|
-
if (litlengthLog > LLFSEv05Log) return ERROR(dictionary_corrupted);
|
|
3654
3654
|
if (FSEv05_isError(litlengthHeaderSize)) return ERROR(dictionary_corrupted);
|
|
3655
|
+
if (litlengthLog > LLFSEv05Log) return ERROR(dictionary_corrupted);
|
|
3655
3656
|
errorCode = FSEv05_buildDTable(dctx->LLTable, litlengthNCount, litlengthMaxValue, litlengthLog);
|
|
3656
3657
|
if (FSEv05_isError(errorCode)) return ERROR(dictionary_corrupted);
|
|
3657
3658
|
|
|
@@ -3662,8 +3663,7 @@ static size_t ZSTDv05_loadEntropy(ZSTDv05_DCtx* dctx, const void* dict, size_t d
|
|
|
3662
3663
|
static size_t ZSTDv05_decompress_insertDictionary(ZSTDv05_DCtx* dctx, const void* dict, size_t dictSize)
|
|
3663
3664
|
{
|
|
3664
3665
|
size_t eSize;
|
|
3665
|
-
|
|
3666
|
-
if (magic != ZSTDv05_DICT_MAGIC) {
|
|
3666
|
+
if (dictSize < 4 || MEM_readLE32(dict) != ZSTDv05_DICT_MAGIC) {
|
|
3667
3667
|
/* pure content mode */
|
|
3668
3668
|
ZSTDv05_refDictContent(dctx, dict, dictSize);
|
|
3669
3669
|
return 0;
|
|
@@ -3893,7 +3893,10 @@ size_t ZBUFFv05_decompressContinue(ZBUFFv05_DCtx* zbc, void* dst, size_t* maxDst
|
|
|
3893
3893
|
case ZBUFFv05ds_decodeHeader:
|
|
3894
3894
|
/* apply header to create / resize buffers */
|
|
3895
3895
|
{
|
|
3896
|
-
|
|
3896
|
+
/* note : also provide space for one full block, so that the
|
|
3897
|
+
* history preserved at wrap time never fills the whole buffer
|
|
3898
|
+
* and the next block always has room to decode into. */
|
|
3899
|
+
size_t neededOutSize = ((size_t)1 << zbc->params.windowLog) + BLOCKSIZE;
|
|
3897
3900
|
size_t neededInSize = BLOCKSIZE; /* a block is never > BLOCKSIZE */
|
|
3898
3901
|
if (zbc->inBuffSize < neededInSize) {
|
|
3899
3902
|
free(zbc->inBuff);
|
|
@@ -1202,7 +1202,7 @@ static unsigned HUFv06_isError(size_t code) { return ERR_isError(code); }
|
|
|
1202
1202
|
/*-**************************************************************
|
|
1203
1203
|
* FSE NCount encoding-decoding
|
|
1204
1204
|
****************************************************************/
|
|
1205
|
-
static short FSEv06_abs(short a) { return a<0 ? -a : a; }
|
|
1205
|
+
static short FSEv06_abs(short a) { return a<0 ? (short)-a : a; }
|
|
1206
1206
|
|
|
1207
1207
|
size_t FSEv06_readNCount (short* normalizedCounter, unsigned* maxSVPtr, unsigned* tableLogPtr,
|
|
1208
1208
|
const void* headerBuffer, size_t hbSize)
|
|
@@ -2979,6 +2979,7 @@ static size_t ZSTDv06_getcBlockSize(const void* src, size_t srcSize, blockProper
|
|
|
2979
2979
|
bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0;
|
|
2980
2980
|
|
|
2981
2981
|
if (bpPtr->blockType == bt_end) return 0;
|
|
2982
|
+
if (cSize > ZSTDv06_BLOCKSIZE_MAX) return ERROR(corruption_detected);
|
|
2982
2983
|
if (bpPtr->blockType == bt_rle) return 1;
|
|
2983
2984
|
return cSize;
|
|
2984
2985
|
}
|
|
@@ -3802,8 +3803,7 @@ static size_t ZSTDv06_loadEntropy(ZSTDv06_DCtx* dctx, const void* dict, size_t d
|
|
|
3802
3803
|
static size_t ZSTDv06_decompress_insertDictionary(ZSTDv06_DCtx* dctx, const void* dict, size_t dictSize)
|
|
3803
3804
|
{
|
|
3804
3805
|
size_t eSize;
|
|
3805
|
-
|
|
3806
|
-
if (magic != ZSTDv06_DICT_MAGIC) {
|
|
3806
|
+
if (dictSize < 4 || MEM_readLE32(dict) != ZSTDv06_DICT_MAGIC) {
|
|
3807
3807
|
/* pure content mode */
|
|
3808
3808
|
ZSTDv06_refDictContent(dctx, dict, dictSize);
|
|
3809
3809
|
return 0;
|
|
@@ -3209,6 +3209,7 @@ static size_t ZSTDv07_getcBlockSize(const void* src, size_t srcSize, blockProper
|
|
|
3209
3209
|
bpPtr->origSize = (bpPtr->blockType == bt_rle) ? cSize : 0;
|
|
3210
3210
|
|
|
3211
3211
|
if (bpPtr->blockType == bt_end) return 0;
|
|
3212
|
+
if (cSize > ZSTDv07_BLOCKSIZE_ABSOLUTEMAX) return ERROR(corruption_detected);
|
|
3212
3213
|
if (bpPtr->blockType == bt_rle) return 1;
|
|
3213
3214
|
return cSize;
|
|
3214
3215
|
}
|
|
@@ -28,12 +28,8 @@ LIB_BINDIR ?= $(LIB_SRCDIR)
|
|
|
28
28
|
# configures a bunch of other variables to space-optimized defaults.
|
|
29
29
|
ZSTD_LIB_MINIFY ?= 0
|
|
30
30
|
|
|
31
|
-
# Legacy support
|
|
32
|
-
|
|
33
|
-
ZSTD_LEGACY_SUPPORT ?= 0
|
|
34
|
-
else
|
|
35
|
-
ZSTD_LEGACY_SUPPORT ?= 5
|
|
36
|
-
endif
|
|
31
|
+
# Legacy support disabled by default
|
|
32
|
+
ZSTD_LEGACY_SUPPORT ?= 0
|
|
37
33
|
ZSTD_LEGACY_MULTITHREADED_API ?= 0
|
|
38
34
|
|
|
39
35
|
# Build size optimizations
|
|
@@ -138,6 +134,8 @@ endif
|
|
|
138
134
|
ifeq ($(shell echo "int main(int argc, char* argv[]) { (void)argc; (void)argv; return 0; }" | $(CC) $(FLAGS) -z cet-report=error -x c -Werror - -o $(VOID) 2>$(VOID) && echo 1 || echo 0),1)
|
|
139
135
|
LDFLAGS += -z cet-report=error
|
|
140
136
|
endif
|
|
137
|
+
# 32-bit system objects usually have no CET properties: 32-bit targets link with LDFLAGS_32
|
|
138
|
+
LDFLAGS_32 = $(subst -z cet-report=error,,$(LDFLAGS))
|
|
141
139
|
|
|
142
140
|
HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
|
|
143
141
|
GREP_OPTIONS ?=
|
|
@@ -206,7 +204,10 @@ endif
|
|
|
206
204
|
endif
|
|
207
205
|
CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
|
208
206
|
|
|
209
|
-
|
|
207
|
+
# Include install_oses.mk from the same directory
|
|
208
|
+
include $(dir $(lastword $(MAKEFILE_LIST)))/install_oses.mk
|
|
209
|
+
LN ?= ln
|
|
210
|
+
CP ?= cp -f
|
|
210
211
|
|
|
211
212
|
ifndef BUILD_DIR
|
|
212
213
|
ifeq ($(UNAME), Darwin)
|
|
@@ -1,27 +1,6 @@
|
|
|
1
1
|
module libzstd [extern_c] {
|
|
2
2
|
header "zstd.h"
|
|
3
3
|
export *
|
|
4
|
-
config_macros [exhaustive] \
|
|
5
|
-
/* zstd.h */ \
|
|
6
|
-
ZSTD_STATIC_LINKING_ONLY, \
|
|
7
|
-
ZSTDLIB_VISIBILITY, \
|
|
8
|
-
ZSTDLIB_VISIBLE, \
|
|
9
|
-
ZSTDLIB_HIDDEN, \
|
|
10
|
-
ZSTD_DLL_EXPORT, \
|
|
11
|
-
ZSTDLIB_STATIC_API, \
|
|
12
|
-
ZSTD_DISABLE_DEPRECATE_WARNINGS, \
|
|
13
|
-
ZSTD_CLEVEL_DEFAULT, \
|
|
14
|
-
/* zdict.h */ \
|
|
15
|
-
ZDICT_STATIC_LINKING_ONLY, \
|
|
16
|
-
ZDICTLIB_VISIBLE, \
|
|
17
|
-
ZDICTLIB_HIDDEN, \
|
|
18
|
-
ZDICTLIB_VISIBILITY, \
|
|
19
|
-
ZDICTLIB_STATIC_API, \
|
|
20
|
-
ZDICT_DISABLE_DEPRECATE_WARNINGS, \
|
|
21
|
-
/* zstd_errors.h */ \
|
|
22
|
-
ZSTDERRORLIB_VISIBLE, \
|
|
23
|
-
ZSTDERRORLIB_HIDDEN, \
|
|
24
|
-
ZSTDERRORLIB_VISIBILITY
|
|
25
4
|
|
|
26
5
|
module dictbuilder [extern_c] {
|
|
27
6
|
header "zdict.h"
|