vcl/source/fontsubset/sft.cxx | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-)
New commits: commit dd6ff950cbc570a11100a7cce69d51577a26bbd7 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Thu Mar 3 20:28:28 2022 +0000 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Thu Mar 3 22:16:50 2022 +0100 ofz: Use-of-uninitialized-value Change-Id: If10e8d2465ef6de62583f6547e3f68e92002f3f8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130944 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index 9ce05ebe0e30..794cdd59d7f8 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -1521,31 +1521,46 @@ int GetTTGlyphComponents(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID, std::vec glyphlist.push_back( glyphID ); - const sal_uInt32 nMaxGlyphSize = glyflength - nOffset; + sal_uInt32 nRemainingData = glyflength - nOffset; - if (nMaxGlyphSize >= 10 && GetInt16(ptr, 0) == -1) { + if (nRemainingData >= 10 && GetInt16(ptr, 0) == -1) { sal_uInt16 flags, index; ptr += 10; + nRemainingData -= 10; do { + if (nRemainingData < 4) + { + SAL_WARN("vcl.fonts", "short read"); + break; + } flags = GetUInt16(ptr, 0); index = GetUInt16(ptr, 2); ptr += 4; + nRemainingData -= 4; n += GetTTGlyphComponents(ttf, index, glyphlist); + sal_uInt32 nAdvance; if (flags & ARG_1_AND_2_ARE_WORDS) { - ptr += 4; + nAdvance = 4; } else { - ptr += 2; + nAdvance = 2; } if (flags & WE_HAVE_A_SCALE) { - ptr += 2; + nAdvance += 2; } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) { - ptr += 4; + nAdvance += 4; } else if (flags & WE_HAVE_A_TWO_BY_TWO) { - ptr += 8; + nAdvance += 8; + } + if (nRemainingData < nAdvance) + { + SAL_WARN("vcl.fonts", "short read"); + break; } + ptr += nAdvance; + nRemainingData -= nAdvance; } while (flags & MORE_COMPONENTS); }