royaltm / rust-delharc Goto Github PK
View Code? Open in Web Editor NEWA Rust library for parsing and decoding LHA/LZH archives.
License: Apache License 2.0
A Rust library for parsing and decoding LHA/LZH archives.
License: Apache License 2.0
First off all thanks for delharc. It is very useful. :-)
Unfortunately there is an issue with some special case Amiga archives: If a comment a.k.a. "file note" is attached to a file, the parse_pathname()
function doesn't stop parsing at the end of the file name but also includes the comment.
Small example archive attached.
Expected: LhA.guide
Currently returned: LhA.guide%00Hello, I am a comment!
Ah, and btw... Instead of fixing the bug it would be really cool to have file note support for delharc included, as we basically do have that already :-)
comment.zip
The Cargo.toml file says the license is MIT. But there is no LICENSE or COPYING file in the repository.
Okay to add the MIT license file?
Would you want to dual license under Apache 2.0 or MIT, in which case we should add 2 license files.
Fuzz testing on ClamAV after integrating delharc identified a possible crash.
Here is the test file (in the zip):
delharc-crash-testfile.zip
I created a simple program to demo using delharc and test this issue.
Using the test program, here is a backtrace of the crash:
❯ RUST_BACKTRACE=1 cargo run -- ./clusterfuzz-testcase-minimized-clamav_scanfile_ARCHIVE_fuz
zer-6117113338068992
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/debug/delharc-bin ./clusterfuzz-testcase-minimized-clamav_scanfile_ARCHIVE_fuzzer-6117113338068992`
Opened the LHA/LZH archive
An error occurred when checking the CRC of this LHA or LZH archive: checksum: crc16 mismatch
Found file in LHA archive:
Details: LhaHeader { level: 2, compression: [45, 108, 104, 53, 45], compressed_size: 538976288, original_size: 2105376, filename: [], msdos_attrs: MsDosAttrs(ARCHIVE), last_modified: 538976288, os_type: 32, file_crc: 8224, extended_area: [], first_header_len: 5, extra_headers: [32, 32, 32, 11, 0, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0, 0] }
thread 'main' panicked at /home/micah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/delharc-0.6.0/src/decode/lhv2.rs:124:30:
slice index starts at 5 but ends at 4
stack backtrace:
0: rust_begin_unwind
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/panicking.rs:647:5
1: core::panicking::panic_fmt
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/panicking.rs:72:14
2: core::slice::index::slice_index_order_fail_rt
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/slice/index.rs:98:5
3: core::slice::index::slice_index_order_fail
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/slice/index.rs:91:14
4: <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index_mut
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/slice/index.rs:403:13
5: core::slice::index::<impl core::ops::index::IndexMut<I> for [T]>::index_mut
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/slice/index.rs:29:9
6: core::array::<impl core::ops::index::IndexMut<I> for [T; N]>::index_mut
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/array/mod.rs:359:9
7: delharc::decode::lhv2::LhaV2Decoder<C,R>::read_temp_tree
at /home/micah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/delharc-0.6.0/src/decode/lhv2.rs:124:30
8: delharc::decode::lhv2::LhaV2Decoder<C,R>::begin_new_block
at /home/micah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/delharc-0.6.0/src/decode/lhv2.rs:208:9
9: <delharc::decode::lhv2::LhaV2Decoder<C,R> as delharc::decode::Decoder<R>>::fill_buffer
at /home/micah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/delharc-0.6.0/src/decode/lhv2.rs:273:17
10: <delharc::decode::DecoderAny<R> as delharc::decode::Decoder<R>>::fill_buffer
at /home/micah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/delharc-0.6.0/src/decode.rs:404:50
11: <delharc::decode::LhaDecodeReader<R> as std::io::Read>::read
at /home/micah/.cargo/registry/src/index.crates.io-6f17d22bba15001f/delharc-0.6.0/src/decode.rs:330:9
12: std::io::default_read_to_end::small_probe_read
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/io/mod.rs:431:19
13: std::io::default_read_to_end
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/io/mod.rs:446:20
14: std::io::Read::read_to_end
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/std/src/io/mod.rs:856:9
15: delharc_bin::main
at ./src/main.rs:55:23
16: core::ops::function::FnOnce::call_once
at /rustc/aedd173a2c086e558c2b66d3743b344f977621a7/library/core/src/ops/function.rs:250:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
This issue doesn't look too difficult. I will submit a PR.
It would be nice to have an additional interface to parse a file from a &[u8]
slice.
Something along these lines:
pub fn parse_file_from_bytes(data: &[u8], file_name: &str) -> io::Result<LhaDecodeReader<File>> {
Ok(LhaDecodeReader::from_bytes(data, file_name)?)
}
My example interface passes in the file name (basename) as well, in case you want it for error messages or whatever. Maybe not needed?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.