Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not raise error if code equals range in get_bit #16

Merged
merged 8 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/decode/rangecoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ where
fn get_bit(&mut self) -> error::Result<bool> {
self.range >>= 1;

if self.code == self.range {
return Err(error::Error::LZMAError(String::from(
"Corrupted range coding",
)));
}

let bit = self.code > self.range;
let bit = self.code >= self.range;
if bit {
self.code -= self.range
}
Expand Down
10 changes: 10 additions & 0 deletions tests/files/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Test files #

This folder contains a collection of test files to cover different use cases of the lzma-rs library.

This README describes files that are not self-explanatory in this folder.

## bad-random-data
dragly marked this conversation as resolved.
Show resolved Hide resolved

This is a file that causes the code and range to be equal at some point during decoding LZMA data.
Previously, this file would raise an `LZMAError("Corrupted range coding")`, although the file is a valid LZMA file.
13,206 changes: 13,206 additions & 0 deletions tests/files/bad-random-data

Large diffs are not rendered by default.

Binary file added tests/files/bad-random-data.lzma
Binary file not shown.
2 changes: 2 additions & 0 deletions tests/lzma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,15 @@ fn round_trip_hello() {
fn round_trip_files() {
let _ = env_logger::try_init();
round_trip_file("tests/files/foo.txt");
round_trip_file("tests/files/bad-random-data");
}

#[test]
fn big_file() {
let _ = env_logger::try_init();
decomp_big_file("tests/files/foo.txt.lzma", "tests/files/foo.txt");
decomp_big_file("tests/files/hugedict.txt.lzma", "tests/files/foo.txt");
decomp_big_file("tests/files/bad-random-data.lzma", "tests/files/bad-random-data");
}

#[test]
Expand Down