You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 84cdafb
Browse filesBrowse the repository at this point in the historyBrowse files
fix handling of invalid match offsets during decompression
* fix handling of invalid match offsets during decompression
* extend decompress tests
* remove ineffective zeroing of memory
Is redundant now due to new `offset == 0` check.
And it looks like previously this zeroing did not work as desired anyway:
It only affected the first byte but did not help for any subsequently copied bytes.
The LZ4 C implementation it is referring to does this differently.
* fuzz decompression with MemorySanitizer
* remove inline(always) to avoid performance regression
inline(always) is a footgun. In combination with the changes in
read_match_offset the performance degrades by 50% in some cases.
Copy file name to clipboardExpand all lines: .github/workflows/rust.yml
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -16,6 +16,8 @@ jobs:
16
16
uses: dtolnay/rust-toolchain@master
17
17
with:
18
18
toolchain: nightly
19
+
# 'rust-src' component is needed for fuzzing with `--sanitizer=memory`
20
+
components: rust-src
19
21
- uses: actions/checkout@v3
20
22
- name: Ensure no_std compiles
21
23
run: cargo build --no-default-features
@@ -47,6 +49,15 @@ jobs:
47
49
run: for fuzz_test in `cargo fuzz list`; do cargo +nightly fuzz run $fuzz_test -- -max_total_time=30 || exit 1; done
48
50
- name: Run fuzz tests (unsafe)
49
51
run: for fuzz_test in `cargo fuzz list`; do cargo +nightly fuzz run $fuzz_test --no-default-features -- -max_total_time=30 || exit 1; done
52
+
- name: Run decompress fuzz test (unsafe; memory sanitizer)
53
+
# Only run this single test because this fuzz target is where invalid memory access might occur
54
+
# (uses decompress functions which create uninitialized `Vec`); running all fuzz tests with MemorySanitizer
55
+
# might make them less effective due to the slowdown from the sanitizer
56
+
# Have to run with `--dev` because otherwise memory access might be optimized away
57
+
# Note that the stack traces reported by MemorySanitizer here are not readable;
58
+
# that would require llvm-symbolizer, see https://clang.llvm.org/docs/MemorySanitizer.html#report-symbolization
59
+
# But setting up llvm-symbolizer here might not be worth it; can do that locally when reproducing the issue
// There is an edge case when output_ptr == start, which causes the decoder to potentially
63
-
// expose up to match_length bytes of uninitialized data in the decompression buffer.
64
-
// To prevent that we write a dummy zero to output, which will zero out output in such cases.
65
-
// This is the same strategy used by the reference C implementation https://github.com/lz4/lz4/pull/772
66
-
output_ptr.write(0u8);
67
62
let dst_ptr_end = output_ptr.add(match_length);
68
63
69
64
while output_ptr.add(1) < dst_ptr_end {
@@ -161,16 +156,21 @@ fn read_integer_ptr(
161
156
Ok(n)
162
157
}
163
158
164
-
/// Read a little-endian 16-bit integer from the input stream.
159
+
/// Read the match offset as a little-endian 16-bit integer from the input stream.
0 commit comments