-
Notifications
You must be signed in to change notification settings - Fork 289
Fix CCITT Fax3/Fax4 decoder heap overflow in vendored libtiff (CVE-2011-0192)#1643
Open
dkgkdfg65 wants to merge 1 commit into
Open
Fix CCITT Fax3/Fax4 decoder heap overflow in vendored libtiff (CVE-2011-0192) #1643dkgkdfg65 wants to merge 1 commit into
dkgkdfg65 wants to merge 1 commit into
Conversation
Backport the upstream libtiff 3.9.5 bounds check into the vendored libtiff 3.9.4 CCITT fax decoder (DesktopEditor/cximage/tiff/tif_fax3.h). The EXPAND2D macro's S_VL (vertical-left) case writes a decoded run via SETVALUE / *pa++ without validating the new changing-element position against the reference line. A crafted CCITT G3/G4 image can therefore drive the run array (runs[], sized in Fax3SetupState) past its end, producing a heap-buffer-overflow WRITE in Fax4Decode. In this codebase the decoder is reachable from CxImageTIF::Decode -> TIFFReadRGBAImage when a TIFF embedded in an untrusted document is rendered. This mirrors the official upstream fix (libtiff 3.9.5, tif_fax3.h): the unexpected VL transition is rejected instead of writing out of bounds.
CLA assistant check
All committers have signed the CLA.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The vendored libtiff 3.9.4 (2010) CCITT Fax3/Fax4 decoder in
DesktopEditor/cximage/tiff/is vulnerable to a heap buffer overflow (CVE-2011-0192 ). This PR backports the official upstream fix (libtiff 3.9.5) as a single-file, surgical change toDesktopEditor/cximage/tiff/tif_fax3.h.The bug
Fax4Decode(and the other 2-D decoders) expand runs through theEXPAND2Dmacro intif_fax3.h. TheS_VL(vertical-left) case writes a decoded run viaSETVALUE/*pa++without validating the new changing-element position against the reference line. A crafted CCITT G3/G4 stream can drive the run array (runs[], sized once inFax3SetupState) past its end, yielding a heap-buffer-overflow WRITE inFax4Decode.ASan backtrace (vendored 3.9.4 sources, exact API ONLYOFFICE calls):
Reachability in this codebase
A TIFF embedded in (or opened as) an untrusted document is decoded by CxImage → libtiff:
DesktopEditor/raster/ImageFileFormatChecker.cppsniffs the TIFF magic (II*/MM*) — by content, not extension.CBgraFrame::OpenFile/Decode→CxImage::Decode(_CXIMAGE_FORMAT_TIF)→CxImageTIF::Decode(ximatif.cpp), which callsTIFFReadRGBAImage(ximatif.cpp:175) — the exact sink that overflows.CBgraFrameis fed by document-conversion image managers (OOXML/PPTXimagemanager.cpp, RTFRtfPicture.cpp, FB2/HTML/PDF, WMF/EMF blips, ...).So a malicious image inside a DOCX/PPTX/RTF/FB2/HTML/PDF processed during conversion/rendering reaches the vulnerable decoder.
The fix
Backport of the upstream libtiff 3.9.5 guard in the
EXPAND2DS_VLcase — reject the unexpected VL transition instead of writing out of bounds:Note: although the crash manifests in
Fax4Decode(tif_fax3.c), theEXPAND2Dmacro and the upstream fix both live intif_fax3.h, so the change is confined to that header (matching upstream exactly).Verification
Built the vendored 3.9.4 tiff sources with
clang -fsanitize=addressand exercised the sameTIFFReadRGBAImagepath asCxImageTIF::Decode:Important: this is a stopgap
The vendored libtiff here is 3.9.4 (2010). It still carries many other pre-4.0 libtiff CVEs beyond this one; a single backport does not make it safe. Strongly recommend upgrading the vendored CxImage libtiff to a current 4.x release (and ideally consolidating with the 4.x copy already present under
DesktopEditor/raster/Jp2/openjpeg/.../thirdparty/libtiff). This PR is a minimal, low-risk mitigation for the one reachable heap-write in the meantime.Refs: CVE-2011-0192; upstream libtiff 3.9.5
tif_fax3.hfix.