This repository has been archived by the owner on Sep 3, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix madler#197, oss-fuzz/10036: only write 4 bytes per iteration in d…
…eflate_quick by aggregating the two consecutive values to be written by static_emit_ptr to s->pending_buf and writing the two values at once in a 4 byte store, we avoid running out of the allocated buffer. We used to call quick_send_bits twice and bumped the counter s->pending in the first call, which made the second call write to memory beyond the safe 4 bytes that were guaranteed by the following condition in the enclosing loop in deflate_quick: if (s->pending + 4 >= s->pending_buf_size) { flush_pending(s->strm); The bug was exposed by the memory sanitizer like so: MemorySanitizer:DEADLYSIGNAL -- | ==1==ERROR: MemorySanitizer: SEGV on unknown address 0x730000020000 (pc 0x0000005b6ce4 bp 0x7fff59adb5e0 sp 0x7fff59adb570 T1) | ==1==The signal is caused by a WRITE memory access. | #0 0x5b6ce3 in quick_send_bits zlib-ng/arch/x86/deflate_quick.c:134:48 | madler#1 0x5b5752 in deflate_quick zlib-ng/arch/x86/deflate_quick.c:243:21 | madler#2 0x590a15 in zng_deflate zlib-ng/deflate.c:952:18 | madler#3 0x587165 in zng_compress2 zlib-ng/compress.c:59:15 | madler#4 0x5866d3 in check_compress_level zlib-ng/test/fuzz/compress_fuzzer.c:22:3 | madler#5 0x5862d8 in LLVMFuzzerTestOneInput zlib-ng/test/fuzz/compress_fuzzer.c:74:3 | madler#6 0x4e9b48 in fuzzer::Fuzzer::ExecuteCallback(unsigned char const*, unsigned long) /src/libfuzzer/FuzzerLoop.cpp:575:15 | madler#7 0x4a2f66 in fuzzer::RunOneTest(fuzzer::Fuzzer*, char const*, unsigned long) /src/libfuzzer/FuzzerDriver.cpp:280:6 | madler#8 0x4b3adb in fuzzer::FuzzerDriver(int*, char***, int (*)(unsigned char const*, unsigned long)) /src/libfuzzer/FuzzerDriver.cpp:715:9 | madler#9 0x4a2091 in main /src/libfuzzer/FuzzerMain.cpp:20:10 | madler#10 0x7fb8919b082f in __libc_start_main /build/glibc-Cl5G7W/glibc-2.23/csu/libc-start.c:291 | madler#11 0x41ec68 in _start | MemorySanitizer can not provide additional info. | SUMMARY: MemorySanitizer: SEGV (/mnt/scratch0/clusterfuzz/slave-bot/builds/clusterfuzz-builds_zlib-ng_7ead0a3e4980f024583384fd355b6e3ddd4b2ca2/revisions/compress_fuzzer+0x5b6ce3)
- Loading branch information