Coverage Report

Created: 2026-11-13 07:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/work/libzstd-src/lib/legacy/zstd_legacy.h
Line
Count
Source
1
/*
2
 * Copyright (c) Meta Platforms, Inc. and affiliates.
3
 * All rights reserved.
4
 *
5
 * This source code is licensed under both the BSD-style license (found in the
6
 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7
 * in the COPYING file in the root directory of this source tree).
8
 * You may select, at your option, one of the above-listed licenses.
9
 */
10
11
#ifndef ZSTD_LEGACY_H
12
#define ZSTD_LEGACY_H
13
14
#if defined (__cplusplus)
15
extern "C" {
16
#endif
17
18
/* *************************************
19
*  Includes
20
***************************************/
21
#include "../common/mem.h"            /* MEM_STATIC */
22
#include "../common/error_private.h"  /* ERROR */
23
#include "../common/zstd_internal.h"  /* ZSTD_inBuffer, ZSTD_outBuffer, ZSTD_frameSizeInfo */
24
25
#if !defined (ZSTD_LEGACY_SUPPORT) || (ZSTD_LEGACY_SUPPORT == 0)
26
#  undef ZSTD_LEGACY_SUPPORT
27
#  define ZSTD_LEGACY_SUPPORT 8
28
#endif
29
30
#if (ZSTD_LEGACY_SUPPORT <= 1)
31
#  include "zstd_v01.h"
32
#endif
33
#if (ZSTD_LEGACY_SUPPORT <= 2)
34
#  include "zstd_v02.h"
35
#endif
36
#if (ZSTD_LEGACY_SUPPORT <= 3)
37
#  include "zstd_v03.h"
38
#endif
39
#if (ZSTD_LEGACY_SUPPORT <= 4)
40
#  include "zstd_v04.h"
41
#endif
42
#if (ZSTD_LEGACY_SUPPORT <= 5)
43
#  include "zstd_v05.h"
44
#endif
45
#if (ZSTD_LEGACY_SUPPORT <= 6)
46
#  include "zstd_v06.h"
47
#endif
48
#if (ZSTD_LEGACY_SUPPORT <= 7)
49
#  include "zstd_v07.h"
50
#endif
51
52
/** ZSTD_isLegacy() :
53
    @return : > 0 if supported by legacy decoder. 0 otherwise.
54
              return value is the version.
55
*/
56
MEM_STATIC unsigned ZSTD_isLegacy(const void* src, size_t srcSize)
57
75.3k
{
58
75.3k
    U32 magicNumberLE;
59
75.3k
    if (srcSize<4) return 0;
60
75.2k
    magicNumberLE = MEM_readLE32(src);
61
75.2k
    switch(magicNumberLE)
62
75.2k
    {
63
#if (ZSTD_LEGACY_SUPPORT <= 1)
64
        case ZSTDv01_magicNumberLE:return 1;
65
#endif
66
#if (ZSTD_LEGACY_SUPPORT <= 2)
67
        case ZSTDv02_magicNumber : return 2;
68
#endif
69
#if (ZSTD_LEGACY_SUPPORT <= 3)
70
        case ZSTDv03_magicNumber : return 3;
71
#endif
72
#if (ZSTD_LEGACY_SUPPORT <= 4)
73
        case ZSTDv04_magicNumber : return 4;
74
#endif
75
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
76
9.36k
        case ZSTDv05_MAGICNUMBER : return 5;
77
0
#endif
78
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
79
8.76k
        case ZSTDv06_MAGICNUMBER : return 6;
80
0
#endif
81
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
82
11.6k
        case ZSTDv07_MAGICNUMBER : return 7;
83
0
#endif
84
45.4k
        default : return 0;
85
75.2k
    }
86
75.2k
}
zstd_decompress.c:ZSTD_isLegacy
Line
Count
Source
57
75.3k
{
58
75.3k
    U32 magicNumberLE;
59
75.3k
    if (srcSize<4) return 0;
60
75.2k
    magicNumberLE = MEM_readLE32(src);
61
75.2k
    switch(magicNumberLE)
62
75.2k
    {
63
#if (ZSTD_LEGACY_SUPPORT <= 1)
64
        case ZSTDv01_magicNumberLE:return 1;
65
#endif
66
#if (ZSTD_LEGACY_SUPPORT <= 2)
67
        case ZSTDv02_magicNumber : return 2;
68
#endif
69
#if (ZSTD_LEGACY_SUPPORT <= 3)
70
        case ZSTDv03_magicNumber : return 3;
71
#endif
72
#if (ZSTD_LEGACY_SUPPORT <= 4)
73
        case ZSTDv04_magicNumber : return 4;
74
#endif
75
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
76
9.36k
        case ZSTDv05_MAGICNUMBER : return 5;
77
0
#endif
78
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
79
8.76k
        case ZSTDv06_MAGICNUMBER : return 6;
80
0
#endif
81
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
82
11.6k
        case ZSTDv07_MAGICNUMBER : return 7;
83
0
#endif
84
45.4k
        default : return 0;
85
75.2k
    }
86
75.2k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_isLegacy
87
88
89
MEM_STATIC unsigned long long ZSTD_getDecompressedSize_legacy(const void* src, size_t srcSize)
90
1.15k
{
91
1.15k
    U32 const version = ZSTD_isLegacy(src, srcSize);
92
1.15k
    if (version < 5) return 0;  /* no decompressed size in frame header, or not a legacy format */
93
1.15k
#if (ZSTD_LEGACY_SUPPORT <= 5)
94
1.15k
    if (version==5) {
95
437
        ZSTDv05_parameters fParams;
96
437
        size_t const frResult = ZSTDv05_getFrameParams(&fParams, src, srcSize);
97
437
        if (frResult != 0) return 0;
98
437
        return fParams.srcSize;
99
437
    }
100
718
#endif
101
718
#if (ZSTD_LEGACY_SUPPORT <= 6)
102
718
    if (version==6) {
103
417
        ZSTDv06_frameParams fParams;
104
417
        size_t const frResult = ZSTDv06_getFrameParams(&fParams, src, srcSize);
105
417
        if (frResult != 0) return 0;
106
417
        return fParams.frameContentSize;
107
417
    }
108
301
#endif
109
301
#if (ZSTD_LEGACY_SUPPORT <= 7)
110
301
    if (version==7) {
111
301
        ZSTDv07_frameParams fParams;
112
301
        size_t const frResult = ZSTDv07_getFrameParams(&fParams, src, srcSize);
113
301
        if (frResult != 0) return 0;
114
301
        return fParams.frameContentSize;
115
301
    }
116
0
#endif
117
0
    return 0;   /* should not be possible */
118
301
}
zstd_decompress.c:ZSTD_getDecompressedSize_legacy
Line
Count
Source
90
1.15k
{
91
1.15k
    U32 const version = ZSTD_isLegacy(src, srcSize);
92
1.15k
    if (version < 5) return 0;  /* no decompressed size in frame header, or not a legacy format */
93
1.15k
#if (ZSTD_LEGACY_SUPPORT <= 5)
94
1.15k
    if (version==5) {
95
437
        ZSTDv05_parameters fParams;
96
437
        size_t const frResult = ZSTDv05_getFrameParams(&fParams, src, srcSize);
97
437
        if (frResult != 0) return 0;
98
437
        return fParams.srcSize;
99
437
    }
100
718
#endif
101
718
#if (ZSTD_LEGACY_SUPPORT <= 6)
102
718
    if (version==6) {
103
417
        ZSTDv06_frameParams fParams;
104
417
        size_t const frResult = ZSTDv06_getFrameParams(&fParams, src, srcSize);
105
417
        if (frResult != 0) return 0;
106
417
        return fParams.frameContentSize;
107
417
    }
108
301
#endif
109
301
#if (ZSTD_LEGACY_SUPPORT <= 7)
110
301
    if (version==7) {
111
301
        ZSTDv07_frameParams fParams;
112
301
        size_t const frResult = ZSTDv07_getFrameParams(&fParams, src, srcSize);
113
301
        if (frResult != 0) return 0;
114
301
        return fParams.frameContentSize;
115
301
    }
116
0
#endif
117
0
    return 0;   /* should not be possible */
118
301
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_getDecompressedSize_legacy
119
120
121
MEM_STATIC size_t ZSTD_decompressLegacy(
122
                     void* dst, size_t dstCapacity,
123
               const void* src, size_t compressedSize,
124
               const void* dict,size_t dictSize)
125
8.44k
{
126
8.44k
    U32 const version = ZSTD_isLegacy(src, compressedSize);
127
8.44k
    char x;
128
    /* Avoid passing NULL to legacy decoding. */
129
8.44k
    if (dst == NULL) {
130
2.34k
        assert(dstCapacity == 0);
131
2.34k
        dst = &x;
132
2.34k
    }
133
8.44k
    if (src == NULL) {
134
0
        assert(compressedSize == 0);
135
0
        src = &x;
136
0
    }
137
8.44k
    if (dict == NULL) {
138
8.44k
        assert(dictSize == 0);
139
8.44k
        dict = &x;
140
8.44k
    }
141
8.44k
    (void)dst; (void)dstCapacity; (void)dict; (void)dictSize;  /* unused when ZSTD_LEGACY_SUPPORT >= 8 */
142
8.44k
    switch(version)
143
8.44k
    {
144
#if (ZSTD_LEGACY_SUPPORT <= 1)
145
        case 1 :
146
            return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize);
147
#endif
148
#if (ZSTD_LEGACY_SUPPORT <= 2)
149
        case 2 :
150
            return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize);
151
#endif
152
#if (ZSTD_LEGACY_SUPPORT <= 3)
153
        case 3 :
154
            return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize);
155
#endif
156
#if (ZSTD_LEGACY_SUPPORT <= 4)
157
        case 4 :
158
            return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize);
159
#endif
160
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
161
2.63k
        case 5 :
162
2.63k
            {   size_t result;
163
2.63k
                ZSTDv05_DCtx* const zd = ZSTDv05_createDCtx();
164
2.63k
                if (zd==NULL) return ERROR(memory_allocation);
165
2.63k
                result = ZSTDv05_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
166
2.63k
                ZSTDv05_freeDCtx(zd);
167
2.63k
                return result;
168
2.63k
            }
169
0
#endif
170
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
171
2.39k
        case 6 :
172
2.39k
            {   size_t result;
173
2.39k
                ZSTDv06_DCtx* const zd = ZSTDv06_createDCtx();
174
2.39k
                if (zd==NULL) return ERROR(memory_allocation);
175
2.39k
                result = ZSTDv06_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
176
2.39k
                ZSTDv06_freeDCtx(zd);
177
2.39k
                return result;
178
2.39k
            }
179
0
#endif
180
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
181
3.40k
        case 7 :
182
3.40k
            {   size_t result;
183
3.40k
                ZSTDv07_DCtx* const zd = ZSTDv07_createDCtx();
184
3.40k
                if (zd==NULL) return ERROR(memory_allocation);
185
3.40k
                result = ZSTDv07_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
186
3.40k
                ZSTDv07_freeDCtx(zd);
187
3.40k
                return result;
188
3.40k
            }
189
0
#endif
190
0
        default :
191
0
            return ERROR(prefix_unknown);
192
8.44k
    }
