head 1.2; access; symbols netbsd-11-1-RELEASE:1.1.1.1.2.1 netbsd-11-0-RELEASE:1.1.1.1 netbsd-11-0-RC7:1.1.1.1 netbsd-11-0-RC6:1.1.1.1 netbsd-11-0-RC5:1.1.1.1 netbsd-11-0-RC4:1.1.1.1 netbsd-11-0-RC3:1.1.1.1 netbsd-11-0-RC2:1.1.1.1 netbsd-11-0-RC1:1.1.1.1 netbsd-11:1.1.1.1.0.2 netbsd-11-base:1.1.1.1 brotli-1-0-9:1.1.1.1 GOOGLE:1.1.1; locks; strict; comment @ * @; 1.2 date 2026.10.28.21.13.09; author mrg; state dead; branches; next 1.1; commitid WySy0JIemcP5Wh1H; 1.1 date 2023.01.29.06.38.34; author mrg; state Exp; branches 1.1.1.1; next ; commitid gOcuvoN6w4Ry1pbE; 1.1.1.1 date 2023.01.29.06.38.34; author mrg; state Exp; branches 1.1.1.1.2.1; next ; commitid gOcuvoN6w4Ry1pbE; 1.1.1.1.2.1 date 2026.10.29.16.03.51; author martin; state dead; branches; next ; commitid Zd6vMoBhuWqLbo1H; desc @@ 1.2 log @merge brotli 1.2.1. @ text @/* NOLINT(build/header_guard) */ /* Copyright 2013 Google Inc. All Rights Reserved. Distributed under MIT license. See file LICENSE for detail or copy at https://opensource.org/licenses/MIT */ /* template parameters: EXPORT_FN, FN */ static BROTLI_NOINLINE void EXPORT_FN(CreateBackwardReferences)( size_t num_bytes, size_t position, const uint8_t* ringbuffer, size_t ringbuffer_mask, ContextLut literal_context_lut, const BrotliEncoderParams* params, Hasher* hasher, int* dist_cache, size_t* last_insert_len, Command* commands, size_t* num_commands, size_t* num_literals) { HASHER()* privat = &hasher->privat.FN(_); /* Set maximum distance, see section 9.1. of the spec. */ const size_t max_backward_limit = BROTLI_MAX_BACKWARD_LIMIT(params->lgwin); const size_t position_offset = params->stream_offset; const Command* const orig_commands = commands; size_t insert_length = *last_insert_len; const size_t pos_end = position + num_bytes; const size_t store_end = num_bytes >= FN(StoreLookahead)() ? position + num_bytes - FN(StoreLookahead)() + 1 : position; /* For speed up heuristics for random data. */ const size_t random_heuristics_window_size = LiteralSpreeLengthForSparseSearch(params); size_t apply_random_heuristics = position + random_heuristics_window_size; const size_t gap = 0; /* Minimum score to accept a backward reference. */ const score_t kMinScore = BROTLI_SCORE_BASE + 100; BROTLI_UNUSED(literal_context_lut); FN(PrepareDistanceCache)(privat, dist_cache); while (position + FN(HashTypeLength)() < pos_end) { size_t max_length = pos_end - position; size_t max_distance = BROTLI_MIN(size_t, position, max_backward_limit); size_t dictionary_start = BROTLI_MIN(size_t, position + position_offset, max_backward_limit); HasherSearchResult sr; sr.len = 0; sr.len_code_delta = 0; sr.distance = 0; sr.score = kMinScore; FN(FindLongestMatch)(privat, ¶ms->dictionary, ringbuffer, ringbuffer_mask, dist_cache, position, max_length, max_distance, dictionary_start + gap, params->dist.max_distance, &sr); if (sr.score > kMinScore) { /* Found a match. Let's look for something even better ahead. */ int delayed_backward_references_in_row = 0; --max_length; for (;; --max_length) { const score_t cost_diff_lazy = 175; HasherSearchResult sr2; sr2.len = params->quality < MIN_QUALITY_FOR_EXTENSIVE_REFERENCE_SEARCH ? BROTLI_MIN(size_t, sr.len - 1, max_length) : 0; sr2.len_code_delta = 0; sr2.distance = 0; sr2.score = kMinScore; max_distance = BROTLI_MIN(size_t, position + 1, max_backward_limit); dictionary_start = BROTLI_MIN(size_t, position + 1 + position_offset, max_backward_limit); FN(FindLongestMatch)(privat, ¶ms->dictionary, ringbuffer, ringbuffer_mask, dist_cache, position + 1, max_length, max_distance, dictionary_start + gap, params->dist.max_distance, &sr2); if (sr2.score >= sr.score + cost_diff_lazy) { /* Ok, let's just write one byte for now and start a match from the next byte. */ ++position; ++insert_length; sr = sr2; if (++delayed_backward_references_in_row < 4 && position + FN(HashTypeLength)() < pos_end) { continue; } } break; } apply_random_heuristics = position + 2 * sr.len + random_heuristics_window_size; dictionary_start = BROTLI_MIN(size_t, position + position_offset, max_backward_limit); { /* The first 16 codes are special short-codes, and the minimum offset is 1. */ size_t distance_code = ComputeDistanceCode( sr.distance, dictionary_start + gap, dist_cache); if ((sr.distance <= (dictionary_start + gap)) && distance_code > 0) { dist_cache[3] = dist_cache[2]; dist_cache[2] = dist_cache[1]; dist_cache[1] = dist_cache[0]; dist_cache[0] = (int)sr.distance; FN(PrepareDistanceCache)(privat, dist_cache); } InitCommand(commands++, ¶ms->dist, insert_length, sr.len, sr.len_code_delta, distance_code); } *num_literals += insert_length; insert_length = 0; /* Put the hash keys into the table, if there are enough bytes left. Depending on the hasher implementation, it can push all positions in the given range or only a subset of them. Avoid hash poisoning with RLE data. */ { size_t range_start = position + 2; size_t range_end = BROTLI_MIN(size_t, position + sr.len, store_end); if (sr.distance < (sr.len >> 2)) { range_start = BROTLI_MIN(size_t, range_end, BROTLI_MAX(size_t, range_start, position + sr.len - (sr.distance << 2))); } FN(StoreRange)(privat, ringbuffer, ringbuffer_mask, range_start, range_end); } position += sr.len; } else { ++insert_length; ++position; /* If we have not seen matches for a long time, we can skip some match lookups. Unsuccessful match lookups are very very expensive and this kind of a heuristic speeds up compression quite a lot. */ if (position > apply_random_heuristics) { /* Going through uncompressible data, jump. */ if (position > apply_random_heuristics + 4 * random_heuristics_window_size) { /* It is quite a long time since we saw a copy, so we assume that this data is not compressible, and store hashes less often. Hashes of non compressible data are less likely to turn out to be useful in the future, too, so we store less of them to not to flood out the hash table of good compressible data. */ const size_t kMargin = BROTLI_MAX(size_t, FN(StoreLookahead)() - 1, 4); size_t pos_jump = BROTLI_MIN(size_t, position + 16, pos_end - kMargin); for (; position < pos_jump; position += 4) { FN(Store)(privat, ringbuffer, ringbuffer_mask, position); insert_length += 4; } } else { const size_t kMargin = BROTLI_MAX(size_t, FN(StoreLookahead)() - 1, 2); size_t pos_jump = BROTLI_MIN(size_t, position + 8, pos_end - kMargin); for (; position < pos_jump; position += 2) { FN(Store)(privat, ringbuffer, ringbuffer_mask, position); insert_length += 2; } } } } } insert_length += pos_end - position; *last_insert_len = insert_length; *num_commands += (size_t)(commands - orig_commands); } @ 1.1 log @Initial revision @ text @@ 1.1.1.1 log @initial import of brotli 1.0.9. modern blender wants freetype to have brotli support enabled or it won't build. fortunately, enabling the decoder support (all it needs currently) is relatively easy and small (~160k on amd64) without exposing brotli as a first class citizen is easy, so this will be linked into xsrc freetype directly. XXX: pullup-10? or perhaps force -10 to use pkgsrc freetype? from pkgsrc DESCR: Brotli is a generic-purpose lossless compression algorithm that compresses data using a combination of a modern variant of the LZ77 algorithm, Huffman coding and 2nd order context modeling, with a compression ratio comparable to the best currently available general-purpose compression methods. It is similar in speed with deflate but offers more dense compression. @ text @@ 1.1.1.1.2.1 log @Pull up the following, requested by mrg in ticket #562: external/mit/brotli/dist/BUILD.bazel up to 1.1.1.1 external/mit/brotli/dist/c/common/dictionary_inc.h up to 1.1.1.1 external/mit/brotli/dist/c/common/shared_dictionary.c up to 1.1.1.1 external/mit/brotli/dist/c/common/shared_dictionary_internal.h up to 1.1.1.1 external/mit/brotli/dist/c/common/static_init.h up to 1.1.1.1 external/mit/brotli/dist/c/dec/prefix.c up to 1.1.1.1 external/mit/brotli/dist/c/dec/prefix_inc.h up to 1.1.1.1 external/mit/brotli/dist/c/dec/static_init.c up to 1.1.1.1 external/mit/brotli/dist/c/dec/static_init.h up to 1.1.1.1 external/mit/brotli/dist/c/include/brotli/shared_dictionary.h up to 1.1.1.1 external/mit/brotli/dist/docs/brotli.svg up to 1.1.1.1 external/mit/brotli/dist/scripts/download_testdata.sh up to 1.1.1.1 external/mit/brotli/dist/tests/testdata/zerosukkanooa.compressed up to 1.1.1.1 external/mit/brotli/dist/tests/cli_test.sh up to 1.1.1.1 external/mit/brotli/dist/SECURITY.md up to 1.1.1.1 external/mit/brotli/dist/.bazelignore up to 1.1.1.1 external/mit/brotli/dist/CHANGELOG.md up to 1.1.1.1 external/mit/brotli/dist/BUILD delete external/mit/brotli/dist/Makefile delete external/mit/brotli/dist/Makefile.am delete external/mit/brotli/dist/WORKSPACE delete external/mit/brotli/dist/bootstrap delete external/mit/brotli/dist/compiler_config_setting.bzl delete external/mit/brotli/dist/configure delete external/mit/brotli/dist/configure-cmake delete external/mit/brotli/dist/configure.ac delete external/mit/brotli/dist/premake5.lua delete external/mit/brotli/dist/c/enc/backward_references.c delete external/mit/brotli/dist/c/enc/backward_references.h delete external/mit/brotli/dist/c/enc/backward_references_hq.c delete external/mit/brotli/dist/c/enc/backward_references_hq.h delete external/mit/brotli/dist/c/enc/backward_references_inc.h delete external/mit/brotli/dist/c/enc/bit_cost.c delete external/mit/brotli/dist/c/enc/bit_cost.h delete external/mit/brotli/dist/c/enc/bit_cost_inc.h delete external/mit/brotli/dist/c/enc/block_encoder_inc.h delete external/mit/brotli/dist/c/enc/block_splitter.c delete external/mit/brotli/dist/c/enc/block_splitter.h delete external/mit/brotli/dist/c/enc/block_splitter_inc.h delete external/mit/brotli/dist/c/enc/brotli_bit_stream.c delete external/mit/brotli/dist/c/enc/brotli_bit_stream.h delete external/mit/brotli/dist/c/enc/cluster.c delete external/mit/brotli/dist/c/enc/cluster.h delete external/mit/brotli/dist/c/enc/cluster_inc.h delete external/mit/brotli/dist/c/enc/command.c delete external/mit/brotli/dist/c/enc/command.h delete external/mit/brotli/dist/c/enc/compress_fragment.c delete external/mit/brotli/dist/c/enc/compress_fragment.h delete external/mit/brotli/dist/c/enc/compress_fragment_two_pass.c delete external/mit/brotli/dist/c/enc/compress_fragment_two_pass.h delete external/mit/brotli/dist/c/enc/dictionary_hash.c delete external/mit/brotli/dist/c/enc/dictionary_hash.h delete external/mit/brotli/dist/c/enc/encode.c delete external/mit/brotli/dist/c/enc/encoder_dict.c delete external/mit/brotli/dist/c/enc/encoder_dict.h delete external/mit/brotli/dist/c/enc/entropy_encode.c delete external/mit/brotli/dist/c/enc/entropy_encode.h delete external/mit/brotli/dist/c/enc/entropy_encode_static.h delete external/mit/brotli/dist/c/enc/fast_log.c delete external/mit/brotli/dist/c/enc/fast_log.h delete external/mit/brotli/dist/c/enc/find_match_length.h delete external/mit/brotli/dist/c/enc/hash.h delete external/mit/brotli/dist/c/enc/hash_composite_inc.h delete external/mit/brotli/dist/c/enc/hash_forgetful_chain_inc.h delete external/mit/brotli/dist/c/enc/hash_longest_match64_inc.h delete external/mit/brotli/dist/c/enc/hash_longest_match_inc.h delete external/mit/brotli/dist/c/enc/hash_longest_match_quickly_inc.h delete external/mit/brotli/dist/c/enc/hash_rolling_inc.h delete external/mit/brotli/dist/c/enc/hash_to_binary_tree_inc.h delete external/mit/brotli/dist/c/enc/histogram.c delete external/mit/brotli/dist/c/enc/histogram.h delete external/mit/brotli/dist/c/enc/histogram_inc.h delete external/mit/brotli/dist/c/enc/literal_cost.c delete external/mit/brotli/dist/c/enc/literal_cost.h delete external/mit/brotli/dist/c/enc/memory.c delete external/mit/brotli/dist/c/enc/memory.h delete external/mit/brotli/dist/c/enc/metablock.c delete external/mit/brotli/dist/c/enc/metablock.h delete external/mit/brotli/dist/c/enc/metablock_inc.h delete external/mit/brotli/dist/c/enc/params.h delete external/mit/brotli/dist/c/enc/prefix.h delete external/mit/brotli/dist/c/enc/quality.h delete external/mit/brotli/dist/c/enc/utf8_util.c delete external/mit/brotli/dist/c/enc/ringbuffer.h delete external/mit/brotli/dist/c/enc/static_dict.c delete external/mit/brotli/dist/c/enc/static_dict.h delete external/mit/brotli/dist/c/enc/static_dict_lut.h delete external/mit/brotli/dist/c/enc/utf8_util.h delete external/mit/brotli/dist/c/enc/write_bits.h delete external/mit/brotli/dist/python/Makefile delete external/mit/brotli/dist/python/README.md delete external/mit/brotli/dist/python/_brotli.cc delete external/mit/brotli/dist/python/bro.py delete external/mit/brotli/dist/python/brotli.py delete external/mit/brotli/dist/python/tests/__init__.py delete external/mit/brotli/dist/python/tests/_test_utils.py delete external/mit/brotli/dist/python/tests/bro_test.py delete external/mit/brotli/dist/python/tests/compress_test.py delete external/mit/brotli/dist/python/tests/compressor_test.py delete external/mit/brotli/dist/python/tests/decompress_test.py delete external/mit/brotli/dist/python/tests/decompressor_test.py delete external/mit/brotli/dist/scripts/sources.lst delete external/mit/brotli/dist/tests/Makefile delete external/mit/brotli/dist/tests/compatibility_test.sh delete external/mit/brotli/dist/tests/roundtrip_test.sh delete external/mit/brotli/dist/CMakeLists.txt up to 1.1.1.2 external/mit/brotli/dist/CONTRIBUTING.md up to 1.1.1.2 external/mit/brotli/dist/MANIFEST.in up to 1.1.1.2 external/mit/brotli/dist/README up to 1.1.1.2 external/mit/brotli/dist/README.md up to 1.1.1.2 external/mit/brotli/dist/setup.cfg up to 1.1.1.2 external/mit/brotli/dist/setup.py up to 1.1.1.2 external/mit/brotli/dist/c/common/constants.c up to 1.1.1.2 external/mit/brotli/dist/c/common/constants.h up to 1.1.1.2 external/mit/brotli/dist/c/common/context.c up to 1.1.1.2 external/mit/brotli/dist/c/common/context.h up to 1.1.1.2 external/mit/brotli/dist/c/common/dictionary.c up to 1.1.1.2 external/mit/brotli/dist/c/common/dictionary.h up to 1.1.1.2 external/mit/brotli/dist/c/common/platform.c up to 1.1.1.2 external/mit/brotli/dist/c/common/platform.h up to 1.2 external/mit/brotli/dist/c/common/transform.c up to 1.1.1.2 external/mit/brotli/dist/c/common/transform.h up to 1.1.1.2 external/mit/brotli/dist/c/common/version.h up to 1.1.1.2 external/mit/brotli/dist/c/dec/bit_reader.c up to 1.1.1.2 external/mit/brotli/dist/c/dec/bit_reader.h up to 1.1.1.2 external/mit/brotli/dist/c/dec/decode.c up to 1.1.1.2 external/mit/brotli/dist/c/dec/huffman.c up to 1.1.1.2 external/mit/brotli/dist/c/dec/huffman.h up to 1.1.1.2 external/mit/brotli/dist/c/dec/prefix.h up to 1.1.1.2 external/mit/brotli/dist/c/dec/state.c up to 1.1.1.2 external/mit/brotli/dist/c/dec/state.h up to 1.1.1.2 external/mit/brotli/dist/c/include/brotli/decode.h up to 1.1.1.2 external/mit/brotli/dist/c/include/brotli/encode.h up to 1.1.1.2 external/mit/brotli/dist/c/include/brotli/port.h up to 1.1.1.2 external/mit/brotli/dist/c/include/brotli/types.h up to 1.1.1.2 external/mit/brotli/dist/c/tools/brotli.c up to 1.1.1.2 external/mit/brotli/dist/c/tools/brotli.md up to 1.1.1.2 external/mit/brotli/dist/docs/brotli.1 up to 1.1.1.2 external/mit/brotli/dist/docs/constants.h.3 up to 1.1.1.2 external/mit/brotli/dist/docs/decode.h.3 up to 1.1.1.2 external/mit/brotli/dist/docs/encode.h.3 up to 1.1.1.2 external/mit/brotli/dist/docs/types.h.3 up to 1.1.1.2 external/mit/brotli/dist/scripts/libbrotlicommon.pc.in up to 1.1.1.2 external/mit/brotli/dist/scripts/libbrotlidec.pc.in up to 1.1.1.2 external/mit/brotli/dist/scripts/libbrotlienc.pc.in up to 1.1.1.2 Initial import of brotli 1.2.1, that fixes CVE 2026-111497. @ text @@