multi_compress 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -3
- data/GET_STARTED.md +3 -3
- data/README.md +75 -66
- data/THIRD_PARTY_NOTICES.md +24 -0
- data/ext/multi_compress/brotli_dec_static_init.c +3 -0
- data/ext/multi_compress/brotli_enc_static_init.c +3 -0
- data/ext/multi_compress/extconf.rb +79 -3
- data/ext/multi_compress/multi_compress.c +199 -120
- data/ext/multi_compress/vendor/.vendored +2 -2
- data/ext/multi_compress/vendor/brotli/LICENSE +19 -0
- data/ext/multi_compress/vendor/brotli/c/common/constants.c +7 -7
- data/ext/multi_compress/vendor/brotli/c/common/constants.h +2 -5
- data/ext/multi_compress/vendor/brotli/c/common/context.c +2 -2
- data/ext/multi_compress/vendor/brotli/c/common/context.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.c +4 -5856
- data/ext/multi_compress/vendor/brotli/c/common/dictionary.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/dictionary_inc.h +5847 -0
- data/ext/multi_compress/vendor/brotli/c/common/platform.c +0 -4
- data/ext/multi_compress/vendor/brotli/c/common/platform.h +182 -43
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary.c +3 -7
- data/ext/multi_compress/vendor/brotli/c/common/shared_dictionary_internal.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/common/static_init.h +56 -0
- data/ext/multi_compress/vendor/brotli/c/common/transform.c +6 -4
- data/ext/multi_compress/vendor/brotli/c/common/transform.h +1 -2
- data/ext/multi_compress/vendor/brotli/c/common/version.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.c +2 -3
- data/ext/multi_compress/vendor/brotli/c/dec/bit_reader.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/dec/decode.c +128 -39
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.c +2 -5
- data/ext/multi_compress/vendor/brotli/c/dec/huffman.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.c +67 -0
- data/ext/multi_compress/vendor/brotli/c/dec/prefix.h +18 -708
- data/ext/multi_compress/vendor/brotli/c/dec/prefix_inc.h +707 -0
- data/ext/multi_compress/vendor/brotli/c/dec/state.c +18 -15
- data/ext/multi_compress/vendor/brotli/c/dec/state.h +2 -6
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.c +53 -0
- data/ext/multi_compress/vendor/brotli/c/dec/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.c +32 -8
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.c +15 -15
- data/ext/multi_compress/vendor/brotli/c/enc/backward_references_hq.h +1 -5
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.c +28 -4
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost.h +8 -40
- data/ext/multi_compress/vendor/brotli/c/enc/bit_cost_inc.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.c +9 -12
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter.h +0 -3
- data/ext/multi_compress/vendor/brotli/c/enc/block_splitter_inc.h +14 -8
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.c +10 -9
- data/ext/multi_compress/vendor/brotli/c/enc/brotli_bit_stream.h +0 -6
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.c +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/cluster.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/command.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/command.h +8 -10
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.c +3 -5
- data/ext/multi_compress/vendor/brotli/c/enc/compound_dictionary.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.c +3 -13
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.c +5 -15
- data/ext/multi_compress/vendor/brotli/c/enc/compress_fragment_two_pass.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.c +127 -1830
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash.h +23 -3
- data/ext/multi_compress/vendor/brotli/c/enc/dictionary_hash_inc.h +1829 -0
- data/ext/multi_compress/vendor/brotli/c/enc/encode.c +77 -52
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.c +9 -7
- data/ext/multi_compress/vendor/brotli/c/enc/encoder_dict.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.c +3 -6
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode.h +2 -4
- data/ext/multi_compress/vendor/brotli/c/enc/entropy_encode_static.h +18 -12
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/fast_log.h +2 -3
- data/ext/multi_compress/vendor/brotli/c/enc/find_match_length.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/hash.h +38 -31
- data/ext/multi_compress/vendor/brotli/c/enc/hash_base.h +38 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_forgetful_chain_inc.h +11 -1
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_inc.h +24 -7
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match64_simd_inc.h +304 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_inc.h +30 -11
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_quickly_inc.h +4 -0
- data/ext/multi_compress/vendor/brotli/c/enc/hash_longest_match_simd_inc.h +278 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.c +1 -0
- data/ext/multi_compress/vendor/brotli/c/enc/histogram.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.c +4 -6
- data/ext/multi_compress/vendor/brotli/c/enc/literal_cost.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/matching_tag_mask.h +69 -0
- data/ext/multi_compress/vendor/brotli/c/enc/memory.c +0 -5
- data/ext/multi_compress/vendor/brotli/c/enc/memory.h +0 -4
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.c +7 -9
- data/ext/multi_compress/vendor/brotli/c/enc/metablock.h +3 -3
- data/ext/multi_compress/vendor/brotli/c/enc/metablock_inc.h +4 -4
- data/ext/multi_compress/vendor/brotli/c/enc/params.h +0 -1
- data/ext/multi_compress/vendor/brotli/c/enc/prefix.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/quality.h +17 -10
- data/ext/multi_compress/vendor/brotli/c/enc/ringbuffer.h +1 -4
- data/ext/multi_compress/vendor/brotli/c/enc/state.h +2 -2
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.c +5 -11
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict.h +1 -3
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.c +224 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut.h +20 -5837
- data/ext/multi_compress/vendor/brotli/c/enc/static_dict_lut_inc.h +5830 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.c +59 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init.h +30 -0
- data/ext/multi_compress/vendor/brotli/c/enc/static_init_lazy.cc +26 -0
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.c +1 -1
- data/ext/multi_compress/vendor/brotli/c/enc/utf8_util.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/enc/write_bits.h +0 -2
- data/ext/multi_compress/vendor/brotli/c/include/brotli/decode.h +1 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/encode.h +5 -1
- data/ext/multi_compress/vendor/brotli/c/include/brotli/port.h +4 -7
- data/ext/multi_compress/vendor/brotli/c/include/brotli/types.h +2 -2
- data/ext/multi_compress/vendor/lz4/LICENSE +12 -0
- data/ext/multi_compress/vendor/zstd/COPYING +339 -0
- data/ext/multi_compress/vendor/zstd/LICENSE +30 -0
- data/ext/multi_compress/vendor/zstd/lib/Makefile +67 -35
- data/ext/multi_compress/vendor/zstd/lib/README.md +33 -2
- data/ext/multi_compress/vendor/zstd/lib/common/allocations.h +55 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bits.h +205 -0
- data/ext/multi_compress/vendor/zstd/lib/common/bitstream.h +84 -108
- data/ext/multi_compress/vendor/zstd/lib/common/compiler.h +170 -41
- data/ext/multi_compress/vendor/zstd/lib/common/cpu.h +37 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.c +7 -1
- data/ext/multi_compress/vendor/zstd/lib/common/debug.h +21 -21
- data/ext/multi_compress/vendor/zstd/lib/common/entropy_common.c +12 -40
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.c +10 -2
- data/ext/multi_compress/vendor/zstd/lib/common/error_private.h +46 -47
- data/ext/multi_compress/vendor/zstd/lib/common/fse.h +8 -100
- data/ext/multi_compress/vendor/zstd/lib/common/fse_decompress.c +28 -116
- data/ext/multi_compress/vendor/zstd/lib/common/huf.h +79 -166
- data/ext/multi_compress/vendor/zstd/lib/common/mem.h +46 -66
- data/ext/multi_compress/vendor/zstd/lib/common/pool.c +27 -11
- data/ext/multi_compress/vendor/zstd/lib/common/pool.h +8 -11
- data/ext/multi_compress/vendor/zstd/lib/common/portability_macros.h +45 -11
- data/ext/multi_compress/vendor/zstd/lib/common/threading.c +74 -14
- data/ext/multi_compress/vendor/zstd/lib/common/threading.h +5 -18
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.c +5 -11
- data/ext/multi_compress/vendor/zstd/lib/common/xxhash.h +2411 -1003
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_common.c +1 -36
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_deps.h +13 -1
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_internal.h +13 -182
- data/ext/multi_compress/vendor/zstd/lib/common/zstd_trace.h +6 -13
- data/ext/multi_compress/vendor/zstd/lib/compress/clevels.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/fse_compress.c +15 -131
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.c +11 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/hist.h +8 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/huf_compress.c +283 -189
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress.c +2419 -903
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_internal.h +423 -245
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.c +116 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_literals.h +16 -8
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.c +10 -10
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_sequences.h +8 -7
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.c +254 -139
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_cwksp.h +184 -95
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.c +163 -81
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_double_fast.h +18 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.c +507 -197
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_fast.h +7 -14
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.c +579 -484
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_lazy.h +133 -65
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.c +61 -40
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm.h +7 -15
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_ldm_geartab.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.c +352 -218
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_opt.h +37 -21
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.c +238 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstd_preSplit.h +33 -0
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.c +239 -175
- data/ext/multi_compress/vendor/zstd/lib/compress/zstdmt_compress.h +5 -16
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress.c +543 -488
- data/ext/multi_compress/vendor/zstd/lib/decompress/huf_decompress_amd64.S +78 -61
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress.c +295 -115
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.c +430 -293
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_block.h +7 -2
- data/ext/multi_compress/vendor/zstd/lib/decompress/zstd_decompress_internal.h +11 -7
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_compress.c +1 -1
- data/ext/multi_compress/vendor/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.c +95 -46
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/cover.h +3 -9
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/divsufsort.h +0 -10
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/fastcover.c +4 -4
- data/ext/multi_compress/vendor/zstd/lib/dictBuilder/zdict.c +25 -97
- data/ext/multi_compress/vendor/zstd/lib/dll/example/Makefile +1 -1
- data/ext/multi_compress/vendor/zstd/lib/dll/example/README.md +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_legacy.h +38 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.c +19 -50
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v01.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.c +27 -80
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v02.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.c +28 -83
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v03.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.c +25 -74
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v04.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.c +31 -76
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v05.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.c +44 -88
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v06.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.c +33 -84
- data/ext/multi_compress/vendor/zstd/lib/legacy/zstd_v07.h +1 -1
- data/ext/multi_compress/vendor/zstd/lib/libzstd.mk +65 -33
- data/ext/multi_compress/vendor/zstd/lib/libzstd.pc.in +5 -5
- data/ext/multi_compress/vendor/zstd/lib/module.modulemap +13 -3
- data/ext/multi_compress/vendor/zstd/lib/zdict.h +65 -36
- data/ext/multi_compress/vendor/zstd/lib/zstd.h +890 -267
- data/ext/multi_compress/vendor/zstd/lib/zstd_errors.h +28 -16
- data/lib/multi_compress/version.rb +1 -1
- data/lib/multi_compress.rb +80 -41
- metadata +29 -2
|
@@ -6,9 +6,6 @@
|
|
|
6
6
|
|
|
7
7
|
#include <brotli/decode.h>
|
|
8
8
|
|
|
9
|
-
#include <stdlib.h> /* free, malloc */
|
|
10
|
-
#include <string.h> /* memcpy, memset */
|
|
11
|
-
|
|
12
9
|
#include "../common/constants.h"
|
|
13
10
|
#include "../common/context.h"
|
|
14
11
|
#include "../common/dictionary.h"
|
|
@@ -20,6 +17,7 @@
|
|
|
20
17
|
#include "huffman.h"
|
|
21
18
|
#include "prefix.h"
|
|
22
19
|
#include "state.h"
|
|
20
|
+
#include "static_init.h"
|
|
23
21
|
|
|
24
22
|
#if defined(BROTLI_TARGET_NEON)
|
|
25
23
|
#include <arm_neon.h>
|
|
@@ -46,16 +44,19 @@ extern "C" {
|
|
|
46
44
|
255 prefix + 32 base + 255 suffix */
|
|
47
45
|
static const brotli_reg_t kRingBufferWriteAheadSlack = 542;
|
|
48
46
|
|
|
49
|
-
static const
|
|
47
|
+
static const BROTLI_MODEL("small")
|
|
48
|
+
uint8_t kCodeLengthCodeOrder[BROTLI_CODE_LENGTH_CODES] = {
|
|
50
49
|
1, 2, 3, 4, 0, 5, 17, 6, 16, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
51
50
|
};
|
|
52
51
|
|
|
53
52
|
/* Static prefix code for the complex code length code lengths. */
|
|
54
|
-
static const
|
|
53
|
+
static const BROTLI_MODEL("small")
|
|
54
|
+
uint8_t kCodeLengthPrefixLength[16] = {
|
|
55
55
|
2, 2, 2, 3, 2, 2, 2, 4, 2, 2, 2, 3, 2, 2, 2, 4,
|
|
56
56
|
};
|
|
57
57
|
|
|
58
|
-
static const
|
|
58
|
+
static const BROTLI_MODEL("small")
|
|
59
|
+
uint8_t kCodeLengthPrefixValue[16] = {
|
|
59
60
|
0, 4, 3, 2, 0, 4, 3, 1, 0, 4, 3, 2, 0, 4, 3, 5,
|
|
60
61
|
};
|
|
61
62
|
|
|
@@ -78,6 +79,10 @@ BROTLI_BOOL BrotliDecoderSetParameter(
|
|
|
78
79
|
BrotliDecoderState* BrotliDecoderCreateInstance(
|
|
79
80
|
brotli_alloc_func alloc_func, brotli_free_func free_func, void* opaque) {
|
|
80
81
|
BrotliDecoderState* state = 0;
|
|
82
|
+
if (!BrotliDecoderEnsureStaticInit()) {
|
|
83
|
+
BROTLI_DUMP();
|
|
84
|
+
return 0;
|
|
85
|
+
}
|
|
81
86
|
if (!alloc_func && !free_func) {
|
|
82
87
|
state = (BrotliDecoderState*)malloc(sizeof(BrotliDecoderState));
|
|
83
88
|
} else if (alloc_func && free_func) {
|
|
@@ -217,7 +222,7 @@ static BROTLI_NOINLINE BrotliDecoderErrorCode DecodeVarLenUint8(
|
|
|
217
222
|
s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_LONG;
|
|
218
223
|
return BROTLI_DECODER_NEEDS_MORE_INPUT;
|
|
219
224
|
}
|
|
220
|
-
*value = (1U << *value) + bits;
|
|
225
|
+
*value = ((brotli_reg_t)1U << *value) + bits;
|
|
221
226
|
s->substate_decode_uint8 = BROTLI_STATE_DECODE_UINT8_NONE;
|
|
222
227
|
return BROTLI_DECODER_SUCCESS;
|
|
223
228
|
|
|
@@ -466,6 +471,53 @@ static BROTLI_INLINE brotli_reg_t ReadPreloadedSymbol(const HuffmanCode* table,
|
|
|
466
471
|
return result;
|
|
467
472
|
}
|
|
468
473
|
|
|
474
|
+
/* Reads up to limit symbols from br and copies them into ringbuffer,
|
|
475
|
+
starting from pos. Caller must ensure that there is enough space
|
|
476
|
+
for the write. Returns the amount of symbols actually copied. */
|
|
477
|
+
static BROTLI_INLINE int BrotliCopyPreloadedSymbolsToU8(const HuffmanCode* table,
|
|
478
|
+
BrotliBitReader* br,
|
|
479
|
+
brotli_reg_t* bits,
|
|
480
|
+
brotli_reg_t* value,
|
|
481
|
+
uint8_t* ringbuffer,
|
|
482
|
+
int pos,
|
|
483
|
+
const int limit) {
|
|
484
|
+
/* Calculate range where CheckInputAmount is always true.
|
|
485
|
+
Start with the number of bytes we can read. */
|
|
486
|
+
int64_t new_lim = br->guard_in - br->next_in;
|
|
487
|
+
/* Convert to bits, since symbols use variable number of bits. */
|
|
488
|
+
new_lim *= 8;
|
|
489
|
+
/* At most 15 bits per symbol, so this is safe. */
|
|
490
|
+
new_lim /= 15;
|
|
491
|
+
const int kMaximalOverread = 4;
|
|
492
|
+
int pos_limit = limit;
|
|
493
|
+
int copies = 0;
|
|
494
|
+
if ((new_lim - kMaximalOverread) <= limit) {
|
|
495
|
+
// Safe cast, since new_lim is already < num_steps
|
|
496
|
+
pos_limit = (int)(new_lim - kMaximalOverread);
|
|
497
|
+
}
|
|
498
|
+
if (pos_limit < 0) {
|
|
499
|
+
pos_limit = 0;
|
|
500
|
+
}
|
|
501
|
+
copies = pos_limit;
|
|
502
|
+
pos_limit += pos;
|
|
503
|
+
/* Fast path, caller made sure it is safe to write,
|
|
504
|
+
we verified that is is safe to read. */
|
|
505
|
+
for (; pos < pos_limit; pos++) {
|
|
506
|
+
BROTLI_DCHECK(BrotliCheckInputAmount(br));
|
|
507
|
+
ringbuffer[pos] = (uint8_t)ReadPreloadedSymbol(table, br, bits, value);
|
|
508
|
+
BROTLI_LOG_ARRAY_INDEX(ringbuffer, pos);
|
|
509
|
+
}
|
|
510
|
+
/* Do the remainder, caller made sure it is safe to write,
|
|
511
|
+
we need to bverify that it is safe to read. */
|
|
512
|
+
while (BrotliCheckInputAmount(br) && copies < limit) {
|
|
513
|
+
ringbuffer[pos] = (uint8_t)ReadPreloadedSymbol(table, br, bits, value);
|
|
514
|
+
BROTLI_LOG_ARRAY_INDEX(ringbuffer, pos);
|
|
515
|
+
pos++;
|
|
516
|
+
copies++;
|
|
517
|
+
}
|
|
518
|
+
return copies;
|
|
519
|
+
}
|
|
520
|
+
|
|
469
521
|
static BROTLI_INLINE brotli_reg_t Log2Floor(brotli_reg_t x) {
|
|
470
522
|
brotli_reg_t result = 0;
|
|
471
523
|
while (x) {
|
|
@@ -1089,7 +1141,7 @@ static BrotliDecoderErrorCode DecodeContextMap(brotli_reg_t context_map_size,
|
|
|
1089
1141
|
h->context_index = context_index;
|
|
1090
1142
|
return BROTLI_DECODER_NEEDS_MORE_INPUT;
|
|
1091
1143
|
}
|
|
1092
|
-
reps += 1U << code;
|
|
1144
|
+
reps += (brotli_reg_t)1U << code;
|
|
1093
1145
|
BROTLI_LOG_UINT(reps);
|
|
1094
1146
|
if (context_index + reps > context_map_size) {
|
|
1095
1147
|
return
|
|
@@ -1363,6 +1415,7 @@ static BROTLI_BOOL BROTLI_NOINLINE BrotliEnsureRingBuffer(
|
|
|
1363
1415
|
static BrotliDecoderErrorCode BROTLI_NOINLINE
|
|
1364
1416
|
SkipMetadataBlock(BrotliDecoderState* s) {
|
|
1365
1417
|
BrotliBitReader* br = &s->br;
|
|
1418
|
+
int nbytes;
|
|
1366
1419
|
|
|
1367
1420
|
if (s->meta_block_remaining_len == 0) {
|
|
1368
1421
|
return BROTLI_DECODER_SUCCESS;
|
|
@@ -1373,7 +1426,7 @@ SkipMetadataBlock(BrotliDecoderState* s) {
|
|
|
1373
1426
|
/* Drain accumulator. */
|
|
1374
1427
|
if (BrotliGetAvailableBits(br) >= 8) {
|
|
1375
1428
|
uint8_t buffer[8];
|
|
1376
|
-
|
|
1429
|
+
nbytes = (int)(BrotliGetAvailableBits(br)) >> 3;
|
|
1377
1430
|
BROTLI_DCHECK(nbytes <= 8);
|
|
1378
1431
|
if (nbytes > s->meta_block_remaining_len) {
|
|
1379
1432
|
nbytes = s->meta_block_remaining_len;
|
|
@@ -1390,7 +1443,7 @@ SkipMetadataBlock(BrotliDecoderState* s) {
|
|
|
1390
1443
|
}
|
|
1391
1444
|
|
|
1392
1445
|
/* Direct access to metadata is possible. */
|
|
1393
|
-
|
|
1446
|
+
nbytes = (int)BrotliGetRemainingBytes(br);
|
|
1394
1447
|
if (nbytes > s->meta_block_remaining_len) {
|
|
1395
1448
|
nbytes = s->meta_block_remaining_len;
|
|
1396
1449
|
}
|
|
@@ -1486,7 +1539,7 @@ static BROTLI_BOOL AttachCompoundDictionary(
|
|
|
1486
1539
|
return BROTLI_TRUE;
|
|
1487
1540
|
}
|
|
1488
1541
|
|
|
1489
|
-
static void
|
|
1542
|
+
static void EnsureCompoundDictionaryInitialized(BrotliDecoderState* state) {
|
|
1490
1543
|
BrotliDecoderCompoundDictionary* addon = state->compound_dictionary;
|
|
1491
1544
|
/* 256 = (1 << 8) slots in block map. */
|
|
1492
1545
|
int block_bits = 8;
|
|
@@ -1507,7 +1560,7 @@ static BROTLI_BOOL InitializeCompoundDictionaryCopy(BrotliDecoderState* s,
|
|
|
1507
1560
|
int address, int length) {
|
|
1508
1561
|
BrotliDecoderCompoundDictionary* addon = s->compound_dictionary;
|
|
1509
1562
|
int index;
|
|
1510
|
-
|
|
1563
|
+
EnsureCompoundDictionaryInitialized(s);
|
|
1511
1564
|
index = addon->block_map[address >> addon->block_bits];
|
|
1512
1565
|
while (address >= addon->chunk_offsets[index + 1]) index++;
|
|
1513
1566
|
if (addon->total_size < address + length) return BROTLI_FALSE;
|
|
@@ -1753,7 +1806,7 @@ static void CalculateDistanceLut(BrotliDecoderState* s) {
|
|
|
1753
1806
|
brotli_reg_t npostfix = s->distance_postfix_bits;
|
|
1754
1807
|
brotli_reg_t ndirect = s->num_direct_distance_codes;
|
|
1755
1808
|
brotli_reg_t alphabet_size_limit = s->distance_hgroup.alphabet_size_limit;
|
|
1756
|
-
brotli_reg_t postfix = 1u << npostfix;
|
|
1809
|
+
brotli_reg_t postfix = (brotli_reg_t)1u << npostfix;
|
|
1757
1810
|
brotli_reg_t j;
|
|
1758
1811
|
brotli_reg_t bits = 1;
|
|
1759
1812
|
brotli_reg_t half = 0;
|
|
@@ -1959,35 +2012,72 @@ CommandInner:
|
|
|
1959
2012
|
brotli_reg_t bits;
|
|
1960
2013
|
brotli_reg_t value;
|
|
1961
2014
|
PreloadSymbol(safe, s->literal_htree, br, &bits, &value);
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
2015
|
+
if (!safe) {
|
|
2016
|
+
// This is a hottest part of the decode, so we copy the loop below
|
|
2017
|
+
// and optimize it by calculating the number of steps where all checks
|
|
2018
|
+
// evaluate to false (ringbuffer size/block size/input size).
|
|
2019
|
+
// Since all checks are loop invariant, we just need to find
|
|
2020
|
+
// minimal number of iterations for a simple loop, and run
|
|
2021
|
+
// the full version for the remainder.
|
|
2022
|
+
int num_steps = i - 1;
|
|
2023
|
+
if (num_steps > 0 && ((brotli_reg_t)(num_steps) > s->block_length[0])) {
|
|
2024
|
+
// Safe cast, since block_length < steps
|
|
2025
|
+
num_steps = (int)s->block_length[0];
|
|
1967
2026
|
}
|
|
1968
|
-
if (
|
|
1969
|
-
|
|
2027
|
+
if (s->ringbuffer_size >= pos &&
|
|
2028
|
+
(s->ringbuffer_size - pos) <= num_steps) {
|
|
2029
|
+
num_steps = s->ringbuffer_size - pos - 1;
|
|
1970
2030
|
}
|
|
1971
|
-
if (
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
2031
|
+
if (num_steps < 0) {
|
|
2032
|
+
num_steps = 0;
|
|
2033
|
+
}
|
|
2034
|
+
num_steps = BrotliCopyPreloadedSymbolsToU8(s->literal_htree, br, &bits,
|
|
2035
|
+
&value, s->ringbuffer, pos,
|
|
2036
|
+
num_steps);
|
|
2037
|
+
pos += num_steps;
|
|
2038
|
+
s->block_length[0] -= (brotli_reg_t)num_steps;
|
|
2039
|
+
i -= num_steps;
|
|
2040
|
+
do {
|
|
2041
|
+
if (!CheckInputAmount(safe, br)) {
|
|
2042
|
+
s->state = BROTLI_STATE_COMMAND_INNER;
|
|
2043
|
+
result = BROTLI_DECODER_NEEDS_MORE_INPUT;
|
|
2044
|
+
goto saveStateAndReturn;
|
|
2045
|
+
}
|
|
2046
|
+
if (BROTLI_PREDICT_FALSE(s->block_length[0] == 0)) {
|
|
2047
|
+
goto NextLiteralBlock;
|
|
2048
|
+
}
|
|
2049
|
+
BrotliCopyPreloadedSymbolsToU8(s->literal_htree, br, &bits, &value,
|
|
2050
|
+
s->ringbuffer, pos, 1);
|
|
2051
|
+
--s->block_length[0];
|
|
2052
|
+
BROTLI_LOG_ARRAY_INDEX(s->ringbuffer, pos);
|
|
2053
|
+
++pos;
|
|
2054
|
+
if (BROTLI_PREDICT_FALSE(pos == s->ringbuffer_size)) {
|
|
2055
|
+
s->state = BROTLI_STATE_COMMAND_INNER_WRITE;
|
|
2056
|
+
--i;
|
|
2057
|
+
goto saveStateAndReturn;
|
|
2058
|
+
}
|
|
2059
|
+
} while (--i != 0);
|
|
2060
|
+
} else { /* safe */
|
|
2061
|
+
do {
|
|
2062
|
+
if (BROTLI_PREDICT_FALSE(s->block_length[0] == 0)) {
|
|
2063
|
+
goto NextLiteralBlock;
|
|
2064
|
+
}
|
|
1975
2065
|
brotli_reg_t literal;
|
|
1976
2066
|
if (!SafeReadSymbol(s->literal_htree, br, &literal)) {
|
|
1977
2067
|
result = BROTLI_DECODER_NEEDS_MORE_INPUT;
|
|
1978
2068
|
goto saveStateAndReturn;
|
|
1979
2069
|
}
|
|
1980
2070
|
s->ringbuffer[pos] = (uint8_t)literal;
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
}
|
|
1990
|
-
}
|
|
2071
|
+
--s->block_length[0];
|
|
2072
|
+
BROTLI_LOG_ARRAY_INDEX(s->ringbuffer, pos);
|
|
2073
|
+
++pos;
|
|
2074
|
+
if (BROTLI_PREDICT_FALSE(pos == s->ringbuffer_size)) {
|
|
2075
|
+
s->state = BROTLI_STATE_COMMAND_INNER_WRITE;
|
|
2076
|
+
--i;
|
|
2077
|
+
goto saveStateAndReturn;
|
|
2078
|
+
}
|
|
2079
|
+
} while (--i != 0);
|
|
2080
|
+
}
|
|
1991
2081
|
} else {
|
|
1992
2082
|
uint8_t p1 = s->ringbuffer[(pos - 1) & s->ringbuffer_mask];
|
|
1993
2083
|
uint8_t p2 = s->ringbuffer[(pos - 2) & s->ringbuffer_mask];
|
|
@@ -2855,16 +2945,15 @@ void BrotliDecoderSetMetadataCallbacks(
|
|
|
2855
2945
|
|
|
2856
2946
|
/* Escalate internal functions visibility; for testing purposes only. */
|
|
2857
2947
|
#if defined(BROTLI_TEST)
|
|
2858
|
-
BROTLI_BOOL
|
|
2948
|
+
BROTLI_BOOL BrotliSafeReadSymbolForTest(
|
|
2859
2949
|
const HuffmanCode*, BrotliBitReader*, brotli_reg_t*);
|
|
2860
|
-
BROTLI_BOOL
|
|
2950
|
+
BROTLI_BOOL BrotliSafeReadSymbolForTest(
|
|
2861
2951
|
const HuffmanCode* table, BrotliBitReader* br, brotli_reg_t* result) {
|
|
2862
2952
|
return SafeReadSymbol(table, br, result);
|
|
2863
2953
|
}
|
|
2864
|
-
|
|
2865
|
-
void InverseMoveToFrontTransformForTest(
|
|
2954
|
+
void BrotliInverseMoveToFrontTransformForTest(
|
|
2866
2955
|
uint8_t*, brotli_reg_t, BrotliDecoderState*);
|
|
2867
|
-
void
|
|
2956
|
+
void BrotliInverseMoveToFrontTransformForTest(
|
|
2868
2957
|
uint8_t* v, brotli_reg_t l, BrotliDecoderState* s) {
|
|
2869
2958
|
InverseMoveToFrontTransform(v, l, s);
|
|
2870
2959
|
}
|
|
@@ -8,10 +8,6 @@
|
|
|
8
8
|
|
|
9
9
|
#include "huffman.h"
|
|
10
10
|
|
|
11
|
-
#include <string.h> /* memcpy, memset */
|
|
12
|
-
|
|
13
|
-
#include <brotli/types.h>
|
|
14
|
-
|
|
15
11
|
#include "../common/constants.h"
|
|
16
12
|
#include "../common/platform.h"
|
|
17
13
|
|
|
@@ -26,7 +22,8 @@ extern "C" {
|
|
|
26
22
|
((sizeof(brotli_reg_t) << 3) - BROTLI_REVERSE_BITS_MAX)
|
|
27
23
|
#else
|
|
28
24
|
#define BROTLI_REVERSE_BITS_BASE 0
|
|
29
|
-
static
|
|
25
|
+
static BROTLI_MODEL("small")
|
|
26
|
+
uint8_t kReverseBits[1 << BROTLI_REVERSE_BITS_MAX] = {
|
|
30
27
|
0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
|
|
31
28
|
0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
|
|
32
29
|
0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/* Copyright 2025 Google Inc. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
Distributed under MIT license.
|
|
4
|
+
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
#include "prefix.h"
|
|
8
|
+
|
|
9
|
+
#include "../common/platform.h" /* IWYU pragma: keep */
|
|
10
|
+
#include "../common/static_init.h"
|
|
11
|
+
|
|
12
|
+
#if (BROTLI_STATIC_INIT != BROTLI_STATIC_INIT_NONE)
|
|
13
|
+
#include "../common/constants.h"
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
|
17
|
+
extern "C" {
|
|
18
|
+
#endif
|
|
19
|
+
|
|
20
|
+
#if (BROTLI_STATIC_INIT == BROTLI_STATIC_INIT_NONE)
|
|
21
|
+
/* Embed kCmdLut. */
|
|
22
|
+
#include "prefix_inc.h"
|
|
23
|
+
#else
|
|
24
|
+
BROTLI_COLD BROTLI_BOOL BrotliDecoderInitCmdLut(CmdLutElement* items) {
|
|
25
|
+
static const uint8_t kInsertLengthExtraBits[24] = {
|
|
26
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02, 0x03, 0x03,
|
|
27
|
+
0x04, 0x04, 0x05, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0C, 0x0E, 0x18};
|
|
28
|
+
static const uint8_t kCopyLengthExtraBits[24] = {
|
|
29
|
+
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x02, 0x02,
|
|
30
|
+
0x03, 0x03, 0x04, 0x04, 0x05, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x18};
|
|
31
|
+
static const uint8_t kCellPos[11] = {0, 1, 0, 1, 8, 9, 2, 16, 10, 17, 18};
|
|
32
|
+
|
|
33
|
+
uint16_t insert_length_offsets[24];
|
|
34
|
+
uint16_t copy_length_offsets[24];
|
|
35
|
+
insert_length_offsets[0] = 0;
|
|
36
|
+
copy_length_offsets[0] = 2;
|
|
37
|
+
for (size_t i = 0; i < 23; ++i) {
|
|
38
|
+
insert_length_offsets[i + 1] =
|
|
39
|
+
insert_length_offsets[i] + (uint16_t)(1u << kInsertLengthExtraBits[i]);
|
|
40
|
+
copy_length_offsets[i + 1] =
|
|
41
|
+
copy_length_offsets[i] + (uint16_t)(1u << kCopyLengthExtraBits[i]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
for (size_t symbol = 0; symbol < BROTLI_NUM_COMMAND_SYMBOLS; ++symbol) {
|
|
45
|
+
CmdLutElement* item = items + symbol;
|
|
46
|
+
const size_t cell_idx = symbol >> 6;
|
|
47
|
+
const size_t cell_pos = kCellPos[cell_idx];
|
|
48
|
+
const size_t copy_code = ((cell_pos << 3) & 0x18) + (symbol & 0x7);
|
|
49
|
+
const uint16_t copy_len_offset = copy_length_offsets[copy_code];
|
|
50
|
+
const size_t insert_code = (cell_pos & 0x18) + ((symbol >> 3) & 0x7);
|
|
51
|
+
item->copy_len_extra_bits = kCopyLengthExtraBits[copy_code];
|
|
52
|
+
item->context = (copy_len_offset > 4) ? 3 : ((uint8_t)copy_len_offset - 2);
|
|
53
|
+
item->copy_len_offset = copy_len_offset;
|
|
54
|
+
item->distance_code = (cell_idx >= 2) ? -1 : 0;
|
|
55
|
+
item->insert_len_extra_bits = kInsertLengthExtraBits[insert_code];
|
|
56
|
+
item->insert_len_offset = insert_length_offsets[insert_code];
|
|
57
|
+
}
|
|
58
|
+
return BROTLI_TRUE;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
BROTLI_MODEL("small")
|
|
62
|
+
CmdLutElement kCmdLut[BROTLI_NUM_COMMAND_SYMBOLS];
|
|
63
|
+
#endif /* BROTLI_STATIC_INIT */
|
|
64
|
+
|
|
65
|
+
#if defined(__cplusplus) || defined(c_plusplus)
|
|
66
|
+
} /* extern "C" */
|
|
67
|
+
#endif
|