]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
zlib: Fix a bug that can crash deflate on some input when using Z_FIXED.
authorEd Maste <emaste@FreeBSD.org>
Tue, 5 Apr 2022 23:34:30 +0000 (23:34 +0000)
committerEd Maste <emaste@FreeBSD.org>
Tue, 5 Apr 2022 23:34:30 +0000 (23:34 +0000)
commit49dcaa348546a9aeacee965fc6cadc3c89d29bf4
tree60156e340bb3fb47cdf8dce513e9018f6c0ec1f7
parent87099980a00cc6d785883214bb89df26490c5379
zlib: Fix a bug that can crash deflate on some input when using Z_FIXED.

Cherry picked from zlib 5c44459c3b28a9bd3283aaceab7c615f8020c531:

This bug was reported by Danilo Ramos of Eideticom, Inc. It has
lain in wait 13 years before being found! The bug was introduced
in zlib 1.2.2.2, with the addition of the Z_FIXED option. That
option forces the use of fixed Huffman codes. For rare inputs with
a large number of distant matches, the pending buffer into which
the compressed data is written can overwrite the distance symbol
table which it overlays. That results in corrupted output due to
invalid distances, and can result in out-of-bound accesses,
crashing the application.

The fix here combines the distance buffer and literal/length
buffers into a single symbol buffer. Now three bytes of pending
buffer space are opened up for each literal or length/distance
pair consumed, instead of the previous two bytes. This assures
that the pending buffer cannot overwrite the symbol table, since
the maximum fixed code compressed length/distance is 31 bits, and
since there are four bytes of pending space for every three bytes
of symbol space.

Approved by: so
Security: CVE-2018-25032
Security: FreeBSD-SA-22:08.zlib
sys/contrib/zlib/deflate.c
sys/contrib/zlib/deflate.h
sys/contrib/zlib/trees.c