Blame SOURCES/0085-fdo-81516-vcl-limit-number-of-CFFs-read-from-font.patch

f085be
From 5591c9c2ab77d32a923200f980e8fe7af61ffd5b Mon Sep 17 00:00:00 2001
f085be
From: Michael Stahl <mstahl@redhat.com>
f085be
Date: Tue, 5 Aug 2014 12:50:05 +0200
f085be
Subject: [PATCH 085/137] fdo#81516: vcl: limit number of CFFs read from font
f085be
f085be
(cherry picked from commit 45b0b47d114437198c9e0872d427576e6e7e6cc6)
f085be
f085be
Conflicts:
f085be
	vcl/source/fontsubset/cff.cxx
f085be
f085be
Change-Id: I9928b9805169a2dbb41be669dc37617b30bc672b
f085be
Reviewed-on: https://gerrit.libreoffice.org/10752
f085be
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
f085be
Tested-by: Miklos Vajna <vmiklos@collabora.co.uk>
f085be
---
f085be
 vcl/source/fontsubset/cff.cxx | 20 +++++++++++++-------
f085be
 1 file changed, 13 insertions(+), 7 deletions(-)
f085be
f085be
diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx
f085be
index 35b6679..476e458 100644
f085be
--- a/vcl/source/fontsubset/cff.cxx
f085be
+++ b/vcl/source/fontsubset/cff.cxx
f085be
@@ -369,7 +369,7 @@ public:
f085be
     explicit CffSubsetterContext( const U8* pBasePtr, int nBaseLen);
f085be
     virtual ~CffSubsetterContext( void);
f085be
 
f085be
-    void    initialCffRead( void);
f085be
+    bool    initialCffRead();
f085be
     bool    emitAsType1( class Type1Emitter&,
f085be
                 const long* pGlyphIDs, const U8* pEncoding,
f085be
                 GlyphWidth* pGlyphWidths, int nGlyphCount, FontSubsetInfo& );
f085be
@@ -1569,9 +1569,7 @@ CffGlobal::CffGlobal( void)
f085be
     // TODO; maFontMatrix.clear();
f085be
 }
f085be
 
f085be
-// --------------------------------------------------------------------
f085be
-
f085be
-void CffSubsetterContext::initialCffRead( void)
f085be
+bool CffSubsetterContext::initialCffRead()
f085be
 {
f085be
     // get the CFFHeader
f085be
     mpReadPtr = mpBasePtr;
f085be
@@ -1629,7 +1627,11 @@ void CffSubsetterContext::initialCffRead( void)
f085be
 //      assert( mnFontDictBase == tellRel());
f085be
         mpReadPtr = mpBasePtr + mnFontDictBase;
f085be
         mnFDAryCount = (mpReadPtr[0]<<8) + mpReadPtr[1];
f085be
-        assert( mnFDAryCount < (int)(sizeof(maCffLocal)/sizeof(*maCffLocal)));
f085be
+        if (static_cast<size_t>(mnFDAryCount) >= SAL_N_ELEMENTS(maCffLocal))
f085be
+        {
f085be
+            SAL_INFO("vcl.fonts", "CffSubsetterContext: too many CFF in font");
f085be
+            return false;
f085be
+        }
f085be
 
f085be
         // read FDArray details to get access to the PRIVDICTs
f085be
         for( int i = 0; i < mnFDAryCount; ++i) {
f085be
@@ -1670,6 +1672,8 @@ void CffSubsetterContext::initialCffRead( void)
f085be
     }
f085be
 
f085be
     // ignore the Notices info
f085be
+
f085be
+    return true;
f085be
 }
f085be
 
f085be
 // --------------------------------------------------------------------
f085be
@@ -2340,14 +2344,16 @@ bool CffSubsetterContext::emitAsType1( Type1Emitter& rEmitter,
f085be
 bool FontSubsetInfo::CreateFontSubsetFromCff( GlyphWidth* pOutGlyphWidths )
f085be
 {
f085be
     CffSubsetterContext aCff( mpInFontBytes, mnInByteLength);
f085be
-    aCff.initialCffRead();
f085be
+    bool bRC = aCff.initialCffRead();
f085be
+    if (!bRC)
f085be
+        return bRC;
f085be
 
f085be
     // emit Type1 subset from the CFF input
f085be
     // TODO: also support CFF->CFF subsetting (when PDF-export and PS-printing need it)
f085be
     const bool bPfbSubset = (0 != (mnReqFontTypeMask & FontSubsetInfo::TYPE1_PFB));
f085be
     Type1Emitter aType1Emitter( mpOutFile, bPfbSubset);
f085be
     aType1Emitter.setSubsetName( mpReqFontName);
f085be
-    bool bRC = aCff.emitAsType1( aType1Emitter,
f085be
+    bRC = aCff.emitAsType1( aType1Emitter,
f085be
         mpReqGlyphIds, mpReqEncodedIds,
f085be
         pOutGlyphWidths, mnReqGlyphCount, *this);
f085be
     return bRC;
f085be
-- 
f085be
1.9.3
f085be