zstd-ruby 1.3.8.0 → 1.4.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +6 -5
- data/README.md +1 -1
- data/ext/zstdruby/libzstd/Makefile +7 -3
- data/ext/zstdruby/libzstd/README.md +4 -2
- data/ext/zstdruby/libzstd/common/compiler.h +1 -1
- data/ext/zstdruby/libzstd/common/fse.h +1 -1
- data/ext/zstdruby/libzstd/common/threading.c +2 -2
- data/ext/zstdruby/libzstd/common/xxhash.c +2 -2
- data/ext/zstdruby/libzstd/common/zstd_internal.h +55 -2
- data/ext/zstdruby/libzstd/compress/fse_compress.c +2 -2
- data/ext/zstdruby/libzstd/compress/zstd_compress.c +423 -296
- data/ext/zstdruby/libzstd/compress/zstd_compress_internal.h +14 -11
- data/ext/zstdruby/libzstd/compress/zstd_fast.c +203 -124
- data/ext/zstdruby/libzstd/compress/zstd_lazy.h +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_ldm.c +1 -1
- data/ext/zstdruby/libzstd/compress/zstd_opt.c +27 -11
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.c +41 -49
- data/ext/zstdruby/libzstd/compress/zstdmt_compress.h +43 -26
- data/ext/zstdruby/libzstd/decompress/zstd_ddict.c +4 -4
- data/ext/zstdruby/libzstd/decompress/zstd_decompress.c +257 -164
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_block.c +51 -47
- data/ext/zstdruby/libzstd/decompress/zstd_decompress_internal.h +7 -0
- data/ext/zstdruby/libzstd/dictBuilder/cover.c +58 -13
- data/ext/zstdruby/libzstd/dictBuilder/cover.h +29 -0
- data/ext/zstdruby/libzstd/dictBuilder/fastcover.c +25 -13
- data/ext/zstdruby/libzstd/dictBuilder/zdict.h +18 -8
- data/ext/zstdruby/libzstd/dll/example/build_package.bat +3 -2
- data/ext/zstdruby/libzstd/legacy/zstd_legacy.h +42 -12
- data/ext/zstdruby/libzstd/legacy/zstd_v01.c +32 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v01.h +12 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v02.c +31 -12
- data/ext/zstdruby/libzstd/legacy/zstd_v02.h +12 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v03.c +32 -12
- data/ext/zstdruby/libzstd/legacy/zstd_v03.h +12 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v04.c +32 -12
- data/ext/zstdruby/libzstd/legacy/zstd_v04.h +12 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v05.c +32 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v05.h +12 -7
- data/ext/zstdruby/libzstd/legacy/zstd_v06.c +36 -8
- data/ext/zstdruby/libzstd/legacy/zstd_v06.h +10 -5
- data/ext/zstdruby/libzstd/legacy/zstd_v07.c +40 -9
- data/ext/zstdruby/libzstd/legacy/zstd_v07.h +10 -5
- data/ext/zstdruby/libzstd/zstd.h +689 -542
- data/lib/zstd-ruby/version.rb +1 -1
- data/zstd-ruby.gemspec +1 -1
- metadata +6 -7
- data/ext/zstdruby/libzstd/dll/libzstd.def +0 -87
@@ -35,13 +35,18 @@ ZSTDv02_decompress() : decompress ZSTD frames compliant with v0.2.x format
|
|
35
35
|
size_t ZSTDv02_decompress( void* dst, size_t maxOriginalSize,
|
36
36
|
const void* src, size_t compressedSize);
|
37
37
|
|
38
|
-
/**
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
/**
|
39
|
+
ZSTDv02_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.2.x format
|
40
|
+
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
41
|
+
cSize (output parameter) : the number of bytes that would be read to decompress this frame
|
42
|
+
or an error code if it fails (which can be tested using ZSTDv01_isError())
|
43
|
+
dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame
|
44
|
+
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
45
|
+
|
46
|
+
note : assumes `cSize` and `dBound` are _not_ NULL.
|
47
|
+
*/
|
48
|
+
void ZSTDv02_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
49
|
+
size_t* cSize, unsigned long long* dBound);
|
45
50
|
|
46
51
|
/**
|
47
52
|
ZSTDv02_isError() : tells if the result of ZSTDv02_decompress() is an error
|
@@ -2369,6 +2369,8 @@ static size_t HUF_decompress (void* dst, size_t dstSize, const void* cSrc, size_
|
|
2369
2369
|
#define LITERAL_NOENTROPY 63
|
2370
2370
|
#define COMMAND_NOENTROPY 7 /* to remove */
|
2371
2371
|
|
2372
|
+
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
|
2373
|
+
|
2372
2374
|
static const size_t ZSTD_blockHeaderSize = 3;
|
2373
2375
|
static const size_t ZSTD_frameHeaderSize = 4;
|
2374
2376
|
|
@@ -2737,7 +2739,7 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
2737
2739
|
BYTE* const base, BYTE* const oend)
|
2738
2740
|
{
|
2739
2741
|
static const int dec32table[] = {0, 1, 2, 1, 4, 4, 4, 4}; /* added */
|
2740
|
-
static const int dec64table[] = {8, 8, 8, 7, 8, 9,10,11}; /*
|
2742
|
+
static const int dec64table[] = {8, 8, 8, 7, 8, 9,10,11}; /* subtracted */
|
2741
2743
|
const BYTE* const ostart = op;
|
2742
2744
|
BYTE* const oLitEnd = op + sequence.litLength;
|
2743
2745
|
BYTE* const oMatchEnd = op + sequence.litLength + sequence.matchLength; /* risk : address space overflow (32-bits) */
|
@@ -2953,36 +2955,59 @@ static size_t ZSTD_decompress(void* dst, size_t maxDstSize, const void* src, siz
|
|
2953
2955
|
return ZSTD_decompressDCtx(&ctx, dst, maxDstSize, src, srcSize);
|
2954
2956
|
}
|
2955
2957
|
|
2956
|
-
|
2958
|
+
/* ZSTD_errorFrameSizeInfoLegacy() :
|
2959
|
+
assumes `cSize` and `dBound` are _not_ NULL */
|
2960
|
+
MEM_STATIC void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
|
2961
|
+
{
|
2962
|
+
*cSize = ret;
|
2963
|
+
*dBound = ZSTD_CONTENTSIZE_ERROR;
|
2964
|
+
}
|
2965
|
+
|
2966
|
+
void ZSTDv03_findFrameSizeInfoLegacy(const void *src, size_t srcSize, size_t* cSize, unsigned long long* dBound)
|
2957
2967
|
{
|
2958
2968
|
const BYTE* ip = (const BYTE*)src;
|
2959
2969
|
size_t remainingSize = srcSize;
|
2970
|
+
size_t nbBlocks = 0;
|
2960
2971
|
U32 magicNumber;
|
2961
2972
|
blockProperties_t blockProperties;
|
2962
2973
|
|
2963
2974
|
/* Frame Header */
|
2964
|
-
if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize)
|
2975
|
+
if (srcSize < ZSTD_frameHeaderSize+ZSTD_blockHeaderSize) {
|
2976
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
2977
|
+
return;
|
2978
|
+
}
|
2965
2979
|
magicNumber = MEM_readLE32(src);
|
2966
|
-
if (magicNumber != ZSTD_magicNumber)
|
2980
|
+
if (magicNumber != ZSTD_magicNumber) {
|
2981
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(prefix_unknown));
|
2982
|
+
return;
|
2983
|
+
}
|
2967
2984
|
ip += ZSTD_frameHeaderSize; remainingSize -= ZSTD_frameHeaderSize;
|
2968
2985
|
|
2969
2986
|
/* Loop on each block */
|
2970
2987
|
while (1)
|
2971
2988
|
{
|
2972
2989
|
size_t cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
|
2973
|
-
if (ZSTD_isError(cBlockSize))
|
2990
|
+
if (ZSTD_isError(cBlockSize)) {
|
2991
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, cBlockSize);
|
2992
|
+
return;
|
2993
|
+
}
|
2974
2994
|
|
2975
2995
|
ip += ZSTD_blockHeaderSize;
|
2976
2996
|
remainingSize -= ZSTD_blockHeaderSize;
|
2977
|
-
if (cBlockSize > remainingSize)
|
2997
|
+
if (cBlockSize > remainingSize) {
|
2998
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
2999
|
+
return;
|
3000
|
+
}
|
2978
3001
|
|
2979
3002
|
if (cBlockSize == 0) break; /* bt_end */
|
2980
3003
|
|
2981
3004
|
ip += cBlockSize;
|
2982
3005
|
remainingSize -= cBlockSize;
|
3006
|
+
nbBlocks++;
|
2983
3007
|
}
|
2984
3008
|
|
2985
|
-
|
3009
|
+
*cSize = ip - (const BYTE*)src;
|
3010
|
+
*dBound = nbBlocks * BLOCKSIZE;
|
2986
3011
|
}
|
2987
3012
|
|
2988
3013
|
|
@@ -3099,11 +3124,6 @@ size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
|
|
3099
3124
|
return ZSTD_decompress(dst, maxOriginalSize, src, compressedSize);
|
3100
3125
|
}
|
3101
3126
|
|
3102
|
-
size_t ZSTDv03_findFrameCompressedSize(const void* src, size_t srcSize)
|
3103
|
-
{
|
3104
|
-
return ZSTD_findFrameCompressedSize(src, srcSize);
|
3105
|
-
}
|
3106
|
-
|
3107
3127
|
ZSTDv03_Dctx* ZSTDv03_createDCtx(void)
|
3108
3128
|
{
|
3109
3129
|
return (ZSTDv03_Dctx*)ZSTD_createDCtx();
|
@@ -35,13 +35,18 @@ ZSTDv03_decompress() : decompress ZSTD frames compliant with v0.3.x format
|
|
35
35
|
size_t ZSTDv03_decompress( void* dst, size_t maxOriginalSize,
|
36
36
|
const void* src, size_t compressedSize);
|
37
37
|
|
38
|
-
/**
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
/**
|
39
|
+
ZSTDv03_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.3.x format
|
40
|
+
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
41
|
+
cSize (output parameter) : the number of bytes that would be read to decompress this frame
|
42
|
+
or an error code if it fails (which can be tested using ZSTDv01_isError())
|
43
|
+
dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame
|
44
|
+
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
45
|
+
|
46
|
+
note : assumes `cSize` and `dBound` are _not_ NULL.
|
47
|
+
*/
|
48
|
+
void ZSTDv03_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
49
|
+
size_t* cSize, unsigned long long* dBound);
|
45
50
|
|
46
51
|
/**
|
47
52
|
ZSTDv03_isError() : tells if the result of ZSTDv03_decompress() is an error
|
@@ -373,6 +373,8 @@ static const size_t ZSTD_frameHeaderSize_min = 5;
|
|
373
373
|
#define MIN_SEQUENCES_SIZE (2 /*seqNb*/ + 2 /*dumps*/ + 3 /*seqTables*/ + 1 /*bitStream*/)
|
374
374
|
#define MIN_CBLOCK_SIZE (3 /*litCSize*/ + MIN_SEQUENCES_SIZE)
|
375
375
|
|
376
|
+
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
|
377
|
+
|
376
378
|
typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
|
377
379
|
|
378
380
|
|
@@ -2860,7 +2862,7 @@ static size_t ZSTD_execSequence(BYTE* op,
|
|
2860
2862
|
const BYTE* const base, const BYTE* const vBase, const BYTE* const dictEnd)
|
2861
2863
|
{
|
2862
2864
|
static const int dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 }; /* added */
|
2863
|
-
static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /*
|
2865
|
+
static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* subtracted */
|
2864
2866
|
BYTE* const oLitEnd = op + sequence.litLength;
|
2865
2867
|
const size_t sequenceLength = sequence.litLength + sequence.matchLength;
|
2866
2868
|
BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */
|
@@ -3119,34 +3121,57 @@ static size_t ZSTD_decompress_usingDict(ZSTD_DCtx* ctx,
|
|
3119
3121
|
return op-ostart;
|
3120
3122
|
}
|
3121
3123
|
|
3122
|
-
|
3124
|
+
/* ZSTD_errorFrameSizeInfoLegacy() :
|
3125
|
+
assumes `cSize` and `dBound` are _not_ NULL */
|
3126
|
+
static void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
|
3127
|
+
{
|
3128
|
+
*cSize = ret;
|
3129
|
+
*dBound = ZSTD_CONTENTSIZE_ERROR;
|
3130
|
+
}
|
3131
|
+
|
3132
|
+
void ZSTDv04_findFrameSizeInfoLegacy(const void *src, size_t srcSize, size_t* cSize, unsigned long long* dBound)
|
3123
3133
|
{
|
3124
3134
|
const BYTE* ip = (const BYTE*)src;
|
3125
3135
|
size_t remainingSize = srcSize;
|
3136
|
+
size_t nbBlocks = 0;
|
3126
3137
|
blockProperties_t blockProperties;
|
3127
3138
|
|
3128
3139
|
/* Frame Header */
|
3129
|
-
if (srcSize < ZSTD_frameHeaderSize_min)
|
3130
|
-
|
3140
|
+
if (srcSize < ZSTD_frameHeaderSize_min) {
|
3141
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
3142
|
+
return;
|
3143
|
+
}
|
3144
|
+
if (MEM_readLE32(src) != ZSTD_MAGICNUMBER) {
|
3145
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(prefix_unknown));
|
3146
|
+
return;
|
3147
|
+
}
|
3131
3148
|
ip += ZSTD_frameHeaderSize_min; remainingSize -= ZSTD_frameHeaderSize_min;
|
3132
3149
|
|
3133
3150
|
/* Loop on each block */
|
3134
3151
|
while (1)
|
3135
3152
|
{
|
3136
3153
|
size_t cBlockSize = ZSTD_getcBlockSize(ip, remainingSize, &blockProperties);
|
3137
|
-
if (ZSTD_isError(cBlockSize))
|
3154
|
+
if (ZSTD_isError(cBlockSize)) {
|
3155
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, cBlockSize);
|
3156
|
+
return;
|
3157
|
+
}
|
3138
3158
|
|
3139
3159
|
ip += ZSTD_blockHeaderSize;
|
3140
3160
|
remainingSize -= ZSTD_blockHeaderSize;
|
3141
|
-
if (cBlockSize > remainingSize)
|
3161
|
+
if (cBlockSize > remainingSize) {
|
3162
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
3163
|
+
return;
|
3164
|
+
}
|
3142
3165
|
|
3143
3166
|
if (cBlockSize == 0) break; /* bt_end */
|
3144
3167
|
|
3145
3168
|
ip += cBlockSize;
|
3146
3169
|
remainingSize -= cBlockSize;
|
3170
|
+
nbBlocks++;
|
3147
3171
|
}
|
3148
3172
|
|
3149
|
-
|
3173
|
+
*cSize = ip - (const BYTE*)src;
|
3174
|
+
*dBound = nbBlocks * BLOCKSIZE;
|
3150
3175
|
}
|
3151
3176
|
|
3152
3177
|
/* ******************************
|
@@ -3578,11 +3603,6 @@ size_t ZSTDv04_decompress(void* dst, size_t maxDstSize, const void* src, size_t
|
|
3578
3603
|
#endif
|
3579
3604
|
}
|
3580
3605
|
|
3581
|
-
size_t ZSTDv04_findFrameCompressedSize(const void* src, size_t srcSize)
|
3582
|
-
{
|
3583
|
-
return ZSTD_findFrameCompressedSize(src, srcSize);
|
3584
|
-
}
|
3585
|
-
|
3586
3606
|
size_t ZSTDv04_resetDCtx(ZSTDv04_Dctx* dctx) { return ZSTD_resetDCtx(dctx); }
|
3587
3607
|
|
3588
3608
|
size_t ZSTDv04_nextSrcSizeToDecompress(ZSTDv04_Dctx* dctx)
|
@@ -35,13 +35,18 @@ ZSTDv04_decompress() : decompress ZSTD frames compliant with v0.4.x format
|
|
35
35
|
size_t ZSTDv04_decompress( void* dst, size_t maxOriginalSize,
|
36
36
|
const void* src, size_t compressedSize);
|
37
37
|
|
38
|
-
/**
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
38
|
+
/**
|
39
|
+
ZSTDv04_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.4.x format
|
40
|
+
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
41
|
+
cSize (output parameter) : the number of bytes that would be read to decompress this frame
|
42
|
+
or an error code if it fails (which can be tested using ZSTDv01_isError())
|
43
|
+
dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame
|
44
|
+
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
45
|
+
|
46
|
+
note : assumes `cSize` and `dBound` are _not_ NULL.
|
47
|
+
*/
|
48
|
+
void ZSTDv04_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
49
|
+
size_t* cSize, unsigned long long* dBound);
|
45
50
|
|
46
51
|
/**
|
47
52
|
ZSTDv04_isError() : tells if the result of ZSTDv04_decompress() is an error
|
@@ -491,6 +491,8 @@ static const size_t ZSTDv05_frameHeaderSize_min = 5;
|
|
491
491
|
|
492
492
|
#define WILDCOPY_OVERLENGTH 8
|
493
493
|
|
494
|
+
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
|
495
|
+
|
494
496
|
typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
|
495
497
|
|
496
498
|
|
@@ -3217,7 +3219,7 @@ static size_t ZSTDv05_execSequence(BYTE* op,
|
|
3217
3219
|
const BYTE* const base, const BYTE* const vBase, const BYTE* const dictEnd)
|
3218
3220
|
{
|
3219
3221
|
static const int dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 }; /* added */
|
3220
|
-
static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /*
|
3222
|
+
static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* subtracted */
|
3221
3223
|
BYTE* const oLitEnd = op + sequence.litLength;
|
3222
3224
|
const size_t sequenceLength = sequence.litLength + sequence.matchLength;
|
3223
3225
|
BYTE* const oMatchEnd = op + sequenceLength; /* risk : address space overflow (32-bits) */
|
@@ -3508,34 +3510,57 @@ size_t ZSTDv05_decompress(void* dst, size_t maxDstSize, const void* src, size_t
|
|
3508
3510
|
#endif
|
3509
3511
|
}
|
3510
3512
|
|
3511
|
-
|
3513
|
+
/* ZSTD_errorFrameSizeInfoLegacy() :
|
3514
|
+
assumes `cSize` and `dBound` are _not_ NULL */
|
3515
|
+
static void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
|
3516
|
+
{
|
3517
|
+
*cSize = ret;
|
3518
|
+
*dBound = ZSTD_CONTENTSIZE_ERROR;
|
3519
|
+
}
|
3520
|
+
|
3521
|
+
void ZSTDv05_findFrameSizeInfoLegacy(const void *src, size_t srcSize, size_t* cSize, unsigned long long* dBound)
|
3512
3522
|
{
|
3513
3523
|
const BYTE* ip = (const BYTE*)src;
|
3514
3524
|
size_t remainingSize = srcSize;
|
3525
|
+
size_t nbBlocks = 0;
|
3515
3526
|
blockProperties_t blockProperties;
|
3516
3527
|
|
3517
3528
|
/* Frame Header */
|
3518
|
-
if (srcSize < ZSTDv05_frameHeaderSize_min)
|
3519
|
-
|
3529
|
+
if (srcSize < ZSTDv05_frameHeaderSize_min) {
|
3530
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
3531
|
+
return;
|
3532
|
+
}
|
3533
|
+
if (MEM_readLE32(src) != ZSTDv05_MAGICNUMBER) {
|
3534
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(prefix_unknown));
|
3535
|
+
return;
|
3536
|
+
}
|
3520
3537
|
ip += ZSTDv05_frameHeaderSize_min; remainingSize -= ZSTDv05_frameHeaderSize_min;
|
3521
3538
|
|
3522
3539
|
/* Loop on each block */
|
3523
3540
|
while (1)
|
3524
3541
|
{
|
3525
3542
|
size_t cBlockSize = ZSTDv05_getcBlockSize(ip, remainingSize, &blockProperties);
|
3526
|
-
if (ZSTDv05_isError(cBlockSize))
|
3543
|
+
if (ZSTDv05_isError(cBlockSize)) {
|
3544
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, cBlockSize);
|
3545
|
+
return;
|
3546
|
+
}
|
3527
3547
|
|
3528
3548
|
ip += ZSTDv05_blockHeaderSize;
|
3529
3549
|
remainingSize -= ZSTDv05_blockHeaderSize;
|
3530
|
-
if (cBlockSize > remainingSize)
|
3550
|
+
if (cBlockSize > remainingSize) {
|
3551
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
3552
|
+
return;
|
3553
|
+
}
|
3531
3554
|
|
3532
3555
|
if (cBlockSize == 0) break; /* bt_end */
|
3533
3556
|
|
3534
3557
|
ip += cBlockSize;
|
3535
3558
|
remainingSize -= cBlockSize;
|
3559
|
+
nbBlocks++;
|
3536
3560
|
}
|
3537
3561
|
|
3538
|
-
|
3562
|
+
*cSize = ip - (const BYTE*)src;
|
3563
|
+
*dBound = nbBlocks * BLOCKSIZE;
|
3539
3564
|
}
|
3540
3565
|
|
3541
3566
|
/* ******************************
|
@@ -33,13 +33,18 @@ extern "C" {
|
|
33
33
|
size_t ZSTDv05_decompress( void* dst, size_t dstCapacity,
|
34
34
|
const void* src, size_t compressedSize);
|
35
35
|
|
36
|
-
/**
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
36
|
+
/**
|
37
|
+
ZSTDv05_findFrameSizeInfoLegacy() : get the source length and decompressed bound of a ZSTD frame compliant with v0.5.x format
|
38
|
+
srcSize : The size of the 'src' buffer, at least as large as the frame pointed to by 'src'
|
39
|
+
cSize (output parameter) : the number of bytes that would be read to decompress this frame
|
40
|
+
or an error code if it fails (which can be tested using ZSTDv01_isError())
|
41
|
+
dBound (output parameter) : an upper-bound for the decompressed size of the data in the frame
|
42
|
+
or ZSTD_CONTENTSIZE_ERROR if an error occurs
|
43
|
+
|
44
|
+
note : assumes `cSize` and `dBound` are _not_ NULL.
|
45
|
+
*/
|
46
|
+
void ZSTDv05_findFrameSizeInfoLegacy(const void *src, size_t srcSize,
|
47
|
+
size_t* cSize, unsigned long long* dBound);
|
43
48
|
|
44
49
|
/* *************************************
|
45
50
|
* Helper functions
|
@@ -506,6 +506,8 @@ typedef enum { bt_compressed, bt_raw, bt_rle, bt_end } blockType_t;
|
|
506
506
|
#define FSEv06_ENCODING_STATIC 2
|
507
507
|
#define FSEv06_ENCODING_DYNAMIC 3
|
508
508
|
|
509
|
+
#define ZSTD_CONTENTSIZE_ERROR (0ULL - 2)
|
510
|
+
|
509
511
|
static const U32 LL_bits[MaxLL+1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
510
512
|
1, 1, 1, 1, 2, 2, 3, 3, 4, 6, 7, 8, 9,10,11,12,
|
511
513
|
13,14,15,16 };
|
@@ -3406,7 +3408,7 @@ static size_t ZSTDv06_execSequence(BYTE* op,
|
|
3406
3408
|
if (sequence.offset < 8) {
|
3407
3409
|
/* close range match, overlap */
|
3408
3410
|
static const U32 dec32table[] = { 0, 1, 2, 1, 4, 4, 4, 4 }; /* added */
|
3409
|
-
static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /*
|
3411
|
+
static const int dec64table[] = { 8, 8, 8, 7, 8, 9,10,11 }; /* subtracted */
|
3410
3412
|
int const sub2 = dec64table[sequence.offset];
|
3411
3413
|
op[0] = match[0];
|
3412
3414
|
op[1] = match[1];
|
@@ -3654,36 +3656,62 @@ size_t ZSTDv06_decompress(void* dst, size_t dstCapacity, const void* src, size_t
|
|
3654
3656
|
#endif
|
3655
3657
|
}
|
3656
3658
|
|
3657
|
-
|
3659
|
+
/* ZSTD_errorFrameSizeInfoLegacy() :
|
3660
|
+
assumes `cSize` and `dBound` are _not_ NULL */
|
3661
|
+
static void ZSTD_errorFrameSizeInfoLegacy(size_t* cSize, unsigned long long* dBound, size_t ret)
|
3662
|
+
{
|
3663
|
+
*cSize = ret;
|
3664
|
+
*dBound = ZSTD_CONTENTSIZE_ERROR;
|
3665
|
+
}
|
3666
|
+
|
3667
|
+
void ZSTDv06_findFrameSizeInfoLegacy(const void *src, size_t srcSize, size_t* cSize, unsigned long long* dBound)
|
3658
3668
|
{
|
3659
3669
|
const BYTE* ip = (const BYTE*)src;
|
3660
3670
|
size_t remainingSize = srcSize;
|
3671
|
+
size_t nbBlocks = 0;
|
3661
3672
|
blockProperties_t blockProperties = { bt_compressed, 0 };
|
3662
3673
|
|
3663
3674
|
/* Frame Header */
|
3664
3675
|
{ size_t const frameHeaderSize = ZSTDv06_frameHeaderSize(src, ZSTDv06_frameHeaderSize_min);
|
3665
|
-
if (ZSTDv06_isError(frameHeaderSize))
|
3666
|
-
|
3667
|
-
|
3676
|
+
if (ZSTDv06_isError(frameHeaderSize)) {
|
3677
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, frameHeaderSize);
|
3678
|
+
return;
|
3679
|
+
}
|
3680
|
+
if (MEM_readLE32(src) != ZSTDv06_MAGICNUMBER) {
|
3681
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(prefix_unknown));
|
3682
|
+
return;
|
3683
|
+
}
|
3684
|
+
if (srcSize < frameHeaderSize+ZSTDv06_blockHeaderSize) {
|
3685
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
3686
|
+
return;
|
3687
|
+
}
|
3668
3688
|
ip += frameHeaderSize; remainingSize -= frameHeaderSize;
|
3669
3689
|
}
|
3670
3690
|
|
3671
3691
|
/* Loop on each block */
|
3672
3692
|
while (1) {
|
3673
3693
|
size_t const cBlockSize = ZSTDv06_getcBlockSize(ip, remainingSize, &blockProperties);
|
3674
|
-
if (ZSTDv06_isError(cBlockSize))
|
3694
|
+
if (ZSTDv06_isError(cBlockSize)) {
|
3695
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, cBlockSize);
|
3696
|
+
return;
|
3697
|
+
}
|
3675
3698
|
|
3676
3699
|
ip += ZSTDv06_blockHeaderSize;
|
3677
3700
|
remainingSize -= ZSTDv06_blockHeaderSize;
|
3678
|
-
if (cBlockSize > remainingSize)
|
3701
|
+
if (cBlockSize > remainingSize) {
|
3702
|
+
ZSTD_errorFrameSizeInfoLegacy(cSize, dBound, ERROR(srcSize_wrong));
|
3703
|
+
return;
|
3704
|
+
}
|
3679
3705
|
|
3680
3706
|
if (cBlockSize == 0) break; /* bt_end */
|
3681
3707
|
|
3682
3708
|
ip += cBlockSize;
|
3683
3709
|
remainingSize -= cBlockSize;
|
3710
|
+
nbBlocks++;
|
3684
3711
|
}
|
3685
3712
|
|
3686
|
-
|
3713
|
+
*cSize = ip - (const BYTE*)src;
|
3714
|
+
*dBound = nbBlocks * ZSTDv06_BLOCKSIZE_MAX;
|
3687
3715
|
}
|
3688
3716
|
|
3689
3717
|
/*_******************************
|