Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit 33f8f35

Browse files
phmccartyjtkukunas
authored andcommitted
default_medium: avoid out-of-bounds read
The `match` pointer can be dereferenced outside the `s->window` buffer, so add a boundary check to avoid the issue. The issue was detected with valgrind. For example, running `gzip FILE` with valgrind on Clear Linux OS for a FILE that reproduces the issue: ==1610872== Thread 3: ==1610872== Invalid read of size 1 ==1610872== at 0x49E9A98: fizzle_matches (deflate_medium.c:150) ==1610872== by 0x49E9A98: deflate_medium (deflate_medium.c:281) ==1610872== by 0x49EC1E7: deflate (deflate.c:1015) ==1610872== by 0x1195D8: UnknownInlinedFun (pigz.c:1602) ==1610872== by 0x1195D8: compress_thread (pigz.c:1752) ==1610872== by 0x11AFD1: ignition (yarn.c:253) ==1610872== by 0x49CB50E: start_thread (pthread_create.c:481) ==1610872== by 0x4B43B02: clone (in /usr/lib64/haswell/libc-2.33.so) ==1610872== Address 0x4c6369f is 1 bytes before a block of size 65,552 alloc'd ==1610872== at 0x48447DA: malloc (vg_replace_malloc.c:380) ==1610872== by 0x49EAB4C: deflateInit2_ (deflate.c:319) ==1610872== by 0x11933D: compress_thread (pigz.c:1637) ==1610872== by 0x11AFD1: ignition (yarn.c:253) ==1610872== by 0x49CB50E: start_thread (pthread_create.c:481) ==1610872== by 0x4B43B02: clone (in /usr/lib64/haswell/libc-2.33.so) The out-of-bounds check for `orig` has been added for completeness.
1 parent 1ac4c01 commit 33f8f35

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

deflate_medium.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ static void fizzle_matches(deflate_state *s, struct match *current, struct match
164164
match--;
165165
orig--;
166166
changed ++;
167+
168+
/* Make sure to avoid an out-of-bounds read on the next iteration */
169+
if (match < s->window || orig < s->window)
170+
break;
167171
}
168172

169173
if (!changed)

0 commit comments

Comments
 (0)