Skip to content

Commit 8b7eb9b

Browse files
fix: Swap to liblzma from lzma-rs introduced issue (#407)
* AI Generated * Delete LZMA_FIX_SUMMARY.md Signed-off-by: Chris Hennick <[email protected]> * Move new test into tests directory * style: cargo fmt --all --------- Signed-off-by: Chris Hennick <[email protected]> Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com> Co-authored-by: Chris Hennick <[email protected]> Co-authored-by: hennickc <[email protected]>
1 parent 54c634b commit 8b7eb9b

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

src/compression.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,10 @@ impl<R: io::BufRead> Decompressor<R> {
309309
#[cfg(feature = "lzma")]
310310
CompressionMethod::Lzma => Decompressor::Lzma(liblzma::bufread::XzDecoder::new_stream(
311311
reader,
312-
liblzma::stream::Stream::new_lzma_decoder(0).unwrap(),
312+
// Use u64::MAX for unlimited memory usage, matching the previous behavior
313+
// from lzma-rs. Using 0 would set the smallest memory limit, which is
314+
// problematic in ancient liblzma versions (5.2.3 and earlier).
315+
liblzma::stream::Stream::new_lzma_decoder(u64::MAX).unwrap(),
313316
)),
314317
#[cfg(feature = "xz")]
315318
CompressionMethod::Xz => Decompressor::Xz(liblzma::bufread::XzDecoder::new(reader)),

tests/bug398.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env rust-script
2+
3+
//! Simple test to verify the LZMA memory limit fix
4+
//! This script tests that LZMA decompression works with the new unlimited memory setting
5+
6+
#[cfg(feature = "lzma")]
7+
fn main() -> Result<(), Box<dyn std::error::Error>> {
8+
println!("Testing LZMA memory limit fix...");
9+
10+
// Test that we can create an LZMA decoder with u64::MAX memory limit
11+
// This would fail in ancient liblzma versions if we used 0
12+
let _stream = liblzma::stream::Stream::new_lzma_decoder(u64::MAX)?;
13+
println!("✓ Successfully created LZMA decoder with unlimited memory (u64::MAX)");
14+
15+
// Test that the old problematic value would work too (for comparison)
16+
// Note: This might fail in ancient versions, but should work in modern ones
17+
let _stream_old = liblzma::stream::Stream::new_lzma_decoder(0);
18+
match _stream_old {
19+
Ok(_) => println!("✓ Old parameter (0) also works in this liblzma version"),
20+
Err(e) => println!(
21+
"⚠ Old parameter (0) fails as expected in ancient versions: {}",
22+
e
23+
),
24+
}
25+
26+
println!("Test completed successfully!");
27+
Ok(())
28+
}

0 commit comments

Comments
 (0)