Fix brotlidump.py crashing when complex prefix code has exactly 1 non-zero code length (#635)

According to the format specification regarding complex prefix codes:

> If there are at least two non-zero code lengths, any trailing zero
> code lengths are omitted, i.e., the last code length in the
> sequence must be non-zero.  In this case, the sum of (32 >> code
> length) over all the non-zero code lengths must equal to 32.

> If the lengths have been read for the entire code length alphabet
> and there was only one non-zero code length, then the prefix code
> has one symbol whose code has zero length.

The script does not handle a case where there is just 1 non-zero code
length where the sum rule doesn't apply, which causes a StopIteration
exception when it attempts to read past the list boundaries.

An example of such file is tests/testdata/mapsdatazrh.compressed. I made
sure this change doesn't break anything by processing all *.compressed
files from the testdata folder with no thrown exceptions.
1 file changed
tree: e719a0dd425cd8fe74676a67fe45bb2b569c9759
  1. c/
  2. csharp/
  3. docs/
  4. fetch-spec/
  5. go/
  6. java/
  7. js/
  8. python/
  9. research/
  10. scripts/
  11. tests/
  12. .editorconfig
  13. .gitignore
  14. .gitmodules
  15. .travis.yml
  16. bootstrap
  17. BUILD
  18. CMakeLists.txt
  19. configure
  20. configure-cmake
  21. configure.ac
  22. CONTRIBUTING.md
  23. LICENSE
  24. Makefile
  25. Makefile.am
  26. MANIFEST.in
  27. premake5.lua
  28. README
  29. README.md
  30. setup.cfg
  31. setup.py
  32. WORKSPACE
README.md

Introduction

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.

The specification of the Brotli Compressed Data Format is defined in RFC 7932.

Brotli is open-sourced under the MIT License, see the LICENSE file.

Brotli mailing list: https://groups.google.com/forum/#!forum/brotli

TravisCI Build Status AppVeyor Build Status

Build instructions

Autotools-style CMake

configure-cmake is an autotools-style configure script for CMake-based projects (not supported on Windows).

The basic commands to build, test and install brotli are:

$ mkdir out && cd out
$ ../configure-cmake
$ make
$ make test
$ make install

By default, debug binaries are built. To generate “release” Makefile specify --disable-debug option to configure-cmake.

Bazel

See Bazel

CMake

The basic commands to build and install brotli are:

$ mkdir out && cd out
$ cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=./installed ..
$ cmake --build . --config Release --target install

You can use other CMake configuration.

Premake5

See Premake5

Python

To install the latest release of the Python module, run the following:

$ pip install brotli

To install the tip-of-the-tree version, run:

$ pip install --upgrade git+https://github.com/google/brotli

See the Python readme for more details on installing from source, development, and testing.

Benchmarks

Related projects

Disclaimer: Brotli authors take no responsibility for the third party projects mentioned in this section.

Independent decoder implementation by Mark Adler, based entirely on format specification.

JavaScript port of brotli decoder. Could be used directly via npm install brotli

Hand ported decoder / encoder in haxe by Dominik Homberger. Output source code: JavaScript, PHP, Python, Java and C#

7Zip plugin