extzstd 0.3.1 → 0.3.2
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/README.md +28 -14
- data/contrib/zstd/CHANGELOG +114 -56
- data/contrib/zstd/CONTRIBUTING.md +14 -0
- data/contrib/zstd/Makefile +37 -31
- data/contrib/zstd/README.md +6 -0
- data/contrib/zstd/appveyor.yml +4 -1
- data/contrib/zstd/lib/Makefile +231 -134
- data/contrib/zstd/lib/README.md +28 -0
- data/contrib/zstd/lib/common/bitstream.h +24 -15
- data/contrib/zstd/lib/common/compiler.h +116 -3
- data/contrib/zstd/lib/common/cpu.h +0 -2
- data/contrib/zstd/lib/common/debug.h +11 -18
- data/contrib/zstd/lib/common/entropy_common.c +188 -42
- data/contrib/zstd/lib/common/error_private.c +1 -0
- data/contrib/zstd/lib/common/error_private.h +1 -1
- data/contrib/zstd/lib/common/fse.h +38 -11
- data/contrib/zstd/lib/common/fse_decompress.c +123 -16
- data/contrib/zstd/lib/common/huf.h +26 -5
- data/contrib/zstd/lib/common/mem.h +66 -93
- data/contrib/zstd/lib/common/pool.c +22 -16
- data/contrib/zstd/lib/common/pool.h +1 -1
- data/contrib/zstd/lib/common/threading.c +6 -5
- data/contrib/zstd/lib/common/xxhash.c +18 -56
- data/contrib/zstd/lib/common/xxhash.h +1 -1
- data/contrib/zstd/lib/common/zstd_common.c +9 -9
- data/contrib/zstd/lib/common/zstd_deps.h +111 -0
- data/contrib/zstd/lib/common/zstd_errors.h +1 -0
- data/contrib/zstd/lib/common/zstd_internal.h +89 -58
- data/contrib/zstd/lib/compress/fse_compress.c +30 -23
- data/contrib/zstd/lib/compress/hist.c +26 -28
- data/contrib/zstd/lib/compress/hist.h +1 -1
- data/contrib/zstd/lib/compress/huf_compress.c +210 -95
- data/contrib/zstd/lib/compress/zstd_compress.c +1339 -409
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +119 -41
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +4 -4
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +17 -3
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +23 -19
- data/contrib/zstd/lib/compress/zstd_cwksp.h +60 -24
- data/contrib/zstd/lib/compress/zstd_double_fast.c +22 -22
- data/contrib/zstd/lib/compress/zstd_fast.c +19 -19
- data/contrib/zstd/lib/compress/zstd_lazy.c +351 -77
- data/contrib/zstd/lib/compress/zstd_lazy.h +20 -0
- data/contrib/zstd/lib/compress/zstd_ldm.c +59 -18
- data/contrib/zstd/lib/compress/zstd_ldm.h +6 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +190 -45
- data/contrib/zstd/lib/compress/zstdmt_compress.c +74 -406
- data/contrib/zstd/lib/compress/zstdmt_compress.h +26 -108
- data/contrib/zstd/lib/decompress/huf_decompress.c +302 -200
- data/contrib/zstd/lib/decompress/zstd_ddict.c +8 -8
- data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/contrib/zstd/lib/decompress/zstd_decompress.c +125 -80
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +145 -37
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +5 -2
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +11 -10
- data/contrib/zstd/lib/dictBuilder/cover.c +29 -20
- data/contrib/zstd/lib/dictBuilder/cover.h +1 -1
- data/contrib/zstd/lib/dictBuilder/fastcover.c +20 -19
- data/contrib/zstd/lib/dictBuilder/zdict.c +15 -16
- data/contrib/zstd/lib/dictBuilder/zdict.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v01.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v02.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v03.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v04.c +6 -2
- data/contrib/zstd/lib/legacy/zstd_v05.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v06.c +5 -1
- data/contrib/zstd/lib/legacy/zstd_v07.c +5 -1
- data/contrib/zstd/lib/libzstd.pc.in +3 -3
- data/contrib/zstd/lib/zstd.h +348 -47
- data/ext/extzstd.c +6 -0
- data/ext/extzstd.h +6 -0
- data/gemstub.rb +3 -21
- data/lib/extzstd.rb +0 -2
- data/lib/extzstd/version.rb +6 -1
- data/test/test_basic.rb +0 -5
- metadata +5 -4
@@ -14,7 +14,7 @@
|
|
14
14
|
/*-*******************************************************
|
15
15
|
* Dependencies
|
16
16
|
*********************************************************/
|
17
|
-
#include
|
17
|
+
#include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */
|
18
18
|
#include "../common/cpu.h" /* bmi2 */
|
19
19
|
#include "../common/mem.h" /* low level memory routines */
|
20
20
|
#define FSE_STATIC_LINKING_ONLY
|
@@ -127,11 +127,11 @@ static size_t ZSTD_initDDict_internal(ZSTD_DDict* ddict,
|
|
127
127
|
ddict->dictContent = dict;
|
128
128
|
if (!dict) dictSize = 0;
|
129
129
|
} else {
|
130
|
-
void* const internalBuffer =
|
130
|
+
void* const internalBuffer = ZSTD_customMalloc(dictSize, ddict->cMem);
|
131
131
|
ddict->dictBuffer = internalBuffer;
|
132
132
|
ddict->dictContent = internalBuffer;
|
133
133
|
if (!internalBuffer) return ERROR(memory_allocation);
|
134
|
-
|
134
|
+
ZSTD_memcpy(internalBuffer, dict, dictSize);
|
135
135
|
}
|
136
136
|
ddict->dictSize = dictSize;
|
137
137
|
ddict->entropy.hufTable[0] = (HUF_DTable)((HufLog)*0x1000001); /* cover both little and big endian */
|
@@ -147,9 +147,9 @@ ZSTD_DDict* ZSTD_createDDict_advanced(const void* dict, size_t dictSize,
|
|
147
147
|
ZSTD_dictContentType_e dictContentType,
|
148
148
|
ZSTD_customMem customMem)
|
149
149
|
{
|
150
|
-
if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
|
150
|
+
if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
|
151
151
|
|
152
|
-
{ ZSTD_DDict* const ddict = (ZSTD_DDict*)
|
152
|
+
{ ZSTD_DDict* const ddict = (ZSTD_DDict*) ZSTD_customMalloc(sizeof(ZSTD_DDict), customMem);
|
153
153
|
if (ddict == NULL) return NULL;
|
154
154
|
ddict->cMem = customMem;
|
155
155
|
{ size_t const initResult = ZSTD_initDDict_internal(ddict,
|
@@ -198,7 +198,7 @@ const ZSTD_DDict* ZSTD_initStaticDDict(
|
|
198
198
|
if ((size_t)sBuffer & 7) return NULL; /* 8-aligned */
|
199
199
|
if (sBufferSize < neededSpace) return NULL;
|
200
200
|
if (dictLoadMethod == ZSTD_dlm_byCopy) {
|
201
|
-
|
201
|
+
ZSTD_memcpy(ddict+1, dict, dictSize); /* local copy */
|
202
202
|
dict = ddict+1;
|
203
203
|
}
|
204
204
|
if (ZSTD_isError( ZSTD_initDDict_internal(ddict,
|
@@ -213,8 +213,8 @@ size_t ZSTD_freeDDict(ZSTD_DDict* ddict)
|
|
213
213
|
{
|
214
214
|
if (ddict==NULL) return 0; /* support free on NULL */
|
215
215
|
{ ZSTD_customMem const cMem = ddict->cMem;
|
216
|
-
|
217
|
-
|
216
|
+
ZSTD_customFree(ddict->dictBuffer, cMem);
|
217
|
+
ZSTD_customFree(ddict, cMem);
|
218
218
|
return 0;
|
219
219
|
}
|
220
220
|
}
|
@@ -15,7 +15,7 @@
|
|
15
15
|
/*-*******************************************************
|
16
16
|
* Dependencies
|
17
17
|
*********************************************************/
|
18
|
-
#include
|
18
|
+
#include "../common/zstd_deps.h" /* size_t */
|
19
19
|
#include "../zstd.h" /* ZSTD_DDict, and several public functions */
|
20
20
|
|
21
21
|
|
@@ -55,7 +55,7 @@
|
|
55
55
|
/*-*******************************************************
|
56
56
|
* Dependencies
|
57
57
|
*********************************************************/
|
58
|
-
#include
|
58
|
+
#include "../common/zstd_deps.h" /* ZSTD_memcpy, ZSTD_memmove, ZSTD_memset */
|
59
59
|
#include "../common/cpu.h" /* bmi2 */
|
60
60
|
#include "../common/mem.h" /* low level memory routines */
|
61
61
|
#define FSE_STATIC_LINKING_ONLY
|
@@ -94,11 +94,18 @@ static size_t ZSTD_startingInputLength(ZSTD_format_e format)
|
|
94
94
|
return startingInputLength;
|
95
95
|
}
|
96
96
|
|
97
|
+
static void ZSTD_DCtx_resetParameters(ZSTD_DCtx* dctx)
|
98
|
+
{
|
99
|
+
assert(dctx->streamStage == zdss_init);
|
100
|
+
dctx->format = ZSTD_f_zstd1;
|
101
|
+
dctx->maxWindowSize = ZSTD_MAXWINDOWSIZE_DEFAULT;
|
102
|
+
dctx->outBufferMode = ZSTD_bm_buffered;
|
103
|
+
dctx->forceIgnoreChecksum = ZSTD_d_validateChecksum;
|
104
|
+
}
|
105
|
+
|
97
106
|
static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx)
|
98
107
|
{
|
99
|
-
dctx->format = ZSTD_f_zstd1; /* ZSTD_decompressBegin() invokes ZSTD_startingInputLength() with argument dctx->format */
|
100
108
|
dctx->staticSize = 0;
|
101
|
-
dctx->maxWindowSize = ZSTD_MAXWINDOWSIZE_DEFAULT;
|
102
109
|
dctx->ddict = NULL;
|
103
110
|
dctx->ddictLocal = NULL;
|
104
111
|
dctx->dictEnd = NULL;
|
@@ -113,7 +120,8 @@ static void ZSTD_initDCtx_internal(ZSTD_DCtx* dctx)
|
|
113
120
|
dctx->noForwardProgress = 0;
|
114
121
|
dctx->oversizedDuration = 0;
|
115
122
|
dctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
|
116
|
-
dctx
|
123
|
+
ZSTD_DCtx_resetParameters(dctx);
|
124
|
+
dctx->validateChecksum = 1;
|
117
125
|
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
|
118
126
|
dctx->dictContentEndForFuzzing = NULL;
|
119
127
|
#endif
|
@@ -134,9 +142,9 @@ ZSTD_DCtx* ZSTD_initStaticDCtx(void *workspace, size_t workspaceSize)
|
|
134
142
|
|
135
143
|
ZSTD_DCtx* ZSTD_createDCtx_advanced(ZSTD_customMem customMem)
|
136
144
|
{
|
137
|
-
if (!customMem.customAlloc ^ !customMem.customFree) return NULL;
|
145
|
+
if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
|
138
146
|
|
139
|
-
{ ZSTD_DCtx* const dctx = (ZSTD_DCtx*)
|
147
|
+
{ ZSTD_DCtx* const dctx = (ZSTD_DCtx*)ZSTD_customMalloc(sizeof(*dctx), customMem);
|
140
148
|
if (!dctx) return NULL;
|
141
149
|
dctx->customMem = customMem;
|
142
150
|
ZSTD_initDCtx_internal(dctx);
|
@@ -164,13 +172,13 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
|
|
164
172
|
RETURN_ERROR_IF(dctx->staticSize, memory_allocation, "not compatible with static DCtx");
|
165
173
|
{ ZSTD_customMem const cMem = dctx->customMem;
|
166
174
|
ZSTD_clearDict(dctx);
|
167
|
-
|
175
|
+
ZSTD_customFree(dctx->inBuff, cMem);
|
168
176
|
dctx->inBuff = NULL;
|
169
177
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
170
178
|
if (dctx->legacyContext)
|
171
179
|
ZSTD_freeLegacyStreamContext(dctx->legacyContext, dctx->previousLegacyVersion);
|
172
180
|
#endif
|
173
|
-
|
181
|
+
ZSTD_customFree(dctx, cMem);
|
174
182
|
return 0;
|
175
183
|
}
|
176
184
|
}
|
@@ -179,7 +187,7 @@ size_t ZSTD_freeDCtx(ZSTD_DCtx* dctx)
|
|
179
187
|
void ZSTD_copyDCtx(ZSTD_DCtx* dstDCtx, const ZSTD_DCtx* srcDCtx)
|
180
188
|
{
|
181
189
|
size_t const toCopy = (size_t)((char*)(&dstDCtx->inBuff) - (char*)dstDCtx);
|
182
|
-
|
190
|
+
ZSTD_memcpy(dstDCtx, srcDCtx, toCopy); /* no need to copy workspace */
|
183
191
|
}
|
184
192
|
|
185
193
|
|
@@ -246,7 +254,7 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
|
|
246
254
|
const BYTE* ip = (const BYTE*)src;
|
247
255
|
size_t const minInputSize = ZSTD_startingInputLength(format);
|
248
256
|
|
249
|
-
|
257
|
+
ZSTD_memset(zfhPtr, 0, sizeof(*zfhPtr)); /* not strictly necessary, but static analyzer do not understand that zfhPtr is only going to be read only if return value is zero, since they are 2 different signals */
|
250
258
|
if (srcSize < minInputSize) return minInputSize;
|
251
259
|
RETURN_ERROR_IF(src==NULL, GENERIC, "invalid parameter");
|
252
260
|
|
@@ -256,7 +264,7 @@ size_t ZSTD_getFrameHeader_advanced(ZSTD_frameHeader* zfhPtr, const void* src, s
|
|
256
264
|
/* skippable frame */
|
257
265
|
if (srcSize < ZSTD_SKIPPABLEHEADERSIZE)
|
258
266
|
return ZSTD_SKIPPABLEHEADERSIZE; /* magic number + frame length */
|
259
|
-
|
267
|
+
ZSTD_memset(zfhPtr, 0, sizeof(*zfhPtr));
|
260
268
|
zfhPtr->frameContentSize = MEM_readLE32((const char *)src + ZSTD_FRAMEIDSIZE);
|
261
269
|
zfhPtr->frameType = ZSTD_skippableFrame;
|
262
270
|
return 0;
|
@@ -446,7 +454,8 @@ static size_t ZSTD_decodeFrameHeader(ZSTD_DCtx* dctx, const void* src, size_t he
|
|
446
454
|
RETURN_ERROR_IF(dctx->fParams.dictID && (dctx->dictID != dctx->fParams.dictID),
|
447
455
|
dictionary_wrong, "");
|
448
456
|
#endif
|
449
|
-
|
457
|
+
dctx->validateChecksum = (dctx->fParams.checksumFlag && !dctx->forceIgnoreChecksum) ? 1 : 0;
|
458
|
+
if (dctx->validateChecksum) XXH64_reset(&dctx->xxhState, 0);
|
450
459
|
return 0;
|
451
460
|
}
|
452
461
|
|
@@ -461,7 +470,7 @@ static ZSTD_frameSizeInfo ZSTD_errorFrameSizeInfo(size_t ret)
|
|
461
470
|
static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize)
|
462
471
|
{
|
463
472
|
ZSTD_frameSizeInfo frameSizeInfo;
|
464
|
-
|
473
|
+
ZSTD_memset(&frameSizeInfo, 0, sizeof(ZSTD_frameSizeInfo));
|
465
474
|
|
466
475
|
#if defined(ZSTD_LEGACY_SUPPORT) && (ZSTD_LEGACY_SUPPORT >= 1)
|
467
476
|
if (ZSTD_isLegacy(src, srcSize))
|
@@ -516,7 +525,7 @@ static ZSTD_frameSizeInfo ZSTD_findFrameSizeInfo(const void* src, size_t srcSize
|
|
516
525
|
ip += 4;
|
517
526
|
}
|
518
527
|
|
519
|
-
frameSizeInfo.compressedSize = ip - ipstart;
|
528
|
+
frameSizeInfo.compressedSize = (size_t)(ip - ipstart);
|
520
529
|
frameSizeInfo.decompressedBound = (zfh.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN)
|
521
530
|
? zfh.frameContentSize
|
522
531
|
: nbBlocks * zfh.blockSizeMax;
|
@@ -579,12 +588,12 @@ static size_t ZSTD_copyRawBlock(void* dst, size_t dstCapacity,
|
|
579
588
|
const void* src, size_t srcSize)
|
580
589
|
{
|
581
590
|
DEBUGLOG(5, "ZSTD_copyRawBlock");
|
591
|
+
RETURN_ERROR_IF(srcSize > dstCapacity, dstSize_tooSmall, "");
|
582
592
|
if (dst == NULL) {
|
583
593
|
if (srcSize == 0) return 0;
|
584
594
|
RETURN_ERROR(dstBuffer_null, "");
|
585
595
|
}
|
586
|
-
|
587
|
-
memcpy(dst, src, srcSize);
|
596
|
+
ZSTD_memcpy(dst, src, srcSize);
|
588
597
|
return srcSize;
|
589
598
|
}
|
590
599
|
|
@@ -592,12 +601,12 @@ static size_t ZSTD_setRleBlock(void* dst, size_t dstCapacity,
|
|
592
601
|
BYTE b,
|
593
602
|
size_t regenSize)
|
594
603
|
{
|
604
|
+
RETURN_ERROR_IF(regenSize > dstCapacity, dstSize_tooSmall, "");
|
595
605
|
if (dst == NULL) {
|
596
606
|
if (regenSize == 0) return 0;
|
597
607
|
RETURN_ERROR(dstBuffer_null, "");
|
598
608
|
}
|
599
|
-
|
600
|
-
memset(dst, b, regenSize);
|
609
|
+
ZSTD_memset(dst, b, regenSize);
|
601
610
|
return regenSize;
|
602
611
|
}
|
603
612
|
|
@@ -647,13 +656,13 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
|
647
656
|
switch(blockProperties.blockType)
|
648
657
|
{
|
649
658
|
case bt_compressed:
|
650
|
-
decodedSize = ZSTD_decompressBlock_internal(dctx, op, oend-op, ip, cBlockSize, /* frame */ 1);
|
659
|
+
decodedSize = ZSTD_decompressBlock_internal(dctx, op, (size_t)(oend-op), ip, cBlockSize, /* frame */ 1);
|
651
660
|
break;
|
652
661
|
case bt_raw :
|
653
|
-
decodedSize = ZSTD_copyRawBlock(op, oend-op, ip, cBlockSize);
|
662
|
+
decodedSize = ZSTD_copyRawBlock(op, (size_t)(oend-op), ip, cBlockSize);
|
654
663
|
break;
|
655
664
|
case bt_rle :
|
656
|
-
decodedSize = ZSTD_setRleBlock(op, oend-op, *ip, blockProperties.origSize);
|
665
|
+
decodedSize = ZSTD_setRleBlock(op, (size_t)(oend-op), *ip, blockProperties.origSize);
|
657
666
|
break;
|
658
667
|
case bt_reserved :
|
659
668
|
default:
|
@@ -661,7 +670,7 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
|
661
670
|
}
|
662
671
|
|
663
672
|
if (ZSTD_isError(decodedSize)) return decodedSize;
|
664
|
-
if (dctx->
|
673
|
+
if (dctx->validateChecksum)
|
665
674
|
XXH64_update(&dctx->xxhState, op, decodedSize);
|
666
675
|
if (decodedSize != 0)
|
667
676
|
op += decodedSize;
|
@@ -676,11 +685,13 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
|
676
685
|
corruption_detected, "");
|
677
686
|
}
|
678
687
|
if (dctx->fParams.checksumFlag) { /* Frame content checksum verification */
|
679
|
-
U32 const checkCalc = (U32)XXH64_digest(&dctx->xxhState);
|
680
|
-
U32 checkRead;
|
681
688
|
RETURN_ERROR_IF(remainingSrcSize<4, checksum_wrong, "");
|
682
|
-
|
683
|
-
|
689
|
+
if (!dctx->forceIgnoreChecksum) {
|
690
|
+
U32 const checkCalc = (U32)XXH64_digest(&dctx->xxhState);
|
691
|
+
U32 checkRead;
|
692
|
+
checkRead = MEM_readLE32(ip);
|
693
|
+
RETURN_ERROR_IF(checkRead != checkCalc, checksum_wrong, "");
|
694
|
+
}
|
684
695
|
ip += 4;
|
685
696
|
remainingSrcSize -= 4;
|
686
697
|
}
|
@@ -688,7 +699,7 @@ static size_t ZSTD_decompressFrame(ZSTD_DCtx* dctx,
|
|
688
699
|
/* Allow caller to get size read */
|
689
700
|
*srcPtr = ip;
|
690
701
|
*srcSizePtr = remainingSrcSize;
|
691
|
-
return op-ostart;
|
702
|
+
return (size_t)(op-ostart);
|
692
703
|
}
|
693
704
|
|
694
705
|
static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
|
@@ -721,7 +732,7 @@ static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
|
|
721
732
|
decodedSize = ZSTD_decompressLegacy(dst, dstCapacity, src, frameSize, dict, dictSize);
|
722
733
|
if (ZSTD_isError(decodedSize)) return decodedSize;
|
723
734
|
|
724
|
-
assert(decodedSize
|
735
|
+
assert(decodedSize <= dstCapacity);
|
725
736
|
dst = (BYTE*)dst + decodedSize;
|
726
737
|
dstCapacity -= decodedSize;
|
727
738
|
|
@@ -761,15 +772,13 @@ static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
|
|
761
772
|
(ZSTD_getErrorCode(res) == ZSTD_error_prefix_unknown)
|
762
773
|
&& (moreThan1Frame==1),
|
763
774
|
srcSize_wrong,
|
764
|
-
"
|
765
|
-
"bytes are garbage:
|
766
|
-
"
|
767
|
-
"
|
768
|
-
"
|
769
|
-
"
|
770
|
-
"
|
771
|
-
"bytes. But this is _much_ less likely than a srcSize field "
|
772
|
-
"error.");
|
775
|
+
"At least one frame successfully completed, "
|
776
|
+
"but following bytes are garbage: "
|
777
|
+
"it's more likely to be a srcSize error, "
|
778
|
+
"specifying more input bytes than size of frame(s). "
|
779
|
+
"Note: one could be unlucky, it might be a corruption error instead, "
|
780
|
+
"happening right at the place where we expect zstd magic bytes. "
|
781
|
+
"But this is _much_ less likely than a srcSize field error.");
|
773
782
|
if (ZSTD_isError(res)) return res;
|
774
783
|
assert(res <= dstCapacity);
|
775
784
|
if (res != 0)
|
@@ -781,7 +790,7 @@ static size_t ZSTD_decompressMultiFrame(ZSTD_DCtx* dctx,
|
|
781
790
|
|
782
791
|
RETURN_ERROR_IF(srcSize, srcSize_wrong, "input not entirely consumed");
|
783
792
|
|
784
|
-
return (BYTE*)dst - (BYTE*)dststart;
|
793
|
+
return (size_t)((BYTE*)dst - (BYTE*)dststart);
|
785
794
|
}
|
786
795
|
|
787
796
|
size_t ZSTD_decompress_usingDict(ZSTD_DCtx* dctx,
|
@@ -899,21 +908,21 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c
|
|
899
908
|
if (dctx->format == ZSTD_f_zstd1) { /* allows header */
|
900
909
|
assert(srcSize >= ZSTD_FRAMEIDSIZE); /* to read skippable magic number */
|
901
910
|
if ((MEM_readLE32(src) & ZSTD_MAGIC_SKIPPABLE_MASK) == ZSTD_MAGIC_SKIPPABLE_START) { /* skippable frame */
|
902
|
-
|
911
|
+
ZSTD_memcpy(dctx->headerBuffer, src, srcSize);
|
903
912
|
dctx->expected = ZSTD_SKIPPABLEHEADERSIZE - srcSize; /* remaining to load to get full skippable frame header */
|
904
913
|
dctx->stage = ZSTDds_decodeSkippableHeader;
|
905
914
|
return 0;
|
906
915
|
} }
|
907
916
|
dctx->headerSize = ZSTD_frameHeaderSize_internal(src, srcSize, dctx->format);
|
908
917
|
if (ZSTD_isError(dctx->headerSize)) return dctx->headerSize;
|
909
|
-
|
918
|
+
ZSTD_memcpy(dctx->headerBuffer, src, srcSize);
|
910
919
|
dctx->expected = dctx->headerSize - srcSize;
|
911
920
|
dctx->stage = ZSTDds_decodeFrameHeader;
|
912
921
|
return 0;
|
913
922
|
|
914
923
|
case ZSTDds_decodeFrameHeader:
|
915
924
|
assert(src != NULL);
|
916
|
-
|
925
|
+
ZSTD_memcpy(dctx->headerBuffer + (dctx->headerSize - srcSize), src, srcSize);
|
917
926
|
FORWARD_IF_ERROR(ZSTD_decodeFrameHeader(dctx, dctx->headerBuffer, dctx->headerSize), "");
|
918
927
|
dctx->expected = ZSTD_blockHeaderSize;
|
919
928
|
dctx->stage = ZSTDds_decodeBlockHeader;
|
@@ -977,7 +986,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c
|
|
977
986
|
RETURN_ERROR_IF(rSize > dctx->fParams.blockSizeMax, corruption_detected, "Decompressed Block Size Exceeds Maximum");
|
978
987
|
DEBUGLOG(5, "ZSTD_decompressContinue: decoded size from block : %u", (unsigned)rSize);
|
979
988
|
dctx->decodedSize += rSize;
|
980
|
-
if (dctx->
|
989
|
+
if (dctx->validateChecksum) XXH64_update(&dctx->xxhState, dst, rSize);
|
981
990
|
dctx->previousDstEnd = (char*)dst + rSize;
|
982
991
|
|
983
992
|
/* Stay on the same stage until we are finished streaming the block. */
|
@@ -1007,10 +1016,13 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c
|
|
1007
1016
|
|
1008
1017
|
case ZSTDds_checkChecksum:
|
1009
1018
|
assert(srcSize == 4); /* guaranteed by dctx->expected */
|
1010
|
-
{
|
1011
|
-
|
1012
|
-
|
1013
|
-
|
1019
|
+
{
|
1020
|
+
if (dctx->validateChecksum) {
|
1021
|
+
U32 const h32 = (U32)XXH64_digest(&dctx->xxhState);
|
1022
|
+
U32 const check32 = MEM_readLE32(src);
|
1023
|
+
DEBUGLOG(4, "ZSTD_decompressContinue: checksum : calculated %08X :: %08X read", (unsigned)h32, (unsigned)check32);
|
1024
|
+
RETURN_ERROR_IF(check32 != h32, checksum_wrong, "");
|
1025
|
+
}
|
1014
1026
|
dctx->expected = 0;
|
1015
1027
|
dctx->stage = ZSTDds_getFrameHeaderSize;
|
1016
1028
|
return 0;
|
@@ -1019,7 +1031,7 @@ size_t ZSTD_decompressContinue(ZSTD_DCtx* dctx, void* dst, size_t dstCapacity, c
|
|
1019
1031
|
case ZSTDds_decodeSkippableHeader:
|
1020
1032
|
assert(src != NULL);
|
1021
1033
|
assert(srcSize <= ZSTD_SKIPPABLEHEADERSIZE);
|
1022
|
-
|
1034
|
+
ZSTD_memcpy(dctx->headerBuffer + (ZSTD_SKIPPABLEHEADERSIZE - srcSize), src, srcSize); /* complete skippable header */
|
1023
1035
|
dctx->expected = MEM_readLE32(dctx->headerBuffer + ZSTD_FRAMEIDSIZE); /* note : dctx->expected can grow seriously large, beyond local buffer size */
|
1024
1036
|
dctx->stage = ZSTDds_skipFrame;
|
1025
1037
|
return 0;
|
@@ -1075,7 +1087,7 @@ ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
|
|
1075
1087
|
workspace, workspaceSize);
|
1076
1088
|
#else
|
1077
1089
|
size_t const hSize = HUF_readDTableX2_wksp(entropy->hufTable,
|
1078
|
-
dictPtr, dictEnd - dictPtr,
|
1090
|
+
dictPtr, (size_t)(dictEnd - dictPtr),
|
1079
1091
|
workspace, workspaceSize);
|
1080
1092
|
#endif
|
1081
1093
|
RETURN_ERROR_IF(HUF_isError(hSize), dictionary_corrupted, "");
|
@@ -1084,40 +1096,46 @@ ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
|
|
1084
1096
|
|
1085
1097
|
{ short offcodeNCount[MaxOff+1];
|
1086
1098
|
unsigned offcodeMaxValue = MaxOff, offcodeLog;
|
1087
|
-
size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, dictEnd-dictPtr);
|
1099
|
+
size_t const offcodeHeaderSize = FSE_readNCount(offcodeNCount, &offcodeMaxValue, &offcodeLog, dictPtr, (size_t)(dictEnd-dictPtr));
|
1088
1100
|
RETURN_ERROR_IF(FSE_isError(offcodeHeaderSize), dictionary_corrupted, "");
|
1089
1101
|
RETURN_ERROR_IF(offcodeMaxValue > MaxOff, dictionary_corrupted, "");
|
1090
1102
|
RETURN_ERROR_IF(offcodeLog > OffFSELog, dictionary_corrupted, "");
|
1091
1103
|
ZSTD_buildFSETable( entropy->OFTable,
|
1092
1104
|
offcodeNCount, offcodeMaxValue,
|
1093
1105
|
OF_base, OF_bits,
|
1094
|
-
offcodeLog
|
1106
|
+
offcodeLog,
|
1107
|
+
entropy->workspace, sizeof(entropy->workspace),
|
1108
|
+
/* bmi2 */0);
|
1095
1109
|
dictPtr += offcodeHeaderSize;
|
1096
1110
|
}
|
1097
1111
|
|
1098
1112
|
{ short matchlengthNCount[MaxML+1];
|
1099
1113
|
unsigned matchlengthMaxValue = MaxML, matchlengthLog;
|
1100
|
-
size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, dictEnd-dictPtr);
|
1114
|
+
size_t const matchlengthHeaderSize = FSE_readNCount(matchlengthNCount, &matchlengthMaxValue, &matchlengthLog, dictPtr, (size_t)(dictEnd-dictPtr));
|
1101
1115
|
RETURN_ERROR_IF(FSE_isError(matchlengthHeaderSize), dictionary_corrupted, "");
|
1102
1116
|
RETURN_ERROR_IF(matchlengthMaxValue > MaxML, dictionary_corrupted, "");
|
1103
1117
|
RETURN_ERROR_IF(matchlengthLog > MLFSELog, dictionary_corrupted, "");
|
1104
1118
|
ZSTD_buildFSETable( entropy->MLTable,
|
1105
1119
|
matchlengthNCount, matchlengthMaxValue,
|
1106
1120
|
ML_base, ML_bits,
|
1107
|
-
matchlengthLog
|
1121
|
+
matchlengthLog,
|
1122
|
+
entropy->workspace, sizeof(entropy->workspace),
|
1123
|
+
/* bmi2 */ 0);
|
1108
1124
|
dictPtr += matchlengthHeaderSize;
|
1109
1125
|
}
|
1110
1126
|
|
1111
1127
|
{ short litlengthNCount[MaxLL+1];
|
1112
1128
|
unsigned litlengthMaxValue = MaxLL, litlengthLog;
|
1113
|
-
size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, dictEnd-dictPtr);
|
1129
|
+
size_t const litlengthHeaderSize = FSE_readNCount(litlengthNCount, &litlengthMaxValue, &litlengthLog, dictPtr, (size_t)(dictEnd-dictPtr));
|
1114
1130
|
RETURN_ERROR_IF(FSE_isError(litlengthHeaderSize), dictionary_corrupted, "");
|
1115
1131
|
RETURN_ERROR_IF(litlengthMaxValue > MaxLL, dictionary_corrupted, "");
|
1116
1132
|
RETURN_ERROR_IF(litlengthLog > LLFSELog, dictionary_corrupted, "");
|
1117
1133
|
ZSTD_buildFSETable( entropy->LLTable,
|
1118
1134
|
litlengthNCount, litlengthMaxValue,
|
1119
1135
|
LL_base, LL_bits,
|
1120
|
-
litlengthLog
|
1136
|
+
litlengthLog,
|
1137
|
+
entropy->workspace, sizeof(entropy->workspace),
|
1138
|
+
/* bmi2 */ 0);
|
1121
1139
|
dictPtr += litlengthHeaderSize;
|
1122
1140
|
}
|
1123
1141
|
|
@@ -1131,7 +1149,7 @@ ZSTD_loadDEntropy(ZSTD_entropyDTables_t* entropy,
|
|
1131
1149
|
entropy->rep[i] = rep;
|
1132
1150
|
} }
|
1133
1151
|
|
1134
|
-
return dictPtr - (const BYTE*)dict;
|
1152
|
+
return (size_t)(dictPtr - (const BYTE*)dict);
|
1135
1153
|
}
|
1136
1154
|
|
1137
1155
|
static size_t ZSTD_decompress_insertDictionary(ZSTD_DCtx* dctx, const void* dict, size_t dictSize)
|
@@ -1170,7 +1188,7 @@ size_t ZSTD_decompressBegin(ZSTD_DCtx* dctx)
|
|
1170
1188
|
dctx->dictID = 0;
|
1171
1189
|
dctx->bType = bt_reserved;
|
1172
1190
|
ZSTD_STATIC_ASSERT(sizeof(dctx->entropy.rep) == sizeof(repStartValue));
|
1173
|
-
|
1191
|
+
ZSTD_memcpy(dctx->entropy.rep, repStartValue, sizeof(repStartValue)); /* initial repcodes */
|
1174
1192
|
dctx->LLTptr = dctx->entropy.LLTable;
|
1175
1193
|
dctx->MLTptr = dctx->entropy.MLTable;
|
1176
1194
|
dctx->OFTptr = dctx->entropy.OFTable;
|
@@ -1394,7 +1412,7 @@ size_t ZSTD_DCtx_setMaxWindowSize(ZSTD_DCtx* dctx, size_t maxWindowSize)
|
|
1394
1412
|
|
1395
1413
|
size_t ZSTD_DCtx_setFormat(ZSTD_DCtx* dctx, ZSTD_format_e format)
|
1396
1414
|
{
|
1397
|
-
return ZSTD_DCtx_setParameter(dctx, ZSTD_d_format, format);
|
1415
|
+
return ZSTD_DCtx_setParameter(dctx, ZSTD_d_format, (int)format);
|
1398
1416
|
}
|
1399
1417
|
|
1400
1418
|
ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam)
|
@@ -1411,8 +1429,12 @@ ZSTD_bounds ZSTD_dParam_getBounds(ZSTD_dParameter dParam)
|
|
1411
1429
|
ZSTD_STATIC_ASSERT(ZSTD_f_zstd1 < ZSTD_f_zstd1_magicless);
|
1412
1430
|
return bounds;
|
1413
1431
|
case ZSTD_d_stableOutBuffer:
|
1414
|
-
bounds.lowerBound = (int)
|
1415
|
-
bounds.upperBound = (int)
|
1432
|
+
bounds.lowerBound = (int)ZSTD_bm_buffered;
|
1433
|
+
bounds.upperBound = (int)ZSTD_bm_stable;
|
1434
|
+
return bounds;
|
1435
|
+
case ZSTD_d_forceIgnoreChecksum:
|
1436
|
+
bounds.lowerBound = (int)ZSTD_d_validateChecksum;
|
1437
|
+
bounds.upperBound = (int)ZSTD_d_ignoreChecksum;
|
1416
1438
|
return bounds;
|
1417
1439
|
default:;
|
1418
1440
|
}
|
@@ -1436,6 +1458,26 @@ static int ZSTD_dParam_withinBounds(ZSTD_dParameter dParam, int value)
|
|
1436
1458
|
RETURN_ERROR_IF(!ZSTD_dParam_withinBounds(p, v), parameter_outOfBound, ""); \
|
1437
1459
|
}
|
1438
1460
|
|
1461
|
+
size_t ZSTD_DCtx_getParameter(ZSTD_DCtx* dctx, ZSTD_dParameter param, int* value)
|
1462
|
+
{
|
1463
|
+
switch (param) {
|
1464
|
+
case ZSTD_d_windowLogMax:
|
1465
|
+
*value = (int)ZSTD_highbit32((U32)dctx->maxWindowSize);
|
1466
|
+
return 0;
|
1467
|
+
case ZSTD_d_format:
|
1468
|
+
*value = (int)dctx->format;
|
1469
|
+
return 0;
|
1470
|
+
case ZSTD_d_stableOutBuffer:
|
1471
|
+
*value = (int)dctx->outBufferMode;
|
1472
|
+
return 0;
|
1473
|
+
case ZSTD_d_forceIgnoreChecksum:
|
1474
|
+
*value = (int)dctx->forceIgnoreChecksum;
|
1475
|
+
return 0;
|
1476
|
+
default:;
|
1477
|
+
}
|
1478
|
+
RETURN_ERROR(parameter_unsupported, "");
|
1479
|
+
}
|
1480
|
+
|
1439
1481
|
size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter dParam, int value)
|
1440
1482
|
{
|
1441
1483
|
RETURN_ERROR_IF(dctx->streamStage != zdss_init, stage_wrong, "");
|
@@ -1451,7 +1493,11 @@ size_t ZSTD_DCtx_setParameter(ZSTD_DCtx* dctx, ZSTD_dParameter dParam, int value
|
|
1451
1493
|
return 0;
|
1452
1494
|
case ZSTD_d_stableOutBuffer:
|
1453
1495
|
CHECK_DBOUNDS(ZSTD_d_stableOutBuffer, value);
|
1454
|
-
dctx->outBufferMode = (
|
1496
|
+
dctx->outBufferMode = (ZSTD_bufferMode_e)value;
|
1497
|
+
return 0;
|
1498
|
+
case ZSTD_d_forceIgnoreChecksum:
|
1499
|
+
CHECK_DBOUNDS(ZSTD_d_forceIgnoreChecksum, value);
|
1500
|
+
dctx->forceIgnoreChecksum = (ZSTD_forceIgnoreChecksum_e)value;
|
1455
1501
|
return 0;
|
1456
1502
|
default:;
|
1457
1503
|
}
|
@@ -1469,8 +1515,7 @@ size_t ZSTD_DCtx_reset(ZSTD_DCtx* dctx, ZSTD_ResetDirective reset)
|
|
1469
1515
|
|| (reset == ZSTD_reset_session_and_parameters) ) {
|
1470
1516
|
RETURN_ERROR_IF(dctx->streamStage != zdss_init, stage_wrong, "");
|
1471
1517
|
ZSTD_clearDict(dctx);
|
1472
|
-
dctx
|
1473
|
-
dctx->maxWindowSize = ZSTD_MAXWINDOWSIZE_DEFAULT;
|
1518
|
+
ZSTD_DCtx_resetParameters(dctx);
|
1474
1519
|
}
|
1475
1520
|
return 0;
|
1476
1521
|
}
|
@@ -1524,7 +1569,7 @@ static void ZSTD_DCtx_updateOversizedDuration(ZSTD_DStream* zds, size_t const ne
|
|
1524
1569
|
{
|
1525
1570
|
if (ZSTD_DCtx_isOverflow(zds, neededInBuffSize, neededOutBuffSize))
|
1526
1571
|
zds->oversizedDuration++;
|
1527
|
-
else
|
1572
|
+
else
|
1528
1573
|
zds->oversizedDuration = 0;
|
1529
1574
|
}
|
1530
1575
|
|
@@ -1538,7 +1583,7 @@ static size_t ZSTD_checkOutBuffer(ZSTD_DStream const* zds, ZSTD_outBuffer const*
|
|
1538
1583
|
{
|
1539
1584
|
ZSTD_outBuffer const expect = zds->expectedOutBuffer;
|
1540
1585
|
/* No requirement when ZSTD_obm_stable is not enabled. */
|
1541
|
-
if (zds->outBufferMode !=
|
1586
|
+
if (zds->outBufferMode != ZSTD_bm_stable)
|
1542
1587
|
return 0;
|
1543
1588
|
/* Any buffer is allowed in zdss_init, this must be the same for every other call until
|
1544
1589
|
* the context is reset.
|
@@ -1548,7 +1593,7 @@ static size_t ZSTD_checkOutBuffer(ZSTD_DStream const* zds, ZSTD_outBuffer const*
|
|
1548
1593
|
/* The buffer must match our expectation exactly. */
|
1549
1594
|
if (expect.dst == output->dst && expect.pos == output->pos && expect.size == output->size)
|
1550
1595
|
return 0;
|
1551
|
-
RETURN_ERROR(dstBuffer_wrong, "
|
1596
|
+
RETURN_ERROR(dstBuffer_wrong, "ZSTD_d_stableOutBuffer enabled but output differs!");
|
1552
1597
|
}
|
1553
1598
|
|
1554
1599
|
/* Calls ZSTD_decompressContinue() with the right parameters for ZSTD_decompressStream()
|
@@ -1560,7 +1605,7 @@ static size_t ZSTD_decompressContinueStream(
|
|
1560
1605
|
ZSTD_DStream* zds, char** op, char* oend,
|
1561
1606
|
void const* src, size_t srcSize) {
|
1562
1607
|
int const isSkipFrame = ZSTD_isSkipFrame(zds);
|
1563
|
-
if (zds->outBufferMode ==
|
1608
|
+
if (zds->outBufferMode == ZSTD_bm_buffered) {
|
1564
1609
|
size_t const dstSize = isSkipFrame ? 0 : zds->outBuffSize - zds->outStart;
|
1565
1610
|
size_t const decodedSize = ZSTD_decompressContinue(zds,
|
1566
1611
|
zds->outBuff + zds->outStart, dstSize, src, srcSize);
|
@@ -1573,14 +1618,14 @@ static size_t ZSTD_decompressContinueStream(
|
|
1573
1618
|
}
|
1574
1619
|
} else {
|
1575
1620
|
/* Write directly into the output buffer */
|
1576
|
-
size_t const dstSize = isSkipFrame ? 0 : oend - *op;
|
1621
|
+
size_t const dstSize = isSkipFrame ? 0 : (size_t)(oend - *op);
|
1577
1622
|
size_t const decodedSize = ZSTD_decompressContinue(zds, *op, dstSize, src, srcSize);
|
1578
1623
|
FORWARD_IF_ERROR(decodedSize, "");
|
1579
1624
|
*op += decodedSize;
|
1580
1625
|
/* Flushing is not needed. */
|
1581
1626
|
zds->streamStage = zdss_read;
|
1582
1627
|
assert(*op <= oend);
|
1583
|
-
assert(zds->outBufferMode ==
|
1628
|
+
assert(zds->outBufferMode == ZSTD_bm_stable);
|
1584
1629
|
}
|
1585
1630
|
return 0;
|
1586
1631
|
}
|
@@ -1663,14 +1708,14 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1663
1708
|
assert(iend >= ip);
|
1664
1709
|
if (toLoad > remainingInput) { /* not enough input to load full header */
|
1665
1710
|
if (remainingInput > 0) {
|
1666
|
-
|
1711
|
+
ZSTD_memcpy(zds->headerBuffer + zds->lhSize, ip, remainingInput);
|
1667
1712
|
zds->lhSize += remainingInput;
|
1668
1713
|
}
|
1669
1714
|
input->pos = input->size;
|
1670
1715
|
return (MAX((size_t)ZSTD_FRAMEHEADERSIZE_MIN(zds->format), hSize) - zds->lhSize) + ZSTD_blockHeaderSize; /* remaining header bytes + next block header */
|
1671
1716
|
}
|
1672
1717
|
assert(ip != NULL);
|
1673
|
-
|
1718
|
+
ZSTD_memcpy(zds->headerBuffer + zds->lhSize, ip, toLoad); zds->lhSize = hSize; ip += toLoad;
|
1674
1719
|
break;
|
1675
1720
|
} }
|
1676
1721
|
|
@@ -1678,10 +1723,10 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1678
1723
|
if (zds->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN
|
1679
1724
|
&& zds->fParams.frameType != ZSTD_skippableFrame
|
1680
1725
|
&& (U64)(size_t)(oend-op) >= zds->fParams.frameContentSize) {
|
1681
|
-
size_t const cSize = ZSTD_findFrameCompressedSize(istart, iend-istart);
|
1726
|
+
size_t const cSize = ZSTD_findFrameCompressedSize(istart, (size_t)(iend-istart));
|
1682
1727
|
if (cSize <= (size_t)(iend-istart)) {
|
1683
1728
|
/* shortcut : using single-pass mode */
|
1684
|
-
size_t const decompressedSize = ZSTD_decompress_usingDDict(zds, op, oend-op, istart, cSize, ZSTD_getDDict(zds));
|
1729
|
+
size_t const decompressedSize = ZSTD_decompress_usingDDict(zds, op, (size_t)(oend-op), istart, cSize, ZSTD_getDDict(zds));
|
1685
1730
|
if (ZSTD_isError(decompressedSize)) return decompressedSize;
|
1686
1731
|
DEBUGLOG(4, "shortcut to single-pass ZSTD_decompress_usingDDict()")
|
1687
1732
|
ip = istart + cSize;
|
@@ -1693,7 +1738,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1693
1738
|
} }
|
1694
1739
|
|
1695
1740
|
/* Check output buffer is large enough for ZSTD_odm_stable. */
|
1696
|
-
if (zds->outBufferMode ==
|
1741
|
+
if (zds->outBufferMode == ZSTD_bm_stable
|
1697
1742
|
&& zds->fParams.frameType != ZSTD_skippableFrame
|
1698
1743
|
&& zds->fParams.frameContentSize != ZSTD_CONTENTSIZE_UNKNOWN
|
1699
1744
|
&& (U64)(size_t)(oend-op) < zds->fParams.frameContentSize) {
|
@@ -1723,7 +1768,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1723
1768
|
|
1724
1769
|
/* Adapt buffer sizes to frame header instructions */
|
1725
1770
|
{ size_t const neededInBuffSize = MAX(zds->fParams.blockSizeMax, 4 /* frame checksum */);
|
1726
|
-
size_t const neededOutBuffSize = zds->outBufferMode ==
|
1771
|
+
size_t const neededOutBuffSize = zds->outBufferMode == ZSTD_bm_buffered
|
1727
1772
|
? ZSTD_decodingBufferSize_min(zds->fParams.windowSize, zds->fParams.frameContentSize)
|
1728
1773
|
: 0;
|
1729
1774
|
|
@@ -1731,7 +1776,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1731
1776
|
|
1732
1777
|
{ int const tooSmall = (zds->inBuffSize < neededInBuffSize) || (zds->outBuffSize < neededOutBuffSize);
|
1733
1778
|
int const tooLarge = ZSTD_DCtx_isOversizedTooLong(zds);
|
1734
|
-
|
1779
|
+
|
1735
1780
|
if (tooSmall || tooLarge) {
|
1736
1781
|
size_t const bufferSize = neededInBuffSize + neededOutBuffSize;
|
1737
1782
|
DEBUGLOG(4, "inBuff : from %u to %u",
|
@@ -1745,10 +1790,10 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1745
1790
|
bufferSize > zds->staticSize - sizeof(ZSTD_DCtx),
|
1746
1791
|
memory_allocation, "");
|
1747
1792
|
} else {
|
1748
|
-
|
1793
|
+
ZSTD_customFree(zds->inBuff, zds->customMem);
|
1749
1794
|
zds->inBuffSize = 0;
|
1750
1795
|
zds->outBuffSize = 0;
|
1751
|
-
zds->inBuff = (char*)
|
1796
|
+
zds->inBuff = (char*)ZSTD_customMalloc(bufferSize, zds->customMem);
|
1752
1797
|
RETURN_ERROR_IF(zds->inBuff == NULL, memory_allocation, "");
|
1753
1798
|
}
|
1754
1799
|
zds->inBuffSize = neededInBuffSize;
|
@@ -1760,7 +1805,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1760
1805
|
|
1761
1806
|
case zdss_read:
|
1762
1807
|
DEBUGLOG(5, "stage zdss_read");
|
1763
|
-
{ size_t const neededInSize = ZSTD_nextSrcSizeToDecompressWithInputSize(zds, iend - ip);
|
1808
|
+
{ size_t const neededInSize = ZSTD_nextSrcSizeToDecompressWithInputSize(zds, (size_t)(iend - ip));
|
1764
1809
|
DEBUGLOG(5, "neededInSize = %u", (U32)neededInSize);
|
1765
1810
|
if (neededInSize==0) { /* end of frame */
|
1766
1811
|
zds->streamStage = zdss_init;
|
@@ -1790,7 +1835,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1790
1835
|
RETURN_ERROR_IF(toLoad > zds->inBuffSize - zds->inPos,
|
1791
1836
|
corruption_detected,
|
1792
1837
|
"should never happen");
|
1793
|
-
loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, iend-ip);
|
1838
|
+
loadedSize = ZSTD_limitCopy(zds->inBuff + zds->inPos, toLoad, ip, (size_t)(iend-ip));
|
1794
1839
|
}
|
1795
1840
|
ip += loadedSize;
|
1796
1841
|
zds->inPos += loadedSize;
|
@@ -1804,7 +1849,7 @@ size_t ZSTD_decompressStream(ZSTD_DStream* zds, ZSTD_outBuffer* output, ZSTD_inB
|
|
1804
1849
|
}
|
1805
1850
|
case zdss_flush:
|
1806
1851
|
{ size_t const toFlushSize = zds->outEnd - zds->outStart;
|
1807
|
-
size_t const flushedSize = ZSTD_limitCopy(op, oend-op, zds->outBuff + zds->outStart, toFlushSize);
|
1852
|
+
size_t const flushedSize = ZSTD_limitCopy(op, (size_t)(oend-op), zds->outBuff + zds->outStart, toFlushSize);
|
1808
1853
|
op += flushedSize;
|
1809
1854
|
zds->outStart += flushedSize;
|
1810
1855
|
if (flushedSize == toFlushSize) { /* flush completed */
|