vcl/source/fontsubset/sft.cxx |   18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

New commits:
commit ebf4ba6d4a59b1947a1e5a94c7405693a0960ffa
Author:     Caolán McNamara <caol...@redhat.com>
AuthorDate: Mon Feb 28 11:45:56 2022 +0000
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Mon Feb 28 14:01:25 2022 +0100

    cid#1473807 Untrusted value as argument
    
    rearrange to make it more obvious to coverity that the value of
    ttf->glyphOffset(glyphID + 1) is the same as nNextOffset
    
    and rename the initial use of length to glyflength to make that
    clearer to me
    
    Change-Id: I0e5c53d9929e1e41d500b7c0833b827808b610f8
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130695
    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 effe83ff55ce..c2d439eda607 100644
--- a/vcl/source/fontsubset/sft.cxx
+++ b/vcl/source/fontsubset/sft.cxx
@@ -2090,29 +2090,29 @@ void GetTTGlobalFontInfo(TrueTypeFont *ttf, 
TTGlobalFontInfo *info)
 
 GlyphData *GetTTRawGlyphData(AbstractTrueTypeFont *ttf, sal_uInt32 glyphID)
 {
+    if (glyphID >= ttf->glyphCount())
+        return nullptr;
+
     sal_uInt32 hmtxlength;
     const sal_uInt8* hmtx = ttf->table(O_hmtx, hmtxlength);
 
     if (!hmtxlength)
         return nullptr;
 
-    sal_uInt32 length;
-    const sal_uInt8* glyf = ttf->table(O_glyf, length);
+    sal_uInt32 glyflength;
+    const sal_uInt8* glyf = ttf->table(O_glyf, glyflength);
     int n;
 
-    if (glyphID >= ttf->glyphCount())
-        return nullptr;
-
     /* #127161# check the glyph offsets */
     sal_uInt32 nNextOffset = ttf->glyphOffset(glyphID + 1);
-    sal_uInt32 nOffset = ttf->glyphOffset(glyphID);
-    if (nNextOffset < nOffset)
+    if (nNextOffset > glyflength)
         return nullptr;
 
-    if (length < ttf->glyphOffset(glyphID + 1))
+    sal_uInt32 nOffset = ttf->glyphOffset(glyphID);
+    if (nOffset > nNextOffset)
         return nullptr;
 
-    length = nNextOffset - nOffset;
+    sal_uInt32 length = nNextOffset - nOffset;
 
     GlyphData* d = static_cast<GlyphData*>(malloc(sizeof(GlyphData))); 
assert(d != nullptr);
 

Reply via email to