193
8.44k
}
zstd_decompress.c:ZSTD_decompressLegacy
Line
Count
Source
125
8.44k
{
126
8.44k
    U32 const version = ZSTD_isLegacy(src, compressedSize);
127
8.44k
    char x;
128
    /* Avoid passing NULL to legacy decoding. */
129
8.44k
    if (dst == NULL) {
130
2.34k
        assert(dstCapacity == 0);
131
2.34k
        dst = &x;
132
2.34k
    }
133
8.44k
    if (src == NULL) {
134
0
        assert(compressedSize == 0);
135
0
        src = &x;
136
0
    }
137
8.44k
    if (dict == NULL) {
138
8.44k
        assert(dictSize == 0);
139
8.44k
        dict = &x;
140
8.44k
    }
141
8.44k
    (void)dst; (void)dstCapacity; (void)dict; (void)dictSize;  /* unused when ZSTD_LEGACY_SUPPORT >= 8 */
142
8.44k
    switch(version)
143
8.44k
    {
144
#if (ZSTD_LEGACY_SUPPORT <= 1)
145
        case 1 :
146
            return ZSTDv01_decompress(dst, dstCapacity, src, compressedSize);
147
#endif
148
#if (ZSTD_LEGACY_SUPPORT <= 2)
149
        case 2 :
150
            return ZSTDv02_decompress(dst, dstCapacity, src, compressedSize);
151
#endif
152
#if (ZSTD_LEGACY_SUPPORT <= 3)
153
        case 3 :
154
            return ZSTDv03_decompress(dst, dstCapacity, src, compressedSize);
155
#endif
156
#if (ZSTD_LEGACY_SUPPORT <= 4)
157
        case 4 :
158
            return ZSTDv04_decompress(dst, dstCapacity, src, compressedSize);
159
#endif
160
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
161
2.63k
        case 5 :
162
2.63k
            {   size_t result;
163
2.63k
                ZSTDv05_DCtx* const zd = ZSTDv05_createDCtx();
164
2.63k
                if (zd==NULL) return ERROR(memory_allocation);
165
2.63k
                result = ZSTDv05_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
166
2.63k
                ZSTDv05_freeDCtx(zd);
167
2.63k
                return result;
168
2.63k
            }
169
0
#endif
170
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
171
2.39k
        case 6 :
172
2.39k
            {   size_t result;
173
2.39k
                ZSTDv06_DCtx* const zd = ZSTDv06_createDCtx();
174
2.39k
                if (zd==NULL) return ERROR(memory_allocation);
175
2.39k
                result = ZSTDv06_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
176
2.39k
                ZSTDv06_freeDCtx(zd);
177
2.39k
                return result;
178
2.39k
            }
179
0
#endif
180
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
181
3.40k
        case 7 :
182
3.40k
            {   size_t result;
183
3.40k
                ZSTDv07_DCtx* const zd = ZSTDv07_createDCtx();
184
3.40k
                if (zd==NULL) return ERROR(memory_allocation);
185
3.40k
                result = ZSTDv07_decompress_usingDict(zd, dst, dstCapacity, src, compressedSize, dict, dictSize);
186
3.40k
                ZSTDv07_freeDCtx(zd);
187
3.40k
                return result;
188
3.40k
            }
189
0
#endif
190
0
        default :
191
0
            return ERROR(prefix_unknown);
192
8.44k
    }
193
8.44k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_decompressLegacy
194
195
MEM_STATIC ZSTD_frameSizeInfo ZSTD_findFrameSizeInfoLegacy(const void *src, size_t srcSize)
196
8.60k
{
197
8.60k
    ZSTD_frameSizeInfo frameSizeInfo;
198
8.60k
    U32 const version = ZSTD_isLegacy(src, srcSize);
199
8.60k
    switch(version)
200
8.60k
    {
201
#if (ZSTD_LEGACY_SUPPORT <= 1)
202
        case 1 :
203
            ZSTDv01_findFrameSizeInfoLegacy(src, srcSize,
204
                &frameSizeInfo.compressedSize,
205
                &frameSizeInfo.decompressedBound);
206
            break;
207
#endif
208
#if (ZSTD_LEGACY_SUPPORT <= 2)
209
        case 2 :
210
            ZSTDv02_findFrameSizeInfoLegacy(src, srcSize,
211
                &frameSizeInfo.compressedSize,
212
                &frameSizeInfo.decompressedBound);
213
            break;
214
#endif
215
#if (ZSTD_LEGACY_SUPPORT <= 3)
216
        case 3 :
217
            ZSTDv03_findFrameSizeInfoLegacy(src, srcSize,
218
                &frameSizeInfo.compressedSize,
219
                &frameSizeInfo.decompressedBound);
220
            break;
221
#endif
222
#if (ZSTD_LEGACY_SUPPORT <= 4)
223
        case 4 :
224
            ZSTDv04_findFrameSizeInfoLegacy(src, srcSize,
225
                &frameSizeInfo.compressedSize,
226
                &frameSizeInfo.decompressedBound);
227
            break;
228
#endif
229
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
230
2.68k
        case 5 :
231
2.68k
            ZSTDv05_findFrameSizeInfoLegacy(src, srcSize,
232
2.68k
                &frameSizeInfo.compressedSize,
233
2.68k
                &frameSizeInfo.decompressedBound);
234
2.68k
            break;
235
0
#endif
236
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
237
2.45k
        case 6 :
238
2.45k
            ZSTDv06_findFrameSizeInfoLegacy(src, srcSize,
239
2.45k
                &frameSizeInfo.compressedSize,
240
2.45k
                &frameSizeInfo.decompressedBound);
241
2.45k
            break;
242
0
#endif
243
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
244
3.45k
        case 7 :
245
3.45k
            ZSTDv07_findFrameSizeInfoLegacy(src, srcSize,
246
3.45k
                &frameSizeInfo.compressedSize,
247
3.45k
                &frameSizeInfo.decompressedBound);
248
3.45k
            break;
249
0
#endif
250
0
        default :
251
0
            frameSizeInfo.compressedSize = ERROR(prefix_unknown);
252
0
            frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
253
0
            break;
254
8.60k
    }
255
8.60k
    if (!ZSTD_isError(frameSizeInfo.compressedSize) && frameSizeInfo.compressedSize > srcSize) {
256
0
        frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
257
0
        frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
258
0
    }
259
    /* In all cases, decompressedBound == nbBlocks * ZSTD_BLOCKSIZE_MAX.
260
     * So we can compute nbBlocks without having to change every function.
261
     */
262
8.60k
    if (frameSizeInfo.decompressedBound != ZSTD_CONTENTSIZE_ERROR) {
263
8.49k
        assert((frameSizeInfo.decompressedBound & (ZSTD_BLOCKSIZE_MAX - 1)) == 0);
264
8.49k
        frameSizeInfo.nbBlocks = (size_t)(frameSizeInfo.decompressedBound / ZSTD_BLOCKSIZE_MAX);
265
8.49k
    }
266
8.60k
    return frameSizeInfo;
267
8.60k
}
zstd_decompress.c:ZSTD_findFrameSizeInfoLegacy
Line
Count
Source
196
8.60k
{
197
8.60k
    ZSTD_frameSizeInfo frameSizeInfo;
198
8.60k
    U32 const version = ZSTD_isLegacy(src, srcSize);
199
8.60k
    switch(version)
200
8.60k
    {
201
#if (ZSTD_LEGACY_SUPPORT <= 1)
202
        case 1 :
203
            ZSTDv01_findFrameSizeInfoLegacy(src, srcSize,
204
                &frameSizeInfo.compressedSize,
205
                &frameSizeInfo.decompressedBound);
206
            break;
207
#endif
208
#if (ZSTD_LEGACY_SUPPORT <= 2)
209
        case 2 :
210
            ZSTDv02_findFrameSizeInfoLegacy(src, srcSize,
211
                &frameSizeInfo.compressedSize,
212
                &frameSizeInfo.decompressedBound);
213
            break;
214
#endif
215
#if (ZSTD_LEGACY_SUPPORT <= 3)
216
        case 3 :
217
            ZSTDv03_findFrameSizeInfoLegacy(src, srcSize,
218
                &frameSizeInfo.compressedSize,
219
                &frameSizeInfo.decompressedBound);
220
            break;
221
#endif
222
#if (ZSTD_LEGACY_SUPPORT <= 4)
223
        case 4 :
224
            ZSTDv04_findFrameSizeInfoLegacy(src, srcSize,
225
                &frameSizeInfo.compressedSize,
226
                &frameSizeInfo.decompressedBound);
227
            break;
228
#endif
229
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
230
2.68k
        case 5 :
231
2.68k
            ZSTDv05_findFrameSizeInfoLegacy(src, srcSize,
232
2.68k
                &frameSizeInfo.compressedSize,
233
2.68k
                &frameSizeInfo.decompressedBound);
234
2.68k
            break;
235
0
#endif
236
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
237
2.45k
        case 6 :
238
2.45k
            ZSTDv06_findFrameSizeInfoLegacy(src, srcSize,
239
2.45k
                &frameSizeInfo.compressedSize,
240
2.45k
                &frameSizeInfo.decompressedBound);
241
2.45k
            break;
242
0
#endif
243
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
244
3.45k
        case 7 :
245
3.45k
            ZSTDv07_findFrameSizeInfoLegacy(src, srcSize,
246
3.45k
                &frameSizeInfo.compressedSize,
247
3.45k
                &frameSizeInfo.decompressedBound);
248
3.45k
            break;
249
0
#endif
250
0
        default :
251
0
            frameSizeInfo.compressedSize = ERROR(prefix_unknown);
252
0
            frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
253
0
            break;
254
8.60k
    }
255
8.60k
    if (!ZSTD_isError(frameSizeInfo.compressedSize) && frameSizeInfo.compressedSize > srcSize) {
256
0
        frameSizeInfo.compressedSize = ERROR(srcSize_wrong);
257
0
        frameSizeInfo.decompressedBound = ZSTD_CONTENTSIZE_ERROR;
258
0
    }
259
    /* In all cases, decompressedBound == nbBlocks * ZSTD_BLOCKSIZE_MAX.
260
     * So we can compute nbBlocks without having to change every function.
261
     */
262
8.60k
    if (frameSizeInfo.decompressedBound != ZSTD_CONTENTSIZE_ERROR) {
263
8.49k
        assert((frameSizeInfo.decompressedBound & (ZSTD_BLOCKSIZE_MAX - 1)) == 0);
264
8.49k
        frameSizeInfo.nbBlocks = (size_t)(frameSizeInfo.decompressedBound / ZSTD_BLOCKSIZE_MAX);
265
8.49k
    }
266
8.60k
    return frameSizeInfo;
267
8.60k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_findFrameSizeInfoLegacy
268
269
MEM_STATIC size_t ZSTD_findFrameCompressedSizeLegacy(const void *src, size_t srcSize)
270
8.54k
{
271
8.54k
    ZSTD_frameSizeInfo frameSizeInfo = ZSTD_findFrameSizeInfoLegacy(src, srcSize);
272
8.54k
    return frameSizeInfo.compressedSize;
273
8.54k
}
zstd_decompress.c:ZSTD_findFrameCompressedSizeLegacy
Line
Count
Source
270
8.54k
{
271
8.54k
    ZSTD_frameSizeInfo frameSizeInfo = ZSTD_findFrameSizeInfoLegacy(src, srcSize);
272
8.54k
    return frameSizeInfo.compressedSize;
273
8.54k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_findFrameCompressedSizeLegacy
274
275
MEM_STATIC size_t ZSTD_freeLegacyStreamContext(void* legacyContext, U32 version)
276
3.52k
{
277
3.52k
    switch(version)
278
3.52k
    {
279
1.76k
        default :
280
1.76k
        case 1 :
281
1.76k
        case 2 :
282
1.76k
        case 3 :
283
1.76k
            (void)legacyContext;
284
1.76k
            return ERROR(version_unsupported);
285
#if (ZSTD_LEGACY_SUPPORT <= 4)
286
        case 4 : return ZBUFFv04_freeDCtx((ZBUFFv04_DCtx*)legacyContext);
287
#endif
288
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
289
481
        case 5 : return ZBUFFv05_freeDCtx((ZBUFFv05_DCtx*)legacyContext);
290
0
#endif
291
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
292
581
        case 6 : return ZBUFFv06_freeDCtx((ZBUFFv06_DCtx*)legacyContext);
293
0
#endif
294
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
295
704
        case 7 : return ZBUFFv07_freeDCtx((ZBUFFv07_DCtx*)legacyContext);
296
3.52k
#endif
297
3.52k
    }
298
3.52k
}
zstd_decompress.c:ZSTD_freeLegacyStreamContext
Line
Count
Source
276
3.52k
{
277
3.52k
    switch(version)
278
3.52k
    {
279
1.76k
        default :
280
1.76k
        case 1 :
281
1.76k
        case 2 :
282
1.76k
        case 3 :
283
1.76k
            (void)legacyContext;
284
1.76k
            return ERROR(version_unsupported);
285
#if (ZSTD_LEGACY_SUPPORT <= 4)
286
        case 4 : return ZBUFFv04_freeDCtx((ZBUFFv04_DCtx*)legacyContext);
287
#endif
288
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
289
481
        case 5 : return ZBUFFv05_freeDCtx((ZBUFFv05_DCtx*)legacyContext);
290
0
#endif
291
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
292
581
        case 6 : return ZBUFFv06_freeDCtx((ZBUFFv06_DCtx*)legacyContext);
293
0
#endif
294
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
295
704
        case 7 : return ZBUFFv07_freeDCtx((ZBUFFv07_DCtx*)legacyContext);
296
3.52k
#endif
297
3.52k
    }
298
3.52k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_freeLegacyStreamContext
299
300
301
MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U32 newVersion,
302
                                        const void* dict, size_t dictSize)
303
1.86k
{
304
1.86k
    char x;
305
    /* Avoid passing NULL to legacy decoding. */
306
1.86k
    if (dict == NULL) {
307
1.86k
        assert(dictSize == 0);
308
1.86k
        dict = &x;
309
1.86k
    }
310
1.86k
    DEBUGLOG(5, "ZSTD_initLegacyStream for v0.%u", newVersion);
311
1.86k
    if (prevVersion != newVersion) ZSTD_freeLegacyStreamContext(*legacyContext, prevVersion);
312
1.86k
    switch(newVersion)
313
1.86k
    {
314
0
        default :
315
0
        case 1 :
316
0
        case 2 :
317
0
        case 3 :
318
0
            (void)dict; (void)dictSize;
319
0
            return 0;
320
#if (ZSTD_LEGACY_SUPPORT <= 4)
321
        case 4 :
322
        {
323
            ZBUFFv04_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv04_createDCtx() : (ZBUFFv04_DCtx*)*legacyContext;
324
            if (dctx==NULL) return ERROR(memory_allocation);
325
            ZBUFFv04_decompressInit(dctx);
326
            ZBUFFv04_decompressWithDictionary(dctx, dict, dictSize);
327
            *legacyContext = dctx;
328
            return 0;
329
        }
330
#endif
331
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
332
483
        case 5 :
333
483
        {
334
483
            ZBUFFv05_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv05_createDCtx() : (ZBUFFv05_DCtx*)*legacyContext;
335
483
            if (dctx==NULL) return ERROR(memory_allocation);
336
483
            ZBUFFv05_decompressInitDictionary(dctx, dict, dictSize);
337
483
            *legacyContext = dctx;
338
483
            return 0;
339
483
        }
340
0
#endif
341
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
342
618
        case 6 :
343
618
        {
344
618
            ZBUFFv06_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv06_createDCtx() : (ZBUFFv06_DCtx*)*legacyContext;
345
618
            if (dctx==NULL) return ERROR(memory_allocation);
346
618
            ZBUFFv06_decompressInitDictionary(dctx, dict, dictSize);
347
618
            *legacyContext = dctx;
348
618
            return 0;
349
618
        }
350
0
#endif
351
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
352
768
        case 7 :
353
768
        {
354
768
            ZBUFFv07_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv07_createDCtx() : (ZBUFFv07_DCtx*)*legacyContext;
355
768
            if (dctx==NULL) return ERROR(memory_allocation);
356
768
            ZBUFFv07_decompressInitDictionary(dctx, dict, dictSize);
357
768
            *legacyContext = dctx;
358
768
            return 0;
359
768
        }
360
1.86k
#endif
361
1.86k
    }
362
1.86k
}
zstd_decompress.c:ZSTD_initLegacyStream
Line
Count
Source
303
1.86k
{
304
1.86k
    char x;
305
    /* Avoid passing NULL to legacy decoding. */
306
1.86k
    if (dict == NULL) {
307
1.86k
        assert(dictSize == 0);
308
1.86k
        dict = &x;
309
1.86k
    }
310
1.86k
    DEBUGLOG(5, "ZSTD_initLegacyStream for v0.%u", newVersion);
311
1.86k
    if (prevVersion != newVersion) ZSTD_freeLegacyStreamContext(*legacyContext, prevVersion);
312
1.86k
    switch(newVersion)
313
1.86k
    {
314
0
        default :
315
0
        case 1 :
316
0
        case 2 :
317
0
        case 3 :
318
0
            (void)dict; (void)dictSize;
319
0
            return 0;
320
#if (ZSTD_LEGACY_SUPPORT <= 4)
321
        case 4 :
322
        {
323
            ZBUFFv04_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv04_createDCtx() : (ZBUFFv04_DCtx*)*legacyContext;
324
            if (dctx==NULL) return ERROR(memory_allocation);
325
            ZBUFFv04_decompressInit(dctx);
326
            ZBUFFv04_decompressWithDictionary(dctx, dict, dictSize);
327
            *legacyContext = dctx;
328
            return 0;
329
        }
330
#endif
331
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
332
483
        case 5 :
333
483
        {
334
483
            ZBUFFv05_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv05_createDCtx() : (ZBUFFv05_DCtx*)*legacyContext;
335
483
            if (dctx==NULL) return ERROR(memory_allocation);
336
483
            ZBUFFv05_decompressInitDictionary(dctx, dict, dictSize);
337
483
            *legacyContext = dctx;
338
483
            return 0;
339
483
        }
340
0
#endif
341
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
342
618
        case 6 :
343
618
        {
344
618
            ZBUFFv06_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv06_createDCtx() : (ZBUFFv06_DCtx*)*legacyContext;
345
618
            if (dctx==NULL) return ERROR(memory_allocation);
346
618
            ZBUFFv06_decompressInitDictionary(dctx, dict, dictSize);
347
618
            *legacyContext = dctx;
348
618
            return 0;
349
618
        }
350
0
#endif
351
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
352
768
        case 7 :
353
768
        {
354
768
            ZBUFFv07_DCtx* dctx = (prevVersion != newVersion) ? ZBUFFv07_createDCtx() : (ZBUFFv07_DCtx*)*legacyContext;
355
768
            if (dctx==NULL) return ERROR(memory_allocation);
356
768
            ZBUFFv07_decompressInitDictionary(dctx, dict, dictSize);
357
768
            *legacyContext = dctx;
358
768
            return 0;
359
768
        }
360
1.86k
#endif
361
1.86k
    }
362
1.86k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_initLegacyStream
363
364
365
366
MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version,
367
                                              ZSTD_outBuffer* output, ZSTD_inBuffer* input)
368
1.86k
{
369
1.86k
    static char x;
370
    /* Avoid passing NULL to legacy decoding. */
371
1.86k
    if (output->dst == NULL) {
372
0
        assert(output->size == 0);
373
0
        output->dst = &x;
374
0
    }
375
1.86k
    if (input->src == NULL) {
376
0
        assert(input->size == 0);
377
0
        input->src = &x;
378
0
    }
379
1.86k
    DEBUGLOG(5, "ZSTD_decompressLegacyStream for v0.%u", version);
380
1.86k
    switch(version)
381
1.86k
    {
382
0
        default :
383
0
        case 1 :
384
0
        case 2 :
385
0
        case 3 :
386
0
            (void)legacyContext; (void)output; (void)input;
387
0
            return ERROR(version_unsupported);
388
#if (ZSTD_LEGACY_SUPPORT <= 4)
389
        case 4 :
390
            {
391
                ZBUFFv04_DCtx* dctx = (ZBUFFv04_DCtx*) legacyContext;
392
                const void* src = (const char*)input->src + input->pos;
393
                size_t readSize = input->size - input->pos;
394
                void* dst = (char*)output->dst + output->pos;
395
                size_t decodedSize = output->size - output->pos;
396
                size_t const hintSize = ZBUFFv04_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
397
                output->pos += decodedSize;
398
                input->pos += readSize;
399
                return hintSize;
400
            }
401
#endif
402
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
403
483
        case 5 :
404
483
            {
405
483
                ZBUFFv05_DCtx* dctx = (ZBUFFv05_DCtx*) legacyContext;
406
483
                const void* src = (const char*)input->src + input->pos;
407
483
                size_t readSize = input->size - input->pos;
408
483
                void* dst = (char*)output->dst + output->pos;
409
483
                size_t decodedSize = output->size - output->pos;
410
483
                size_t const hintSize = ZBUFFv05_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
411
483
                output->pos += decodedSize;
412
483
                input->pos += readSize;
413
483
                return hintSize;
414
0
            }
415
0
#endif
416
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
417
618
        case 6 :
418
618
            {
419
618
                ZBUFFv06_DCtx* dctx = (ZBUFFv06_DCtx*) legacyContext;
420
618
                const void* src = (const char*)input->src + input->pos;
421
618
                size_t readSize = input->size - input->pos;
422
618
                void* dst = (char*)output->dst + output->pos;
423
618
                size_t decodedSize = output->size - output->pos;
424
618
                size_t const hintSize = ZBUFFv06_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
425
618
                output->pos += decodedSize;
426
618
                input->pos += readSize;
427
618
                return hintSize;
428
0
            }
429
0
#endif
430
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
431
768
        case 7 :
432
768
            {
433
768
                ZBUFFv07_DCtx* dctx = (ZBUFFv07_DCtx*) legacyContext;
434
768
                const void* src = (const char*)input->src + input->pos;
435
768
                size_t readSize = input->size - input->pos;
436
768
                void* dst = (char*)output->dst + output->pos;
437
768
                size_t decodedSize = output->size - output->pos;
438
768
                size_t const hintSize = ZBUFFv07_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
439
768
                output->pos += decodedSize;
440
768
                input->pos += readSize;
441
768
                return hintSize;
442
0
            }
443
1.86k
#endif
444
1.86k
    }
445
1.86k
}
zstd_decompress.c:ZSTD_decompressLegacyStream
Line
Count
Source
368
1.86k
{
369
1.86k
    static char x;
370
    /* Avoid passing NULL to legacy decoding. */
371
1.86k
    if (output->dst == NULL) {
372
0
        assert(output->size == 0);
373
0
        output->dst = &x;
374
0
    }
375
1.86k
    if (input->src == NULL) {
376
0
        assert(input->size == 0);
377
0
        input->src = &x;
378
0
    }
379
1.86k
    DEBUGLOG(5, "ZSTD_decompressLegacyStream for v0.%u", version);
380
1.86k
    switch(version)
381
1.86k
    {
382
0
        default :
383
0
        case 1 :
384
0
        case 2 :
385
0
        case 3 :
386
0
            (void)legacyContext; (void)output; (void)input;
387
0
            return ERROR(version_unsupported);
388
#if (ZSTD_LEGACY_SUPPORT <= 4)
389
        case 4 :
390
            {
391
                ZBUFFv04_DCtx* dctx = (ZBUFFv04_DCtx*) legacyContext;
392
                const void* src = (const char*)input->src + input->pos;
393
                size_t readSize = input->size - input->pos;
394
                void* dst = (char*)output->dst + output->pos;
395
                size_t decodedSize = output->size - output->pos;
396
                size_t const hintSize = ZBUFFv04_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
397
                output->pos += decodedSize;
398
                input->pos += readSize;
399
                return hintSize;
400
            }
401
#endif
402
0
#if (ZSTD_LEGACY_SUPPORT <= 5)
403
483
        case 5 :
404
483
            {
405
483
                ZBUFFv05_DCtx* dctx = (ZBUFFv05_DCtx*) legacyContext;
406
483
                const void* src = (const char*)input->src + input->pos;
407
483
                size_t readSize = input->size - input->pos;
408
483
                void* dst = (char*)output->dst + output->pos;
409
483
                size_t decodedSize = output->size - output->pos;
410
483
                size_t const hintSize = ZBUFFv05_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
411
483
                output->pos += decodedSize;
412
483
                input->pos += readSize;
413
483
                return hintSize;
414
0
            }
415
0
#endif
416
0
#if (ZSTD_LEGACY_SUPPORT <= 6)
417
618
        case 6 :
418
618
            {
419
618
                ZBUFFv06_DCtx* dctx = (ZBUFFv06_DCtx*) legacyContext;
420
618
                const void* src = (const char*)input->src + input->pos;
421
618
                size_t readSize = input->size - input->pos;
422
618
                void* dst = (char*)output->dst + output->pos;
423
618
                size_t decodedSize = output->size - output->pos;
424
618
                size_t const hintSize = ZBUFFv06_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
425
618
                output->pos += decodedSize;
426
618
                input->pos += readSize;
427
618
                return hintSize;
428
0
            }
429
0
#endif
430
0
#if (ZSTD_LEGACY_SUPPORT <= 7)
431
768
        case 7 :
432
768
            {
433
768
                ZBUFFv07_DCtx* dctx = (ZBUFFv07_DCtx*) legacyContext;
434
768
                const void* src = (const char*)input->src + input->pos;
435
768
                size_t readSize = input->size - input->pos;
436
768
                void* dst = (char*)output->dst + output->pos;
437
768
                size_t decodedSize = output->size - output->pos;
438
768
                size_t const hintSize = ZBUFFv07_decompressContinue(dctx, dst, &decodedSize, src, &readSize);
439
768
                output->pos += decodedSize;
440
768
                input->pos += readSize;
441
768
                return hintSize;
442
0
            }
443
1.86k
#endif
444
1.86k
    }
445
1.86k
}
Unexecuted instantiation: zstd_ddict.c:ZSTD_decompressLegacyStream
446
447
448
#if defined (__cplusplus)
449
}
450
#endif
451
452
#endif   /* ZSTD_LEGACY_H */