From 6bd20cfb05ac22ed95e3e6135224c668bc28cb3d Mon Sep 17 00:00:00 2001 From: sidney Date: Thu, 4 Feb 2021 13:33:40 +1300 Subject: [PATCH] Fix error revealed by test x.compressed.03 which has a backward reference for a symbol at the start of the data --- CHANGELOG.md | 2 ++ README.md | 2 +- brotlidecpy/decode.py | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ed6115..5ac209d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Fixed issue with compressed input that contains data split across multiple metadata blocks - Some changes to unit/integration tests to better support testing issues in compression format - Renamed test module to conform to pattern expected by unittest +- Unit tests can now test using multiple compressed versions of each uncompressed example file +- Fixed error revealed by one of the newly tested cases involving an edge case in compressed format ## [1.0.2] - 2021-02-02 diff --git a/README.md b/README.md index 56affc1..b32243c 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ which it is not practical to package or require platform-specific binaries. It i the decompression function, under the assumption that will be the most common use-case that might have that restriction. It is hundreds of times slower than the reference `brotli`. -This is a hand port of the decompression portion of the Javascript project that is +This code began as a hand port of the decompression portion of the Javascript project that is itself a hand port of the C code of the reference implementation. * JavaScript port of brotli [brotli.js](https://github.com/devongovett/brotli.js) diff --git a/brotlidecpy/decode.py b/brotlidecpy/decode.py index 7166926..265038b 100644 --- a/brotlidecpy/decode.py +++ b/brotlidecpy/decode.py @@ -465,8 +465,8 @@ def brotli_decompress_buffer(input_buffer): kInsertLengthPrefixCode[insert_code].nbits) copy_length = kCopyLengthPrefixCode[copy_code].offset + br.read_bits( kCopyLengthPrefixCode[copy_code].nbits) - prev_byte1 = output_buffer[pos - 1] - prev_byte2 = output_buffer[pos - 2] + prev_byte1 = output_buffer[pos - 1] if pos > 0 else 0 + prev_byte2 = output_buffer[pos - 2] if pos > 1 else 0 for j in range(0, insert_length): if block_length[0] == 0: decode_block_type(num_block_types[0], block_type_trees, 0, block_type, block_type_rb,