[poppler] 3 commits - fofi/FoFiBase.cc fofi/FoFiBase.h fofi/FoFiTrueType.cc fofi/FoFiTrueType.h fofi/FoFiType1.cc fofi/FoFiType1C.cc fofi/FoFiType1C.h fofi/FoFiType1.h poppler/CairoFontEngine.cc poppler/Gfx.cc poppler/GfxFont.cc poppler/GfxFont.h poppler/GfxState.cc poppler/JPEG2000Stream.cc poppler/PSOutputDev.cc poppler/SplashOutputDev.cc poppler/Stream.h qt5/src qt6/src splash/SplashFontFile.cc splash/SplashFontFile.h splash/SplashFTFontFile.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Mar 18 22:31:42 UTC 2022


 fofi/FoFiBase.cc             |    4 +-
 fofi/FoFiBase.h              |    2 -
 fofi/FoFiTrueType.cc         |   16 ++++----
 fofi/FoFiTrueType.h          |    4 +-
 fofi/FoFiType1.cc            |    6 +--
 fofi/FoFiType1.h             |    4 +-
 fofi/FoFiType1C.cc           |   10 ++---
 fofi/FoFiType1C.h            |    4 +-
 poppler/CairoFontEngine.cc   |   77 ++++++++++++++-----------------------------
 poppler/Gfx.cc               |    6 +--
 poppler/GfxFont.cc           |   22 +++++-------
 poppler/GfxFont.h            |    2 -
 poppler/GfxState.cc          |    7 +--
 poppler/JPEG2000Stream.cc    |   12 ++----
 poppler/PSOutputDev.cc       |   49 ++++++++++-----------------
 poppler/SplashOutputDev.cc   |   14 +++----
 poppler/Stream.h             |   16 +++++---
 qt5/src/QPainterOutputDev.cc |   25 ++++++-------
 qt6/src/QPainterOutputDev.cc |   25 ++++++-------
 splash/SplashFTFontFile.cc   |    6 +--
 splash/SplashFontFile.cc     |   15 +-------
 splash/SplashFontFile.h      |    5 +-
 22 files changed, 134 insertions(+), 197 deletions(-)

New commits:
commit a6b2442e37cc00534bcdca7c83366a0fa0501157
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Mar 14 10:56:27 2022 +0100

    Store font data in a std::vector<unsigned char>
    
    This simplifies various method signatures, because the data array and
    its size do not have to be passed around separately, anymore.
    
    Also, using a std::vector makes tracking the ownership much easier.

diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index d1a95eed..19beb6ea 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -173,10 +173,9 @@ struct _ft_face_data
 {
     _ft_face_data() = default;
 
-    _ft_face_data(FT_Library libA, const char *filenameA, Ref embFontIDA) : size(0), bytes(nullptr), filename(filenameA ? filenameA : ""), embFontID(embFontIDA), lib(libA), face(nullptr), font_face(nullptr) { }
+    _ft_face_data(FT_Library libA, const char *filenameA, Ref embFontIDA) : filename(filenameA ? filenameA : ""), embFontID(embFontIDA), lib(libA), face(nullptr), font_face(nullptr) { }
 
-    size_t size;
-    unsigned char *bytes;
+    std::vector<unsigned char> bytes;
 
     std::string filename;
     Ref embFontID;
@@ -216,41 +215,26 @@ static void _ft_done_face(void *closure)
 {
     struct _ft_face_data *data = (struct _ft_face_data *)closure;
 
-    if (data->bytes) {
-        gfree(data->bytes);
-    }
-
     FT_Done_Face(data->face);
     delete data;
 }
 
-static bool _ft_new_face(FT_Library lib, const char *filename, Ref embFontID, unsigned char *font_data, int font_data_len, FT_Face *face_out, cairo_font_face_t **font_face_out)
+static bool _ft_new_face(FT_Library lib, const char *filename, Ref embFontID, std::vector<unsigned char> &&font_data, FT_Face *face_out, cairo_font_face_t **font_face_out)
 {
     struct _ft_face_data ft_face_data(lib, filename, embFontID);
 
-    if (font_data == nullptr) {
-
+    if (font_data.empty()) {
         /* if we fail to open the file, just pass it to FreeType instead */
         std::ifstream font_data_fstream(filename, std::ios::binary);
         if (!font_data_fstream.is_open()) {
             return _ft_new_face_uncached(lib, filename, face_out, font_face_out);
         }
-
-        /* get length of file */
-        font_data_fstream.seekg(0, font_data_fstream.end);
-        ft_face_data.size = font_data_fstream.tellg();
-    } else {
-        ft_face_data.bytes = font_data;
-        ft_face_data.size = font_data_len;
     }
 
     /* check to see if this is a duplicate of any of the currently open fonts */
     for (_FtFaceDataProxy &face_proxy : _local_open_faces) {
         _ft_face_data *l = static_cast<_ft_face_data *>(face_proxy);
         if ((*l) == ft_face_data) {
-            if (ft_face_data.bytes) {
-                gfree(ft_face_data.bytes);
-            }
             *face_out = l->face;
             *font_face_out = cairo_font_face_reference(l->font_face);
             return true;
@@ -258,12 +242,13 @@ static bool _ft_new_face(FT_Library lib, const char *filename, Ref embFontID, un
     }
 
     /* not a dup, open and insert into list */
-    if (font_data == nullptr) {
+    if (font_data.empty()) {
         if (FT_New_Face(lib, filename, 0, &ft_face_data.face)) {
             return false;
         }
     } else {
-        if (FT_New_Memory_Face(lib, (FT_Byte *)ft_face_data.bytes, ft_face_data.size, 0, &ft_face_data.face)) {
+        ft_face_data.bytes = std::move(font_data);
+        if (FT_New_Memory_Face(lib, (FT_Byte *)ft_face_data.bytes.data(), ft_face_data.bytes.size(), 0, &ft_face_data.face)) {
             return false;
         }
     }
@@ -296,8 +281,7 @@ CairoFreeTypeFont::~CairoFreeTypeFont() { }
 CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Library lib, bool useCIDs)
 {
     const char *fileNameC;
-    unsigned char *font_data;
-    int font_data_len;
+    std::vector<unsigned char> font_data;
     int i, n;
     GfxFontType fontType;
     std::optional<GfxFontLoc> fontLoc;
@@ -313,8 +297,6 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
 
     codeToGID = nullptr;
     codeToGIDLen = 0;
-    font_data = nullptr;
-    font_data_len = 0;
     const GooString *fileName = nullptr;
     fileNameC = nullptr;
 
@@ -332,8 +314,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
 
     // embedded font
     if (fontLoc->locType == gfxFontLocEmbedded) {
-        font_data = gfxFont->readEmbFontFile(xref, &font_data_len);
-        if (nullptr == font_data) {
+        font_data = gfxFont->readEmbFontFile(xref);
+        if (font_data.empty()) {
             goto err2;
         }
 
@@ -352,7 +334,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
     case fontType1:
     case fontType1C:
     case fontType1COT:
-        if (!_ft_new_face(lib, fileNameC, embFontID, font_data, font_data_len, &face, &font_face)) {
+        if (!_ft_new_face(lib, fileNameC, embFontID, std::move(font_data), &face, &font_face)) {
             error(errSyntaxError, -1, "could not create type1 face");
             goto err2;
         }
@@ -391,8 +373,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
             }
         } else {
             std::unique_ptr<FoFiTrueType> ff;
-            if (font_data != nullptr) {
-                ff = FoFiTrueType::make(font_data, font_data_len);
+            if (!font_data.empty()) {
+                ff = FoFiTrueType::make(font_data.data(), font_data.size());
             } else {
                 ff = FoFiTrueType::load(fileNameC);
             }
@@ -406,8 +388,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
     case fontTrueType:
     case fontTrueTypeOT: {
         std::unique_ptr<FoFiTrueType> ff;
-        if (font_data != nullptr) {
-            ff = FoFiTrueType::make(font_data, font_data_len);
+        if (!font_data.empty()) {
+            ff = FoFiTrueType::make(font_data.data(), font_data.size());
         } else {
             ff = FoFiTrueType::load(fileNameC);
         }
@@ -420,7 +402,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
             codeToGID = ((Gfx8BitFont *)gfxFont)->getCodeToGIDMap(ff.get());
             codeToGIDLen = 256;
         }
-        if (!_ft_new_face(lib, fileNameC, embFontID, font_data, font_data_len, &face, &font_face)) {
+        if (!_ft_new_face(lib, fileNameC, embFontID, std::move(font_data), &face, &font_face)) {
             error(errSyntaxError, -1, "could not create truetype face\n");
             goto err2;
         }
@@ -433,8 +415,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
         codeToGIDLen = 0;
 
         if (!useCIDs) {
-            if (font_data != nullptr) {
-                ff1c = FoFiType1C::make(font_data, font_data_len);
+            if (!font_data.empty()) {
+                ff1c = FoFiType1C::make(font_data.data(), font_data.size());
             } else {
                 ff1c = FoFiType1C::load(fileNameC);
             }
@@ -444,7 +426,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
             }
         }
 
-        if (!_ft_new_face(lib, fileNameC, embFontID, font_data, font_data_len, &face, &font_face)) {
+        if (!_ft_new_face(lib, fileNameC, embFontID, std::move(font_data), &face, &font_face)) {
             error(errSyntaxError, -1, "could not create cid face\n");
             goto err2;
         }
@@ -465,8 +447,8 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
         if (!codeToGID) {
             if (!useCIDs) {
                 std::unique_ptr<FoFiTrueType> ff;
-                if (font_data != nullptr) {
-                    ff = FoFiTrueType::make(font_data, font_data_len);
+                if (!font_data.empty()) {
+                    ff = FoFiTrueType::make(font_data.data(), font_data.size());
                 } else {
                     ff = FoFiTrueType::load(fileNameC);
                 }
@@ -477,7 +459,7 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
                 }
             }
         }
-        if (!_ft_new_face(lib, fileNameC, embFontID, font_data, font_data_len, &face, &font_face)) {
+        if (!_ft_new_face(lib, fileNameC, embFontID, std::move(font_data), &face, &font_face)) {
             error(errSyntaxError, -1, "could not create cid (OT) face\n");
             goto err2;
         }
@@ -493,7 +475,6 @@ CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Li
 
 err2:
     gfree(codeToGID);
-    gfree(font_data);
     fprintf(stderr, "some font thing failed\n");
     return nullptr;
 }
diff --git a/poppler/Gfx.cc b/poppler/Gfx.cc
index 82660bad..16f19443 100644
--- a/poppler/Gfx.cc
+++ b/poppler/Gfx.cc
@@ -585,15 +585,13 @@ void Gfx::initDisplayProfile()
                 Object profile = firstElement.dictLookup("DestOutputProfile");
                 if (profile.isStream()) {
                     Stream *iccStream = profile.getStream();
-                    int length = 0;
-                    unsigned char *profBuf = iccStream->toUnsignedChars(&length, 65536, 65536);
-                    auto hp = make_GfxLCMSProfilePtr(cmsOpenProfileFromMem(profBuf, length));
+                    const std::vector<unsigned char> profBuf = iccStream->toUnsignedChars(65536, 65536);
+                    auto hp = make_GfxLCMSProfilePtr(cmsOpenProfileFromMem(profBuf.data(), profBuf.size()));
                     if (!hp) {
                         error(errSyntaxWarning, -1, "read ICCBased color space profile error");
                     } else {
                         state->setDisplayProfile(hp);
                     }
-                    gfree(profBuf);
                 }
             }
         }
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 48b1081c..0f46cffa 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -830,7 +830,7 @@ std::optional<GfxFontLoc> GfxFont::getExternalFont(GooString *path, bool cid)
     return std::move(fontLoc); // std::move only required to please g++-7
 }
 
-unsigned char *GfxFont::readEmbFontFile(XRef *xref, int *len)
+std::vector<unsigned char> GfxFont::readEmbFontFile(XRef *xref)
 {
     Stream *str;
 
@@ -839,12 +839,11 @@ unsigned char *GfxFont::readEmbFontFile(XRef *xref, int *len)
     if (!obj2.isStream()) {
         error(errSyntaxError, -1, "Embedded font file is not a stream");
         embFontID = Ref::INVALID();
-        *len = 0;
-        return nullptr;
+        return std::vector<unsigned char> {};
     }
     str = obj2.getStream();
 
-    unsigned char *buf = str->toUnsignedChars(len);
+    std::vector<unsigned char> buf = str->toUnsignedChars();
     str->close();
 
     return buf;
@@ -1135,10 +1134,10 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     // TrueType font is a losing proposition)
     ffT1 = nullptr;
     ffT1C = nullptr;
-    unsigned char *buf = nullptr;
     if (type == fontType1 && embFontID != Ref::INVALID()) {
-        if ((buf = readEmbFontFile(xref, &len))) {
-            if ((ffT1 = FoFiType1::make(buf, len))) {
+        const std::vector<unsigned char> buf = readEmbFontFile(xref);
+        if (!buf.empty()) {
+            if ((ffT1 = FoFiType1::make(buf.data(), buf.size()))) {
                 if (ffT1->getName()) {
                     if (embFontName) {
                         delete embFontName;
@@ -1150,11 +1149,11 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
                     baseEncFromFontFile = true;
                 }
             }
-            gfree(buf);
         }
     } else if (type == fontType1C && embFontID != Ref::INVALID()) {
-        if ((buf = readEmbFontFile(xref, &len))) {
-            if ((ffT1C = FoFiType1C::make(buf, len))) {
+        const std::vector<unsigned char> buf = readEmbFontFile(xref);
+        if (!buf.empty()) {
+            if ((ffT1C = FoFiType1C::make(buf.data(), buf.size()))) {
                 if (ffT1C->getName()) {
                     if (embFontName) {
                         delete embFontName;
@@ -1166,7 +1165,6 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
                     baseEncFromFontFile = true;
                 }
             }
-            gfree(buf);
         }
     }
 
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index e3459ba3..fed9e2e5 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -282,7 +282,7 @@ public:
     static std::optional<GfxFontLoc> locateBase14Font(const GooString *base14Name);
 
     // Read an external or embedded font file into a buffer.
-    unsigned char *readEmbFontFile(XRef *xref, int *len);
+    std::vector<unsigned char> readEmbFontFile(XRef *xref);
 
     // Get the next char from a string <s> of <len> bytes, returning the
     // char <code>, its Unicode mapping <u>, its displacement vector
diff --git a/poppler/GfxState.cc b/poppler/GfxState.cc
index ebba0f9e..51cc9755 100644
--- a/poppler/GfxState.cc
+++ b/poppler/GfxState.cc
@@ -1773,14 +1773,11 @@ GfxColorSpace *GfxICCBasedColorSpace::parse(Array *arr, OutputDev *out, GfxState
         delete cs;
         return nullptr;
     }
-    unsigned char *profBuf;
     Stream *iccStream = obj1.getStream();
-    int length = 0;
 
-    profBuf = iccStream->toUnsignedChars(&length, 65536, 65536);
-    auto hp = make_GfxLCMSProfilePtr(cmsOpenProfileFromMem(profBuf, length));
+    const std::vector<unsigned char> profBuf = iccStream->toUnsignedChars(65536, 65536);
+    auto hp = make_GfxLCMSProfilePtr(cmsOpenProfileFromMem(profBuf.data(), profBuf.size()));
     cs->profile = hp;
-    gfree(profBuf);
     if (!hp) {
         error(errSyntaxWarning, -1, "read ICCBased color space profile error");
     } else {
diff --git a/poppler/JPEG2000Stream.cc b/poppler/JPEG2000Stream.cc
index 72c461e0..27b72cac 100644
--- a/poppler/JPEG2000Stream.cc
+++ b/poppler/JPEG2000Stream.cc
@@ -39,7 +39,7 @@ struct JPXStreamPrivate
     int ncomps;
     bool inited;
     int smaskInData;
-    void init2(OPJ_CODEC_FORMAT format, unsigned char *buf, int length, bool indexed);
+    void init2(OPJ_CODEC_FORMAT format, const unsigned char *buf, int length, bool indexed);
 };
 
 static inline unsigned char adjustComp(int r, int adjust, int depth, int sgndcorr, bool indexed)
@@ -198,7 +198,7 @@ static void libopenjpeg_warning_callback(const char *msg, void * /*client_data*/
 
 typedef struct JPXData_s
 {
-    unsigned char *data;
+    const unsigned char *data;
     int size;
     int pos;
 } JPXData;
@@ -272,10 +272,8 @@ void JPXStream::init()
         priv->smaskInData = smaskInData.getInt();
     }
 
-    int length = 0;
-    unsigned char *buf = str->toUnsignedChars(&length, bufSize);
-    priv->init2(OPJ_CODEC_JP2, buf, length, indexed);
-    gfree(buf);
+    const std::vector<unsigned char> buf = str->toUnsignedChars(bufSize);
+    priv->init2(OPJ_CODEC_JP2, buf.data(), buf.size(), indexed);
 
     if (priv->image) {
         int numComps = priv->image->numcomps;
@@ -335,7 +333,7 @@ void JPXStream::init()
     priv->inited = true;
 }
 
-void JPXStreamPrivate::init2(OPJ_CODEC_FORMAT format, unsigned char *buf, int length, bool indexed)
+void JPXStreamPrivate::init2(OPJ_CODEC_FORMAT format, const unsigned char *buf, int length, bool indexed)
 {
     JPXData jpxData;
 
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index da12142b..3b142b82 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2374,8 +2374,6 @@ void PSOutputDev::setupExternalType1Font(const GooString *fileName, GooString *p
 
 void PSOutputDev::setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    unsigned char *fontBuf;
-    int fontLen;
     FoFiType1C *ffT1C;
     int i;
 
@@ -2402,12 +2400,12 @@ void PSOutputDev::setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psN
     embFontList->append("\n");
 
     // convert it to a Type 1 font
-    if ((fontBuf = font->readEmbFontFile(xref, &fontLen))) {
-        if ((ffT1C = FoFiType1C::make(fontBuf, fontLen))) {
+    const std::vector<unsigned char> fontBuf = font->readEmbFontFile(xref);
+    if (!fontBuf.empty()) {
+        if ((ffT1C = FoFiType1C::make(fontBuf.data(), fontBuf.size()))) {
             ffT1C->convertToType1(psName->c_str(), nullptr, true, outputFunc, outputStream);
             delete ffT1C;
         }
-        gfree(fontBuf);
     }
 
     // ending comment
@@ -2416,8 +2414,6 @@ void PSOutputDev::setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psN
 
 void PSOutputDev::setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    unsigned char *fontBuf;
-    int fontLen;
     int i;
 
     // check if font is already embedded
@@ -2443,13 +2439,13 @@ void PSOutputDev::setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString
     embFontList->append("\n");
 
     // convert it to a Type 1 font
-    if ((fontBuf = font->readEmbFontFile(xref, &fontLen))) {
-        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf, fontLen)) {
+    const std::vector<unsigned char> fontBuf = font->readEmbFontFile(xref);
+    if (!fontBuf.empty()) {
+        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf.data(), fontBuf.size())) {
             if (ffTT->isOpenTypeCFF()) {
                 ffTT->convertToType1(psName->c_str(), nullptr, true, outputFunc, outputStream);
             }
         }
-        gfree(fontBuf);
     }
 
     // ending comment
@@ -2458,8 +2454,6 @@ void PSOutputDev::setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString
 
 void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    unsigned char *fontBuf;
-    int fontLen;
     int *codeToGID;
 
     // beginning comment
@@ -2469,8 +2463,9 @@ void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *p
     embFontList->append("\n");
 
     // convert it to a Type 42 font
-    if ((fontBuf = font->readEmbFontFile(xref, &fontLen))) {
-        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf, fontLen)) {
+    const std::vector<unsigned char> fontBuf = font->readEmbFontFile(xref);
+    if (!fontBuf.empty()) {
+        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf.data(), fontBuf.size())) {
             codeToGID = ((Gfx8BitFont *)font)->getCodeToGIDMap(ffTT.get());
             ffTT->convertToType42(psName->c_str(), ((Gfx8BitFont *)font)->getHasEncoding() ? ((Gfx8BitFont *)font)->getEncoding() : nullptr, codeToGID, outputFunc, outputStream);
             if (codeToGID) {
@@ -2483,7 +2478,6 @@ void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *p
                 ++font8InfoLen;
             }
         }
-        gfree(fontBuf);
     }
 
     // ending comment
@@ -2580,8 +2574,6 @@ void PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font, const GooString *f
 
 void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *psName)
 {
-    unsigned char *fontBuf;
-    int fontLen;
     FoFiType1C *ffT1C;
     int i;
 
@@ -2608,8 +2600,9 @@ void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *p
     embFontList->append("\n");
 
     // convert it to a Type 0 font
-    if ((fontBuf = font->readEmbFontFile(xref, &fontLen))) {
-        if ((ffT1C = FoFiType1C::make(fontBuf, fontLen))) {
+    const std::vector<unsigned char> fontBuf = font->readEmbFontFile(xref);
+    if (!fontBuf.empty()) {
+        if ((ffT1C = FoFiType1C::make(fontBuf.data(), fontBuf.size()))) {
             if (level >= psLevel3) {
                 // Level 3: use a CID font
                 ffT1C->convertToCIDType0(psName->c_str(), nullptr, 0, outputFunc, outputStream);
@@ -2619,7 +2612,6 @@ void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *p
             }
             delete ffT1C;
         }
-        gfree(fontBuf);
     }
 
     // ending comment
@@ -2628,9 +2620,6 @@ void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *p
 
 void PSOutputDev::setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString *psName, bool needVerticalMetrics)
 {
-    unsigned char *fontBuf;
-    int fontLen;
-
     // beginning comment
     writePSFmt("%%BeginResource: font {0:t}\n", psName);
     embFontList->append("%%+ font ");
@@ -2638,8 +2627,9 @@ void PSOutputDev::setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString
     embFontList->append("\n");
 
     // convert it to a Type 0 font
-    if ((fontBuf = font->readEmbFontFile(xref, &fontLen))) {
-        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf, fontLen)) {
+    const std::vector<unsigned char> fontBuf = font->readEmbFontFile(xref);
+    if (!fontBuf.empty()) {
+        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf.data(), fontBuf.size())) {
             if (level >= psLevel3) {
                 // Level 3: use a CID font
                 ffTT->convertToCIDType2(psName->c_str(), ((GfxCIDFont *)font)->getCIDToGID(), ((GfxCIDFont *)font)->getCIDToGIDLen(), needVerticalMetrics, outputFunc, outputStream);
@@ -2650,7 +2640,6 @@ void PSOutputDev::setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString
                 updateFontMaxValidGlyph(font, maxValidGlyph);
             }
         }
-        gfree(fontBuf);
     }
 
     // ending comment
@@ -2659,8 +2648,6 @@ void PSOutputDev::setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString
 
 void PSOutputDev::setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    unsigned char *fontBuf;
-    int fontLen;
     int i;
 
     // check if font is already embedded
@@ -2686,8 +2673,9 @@ void PSOutputDev::setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString
     embFontList->append("\n");
 
     // convert it to a Type 0 font
-    if ((fontBuf = font->readEmbFontFile(xref, &fontLen))) {
-        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf, fontLen)) {
+    const std::vector<unsigned char> fontBuf = font->readEmbFontFile(xref);
+    if (!fontBuf.empty()) {
+        if (std::unique_ptr<FoFiTrueType> ffTT = FoFiTrueType::make(fontBuf.data(), fontBuf.size())) {
             if (ffTT->isOpenTypeCFF()) {
                 if (level >= psLevel3) {
                     // Level 3: use a CID font
@@ -2698,7 +2686,6 @@ void PSOutputDev::setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString
                 }
             }
         }
-        gfree(fontBuf);
     }
 
     // ending comment
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 8f362b55..8ff7b9a4 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -1845,8 +1845,6 @@ void SplashOutputDev::doUpdateFont(GfxState *state)
     SplashOutFontFileID *id = nullptr;
     SplashFontFile *fontFile;
     SplashFontSrc *fontsrc = nullptr;
-    unsigned char *tmpBuf;
-    int tmpBufLen;
     const double *textMat;
     double m11, m12, m21, m22, fontSize;
     int faceIndex = 0;
@@ -1856,7 +1854,6 @@ void SplashOutputDev::doUpdateFont(GfxState *state)
 
     needFontUpdate = false;
     font = nullptr;
-    tmpBuf = nullptr;
 
     GfxFont *const gfxFont = state->getFont().get();
     if (!gfxFont) {
@@ -1895,11 +1892,12 @@ reload:
 
         // embedded font
         std::string fileName;
+        std::vector<unsigned char> tmpBuf;
 
         if (fontLoc->locType == gfxFontLocEmbedded) {
             // if there is an embedded font, read it to memory
-            tmpBuf = gfxFont->readEmbFontFile((xref) ? xref : doc->getXRef(), &tmpBufLen);
-            if (!tmpBuf) {
+            tmpBuf = gfxFont->readEmbFontFile((xref) ? xref : doc->getXRef());
+            if (tmpBuf.empty()) {
                 goto err2;
             }
 
@@ -1914,7 +1912,7 @@ reload:
         if (!fileName.empty()) {
             fontsrc->setFile(fileName);
         } else {
-            fontsrc->setBuf(tmpBuf, tmpBufLen);
+            fontsrc->setBuf(std::move(tmpBuf));
         }
 
         // load the font file
@@ -1952,7 +1950,7 @@ reload:
             if (!fileName.empty()) {
                 ff = FoFiTrueType::load(fileName.c_str());
             } else {
-                ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
+                ff = FoFiTrueType::make(fontsrc->buf.data(), fontsrc->buf.size());
             }
             int *codeToGID;
             const int n = ff ? 256 : 0;
@@ -2026,7 +2024,7 @@ reload:
                 if (!fileName.empty()) {
                     ff = FoFiTrueType::load(fileName.c_str());
                 } else {
-                    ff = FoFiTrueType::make(tmpBuf, tmpBufLen);
+                    ff = FoFiTrueType::make(fontsrc->buf.data(), fontsrc->buf.size());
                 }
                 if (!ff) {
                     error(errSyntaxError, -1, "Couldn't create a font for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
diff --git a/poppler/Stream.h b/poppler/Stream.h
index 5cc32fe7..3e4b69f0 100644
--- a/poppler/Stream.h
+++ b/poppler/Stream.h
@@ -44,6 +44,7 @@
 
 #include <atomic>
 #include <cstdio>
+#include <vector>
 
 #include "poppler-config.h"
 #include "poppler_private_export.h"
@@ -155,22 +156,23 @@ public:
 
     inline void fillGooString(GooString *s) { fillString(s->toNonConstStr()); }
 
-    inline unsigned char *toUnsignedChars(int *length, int initialSize = 4096, int sizeIncrement = 4096)
+    inline std::vector<unsigned char> toUnsignedChars(int initialSize = 4096, int sizeIncrement = 4096)
     {
+        std::vector<unsigned char> buf(initialSize);
+
         int readChars;
-        unsigned char *buf = (unsigned char *)gmalloc(initialSize);
         int size = initialSize;
-        *length = 0;
+        int length = 0;
         int charsToRead = initialSize;
         bool continueReading = true;
         reset();
-        while (continueReading && (readChars = doGetChars(charsToRead, &buf[*length])) != 0) {
-            *length += readChars;
+        while (continueReading && (readChars = doGetChars(charsToRead, buf.data() + length)) != 0) {
+            length += readChars;
             if (readChars == charsToRead) {
                 if (lookChar() != EOF) {
                     size += sizeIncrement;
                     charsToRead = sizeIncrement;
-                    buf = (unsigned char *)grealloc(buf, size);
+                    buf.resize(size);
                 } else {
                     continueReading = false;
                 }
@@ -178,6 +180,8 @@ public:
                 continueReading = false;
             }
         }
+
+        buf.resize(length);
         return buf;
     }
 
diff --git a/qt5/src/QPainterOutputDev.cc b/qt5/src/QPainterOutputDev.cc
index fce35ecb..4c9b5306 100644
--- a/qt5/src/QPainterOutputDev.cc
+++ b/qt5/src/QPainterOutputDev.cc
@@ -462,14 +462,12 @@ void QPainterOutputDev::updateFont(GfxState *state)
             // load the font from respective location
             switch (fontLoc->locType) {
             case gfxFontLocEmbedded: { // if there is an embedded font, read it to memory
-                int fontDataLen;
-                const unsigned char *fontData = gfxFont->readEmbFontFile(xref, &fontDataLen);
+                const std::vector<unsigned char> fontData = gfxFont->readEmbFontFile(xref);
 
-                m_rawFont = new QRawFont(QByteArray((const char *)fontData, fontDataLen), fontSize, m_hintingPreference);
+                // fontData gets copied in the QByteArray constructor
+                m_rawFont = new QRawFont(QByteArray((const char *)fontData.data(), fontData.size()), fontSize, m_hintingPreference);
                 m_rawFontCache.insert(std::make_pair(fontID, std::unique_ptr<QRawFont>(m_rawFont)));
 
-                // Free the font data, it was copied in the QByteArray constructor
-                free((char *)fontData);
                 break;
             }
             case gfxFontLocExternal: { // font is in an external font file
@@ -521,8 +519,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
 
     } else {
 
-        std::unique_ptr<unsigned char[], void (*)(unsigned char *)> tmpBuf(nullptr, [](unsigned char *b) { free(b); });
-        int tmpBufLen = 0;
+        std::vector<unsigned char> fontBuffer;
 
         std::optional<GfxFontLoc> fontLoc = gfxFont->locateFont(xref, nullptr);
         if (!fontLoc) {
@@ -533,8 +530,8 @@ void QPainterOutputDev::updateFont(GfxState *state)
         // embedded font
         if (fontLoc->locType == gfxFontLocEmbedded) {
             // if there is an embedded font, read it to memory
-            tmpBuf.reset(gfxFont->readEmbFontFile(xref, &tmpBufLen));
-            if (!tmpBuf) {
+            fontBuffer = gfxFont->readEmbFontFile(xref);
+            if (fontBuffer.empty()) {
                 return;
             }
 
@@ -559,7 +556,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
                     return;
                 }
             } else {
-                if (FT_New_Memory_Face(m_ftLibrary, (const FT_Byte *)tmpBuf.get(), tmpBufLen, faceIndex, &freeTypeFace)) {
+                if (FT_New_Memory_Face(m_ftLibrary, (const FT_Byte *)fontBuffer.data(), fontBuffer.size(), faceIndex, &freeTypeFace)) {
                     error(errSyntaxError, -1, "Couldn't create a FreeType face for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
                     return;
                 }
@@ -589,7 +586,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
         }
         case fontTrueType:
         case fontTrueTypeOT: {
-            auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(tmpBuf.get(), tmpBufLen);
+            auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(fontBuffer.data(), fontBuffer.size());
 
             m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont.get())->getCodeToGIDMap(ff.get()) : nullptr;
 
@@ -602,7 +599,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
 
             // check for a CFF font
             if (!m_useCIDs) {
-                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(tmpBuf.get(), tmpBufLen));
+                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(fontBuffer.data(), fontBuffer.size()));
 
                 cidToGIDMap = (ff) ? ff->getCIDToGIDMap(&nCIDs) : nullptr;
             }
@@ -624,7 +621,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
             int nCIDs = 0;
 
             if (!codeToGID && !m_useCIDs) {
-                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(tmpBuf.get(), tmpBufLen);
+                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(fontBuffer.data(), fontBuffer.size());
 
                 if (ff && ff->isOpenTypeCFF()) {
                     cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
@@ -646,7 +643,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
                     memcpy(codeToGID, ((GfxCIDFont *)gfxFont.get())->getCIDToGID(), codeToGIDLen * sizeof(int));
                 }
             } else {
-                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(tmpBuf.get(), tmpBufLen);
+                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(fontBuffer.data(), fontBuffer.size());
                 if (!ff) {
                     return;
                 }
diff --git a/qt6/src/QPainterOutputDev.cc b/qt6/src/QPainterOutputDev.cc
index 6741fce7..4c9b5306 100644
--- a/qt6/src/QPainterOutputDev.cc
+++ b/qt6/src/QPainterOutputDev.cc
@@ -462,14 +462,12 @@ void QPainterOutputDev::updateFont(GfxState *state)
             // load the font from respective location
             switch (fontLoc->locType) {
             case gfxFontLocEmbedded: { // if there is an embedded font, read it to memory
-                int fontDataLen;
-                const char *fontData = gfxFont->readEmbFontFile(xref, &fontDataLen);
+                const std::vector<unsigned char> fontData = gfxFont->readEmbFontFile(xref);
 
-                m_rawFont = new QRawFont(QByteArray(fontData, fontDataLen), fontSize, m_hintingPreference);
+                // fontData gets copied in the QByteArray constructor
+                m_rawFont = new QRawFont(QByteArray((const char *)fontData.data(), fontData.size()), fontSize, m_hintingPreference);
                 m_rawFontCache.insert(std::make_pair(fontID, std::unique_ptr<QRawFont>(m_rawFont)));
 
-                // Free the font data, it was copied in the QByteArray constructor
-                free((char *)fontData);
                 break;
             }
             case gfxFontLocExternal: { // font is in an external font file
@@ -521,8 +519,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
 
     } else {
 
-        std::unique_ptr<char[], void (*)(char *)> tmpBuf(nullptr, [](char *b) { free(b); });
-        int tmpBufLen = 0;
+        std::vector<unsigned char> fontBuffer;
 
         std::optional<GfxFontLoc> fontLoc = gfxFont->locateFont(xref, nullptr);
         if (!fontLoc) {
@@ -533,8 +530,8 @@ void QPainterOutputDev::updateFont(GfxState *state)
         // embedded font
         if (fontLoc->locType == gfxFontLocEmbedded) {
             // if there is an embedded font, read it to memory
-            tmpBuf.reset(gfxFont->readEmbFontFile(xref, &tmpBufLen));
-            if (!tmpBuf) {
+            fontBuffer = gfxFont->readEmbFontFile(xref);
+            if (fontBuffer.empty()) {
                 return;
             }
 
@@ -559,7 +556,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
                     return;
                 }
             } else {
-                if (FT_New_Memory_Face(m_ftLibrary, (const FT_Byte *)tmpBuf.get(), tmpBufLen, faceIndex, &freeTypeFace)) {
+                if (FT_New_Memory_Face(m_ftLibrary, (const FT_Byte *)fontBuffer.data(), fontBuffer.size(), faceIndex, &freeTypeFace)) {
                     error(errSyntaxError, -1, "Couldn't create a FreeType face for '{0:s}'", gfxFont->getName() ? gfxFont->getName()->c_str() : "(unnamed)");
                     return;
                 }
@@ -589,7 +586,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
         }
         case fontTrueType:
         case fontTrueTypeOT: {
-            auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(tmpBuf.get(), tmpBufLen);
+            auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(fontBuffer.data(), fontBuffer.size());
 
             m_codeToGIDCache[id] = (ff) ? ((Gfx8BitFont *)gfxFont.get())->getCodeToGIDMap(ff.get()) : nullptr;
 
@@ -602,7 +599,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
 
             // check for a CFF font
             if (!m_useCIDs) {
-                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(tmpBuf.get(), tmpBufLen));
+                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? std::unique_ptr<FoFiType1C>(FoFiType1C::load(fontLoc->path.c_str())) : std::unique_ptr<FoFiType1C>(FoFiType1C::make(fontBuffer.data(), fontBuffer.size()));
 
                 cidToGIDMap = (ff) ? ff->getCIDToGIDMap(&nCIDs) : nullptr;
             }
@@ -624,7 +621,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
             int nCIDs = 0;
 
             if (!codeToGID && !m_useCIDs) {
-                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(tmpBuf.get(), tmpBufLen);
+                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(fontBuffer.data(), fontBuffer.size());
 
                 if (ff && ff->isOpenTypeCFF()) {
                     cidToGIDMap = ff->getCIDToGIDMap(&nCIDs);
@@ -646,7 +643,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
                     memcpy(codeToGID, ((GfxCIDFont *)gfxFont.get())->getCIDToGID(), codeToGIDLen * sizeof(int));
                 }
             } else {
-                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(tmpBuf.get(), tmpBufLen);
+                auto ff = (fontLoc->locType != gfxFontLocEmbedded) ? FoFiTrueType::load(fontLoc->path.c_str()) : FoFiTrueType::make(fontBuffer.data(), fontBuffer.size());
                 if (!ff) {
                     return;
                 }
diff --git a/splash/SplashFTFontFile.cc b/splash/SplashFTFontFile.cc
index f30248dc..f9343735 100644
--- a/splash/SplashFTFontFile.cc
+++ b/splash/SplashFTFontFile.cc
@@ -46,7 +46,7 @@ SplashFontFile *SplashFTFontFile::loadType1Font(SplashFTFontEngine *engineA, Spl
             return nullptr;
         }
     } else {
-        if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA)) {
+        if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf.data(), src->buf.size(), 0, &faceA)) {
             return nullptr;
         }
     }
@@ -76,7 +76,7 @@ SplashFontFile *SplashFTFontFile::loadCIDFont(SplashFTFontEngine *engineA, Splas
             return nullptr;
         }
     } else {
-        if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, 0, &faceA)) {
+        if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf.data(), src->buf.size(), 0, &faceA)) {
             return nullptr;
         }
     }
@@ -93,7 +93,7 @@ SplashFontFile *SplashFTFontFile::loadTrueTypeFont(SplashFTFontEngine *engineA,
             return nullptr;
         }
     } else {
-        if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf, src->bufLen, faceIndexA, &faceA)) {
+        if (FT_New_Memory_Face(engineA->lib, (const FT_Byte *)src->buf.data(), src->buf.size(), faceIndexA, &faceA)) {
             return nullptr;
         }
     }
diff --git a/splash/SplashFontFile.cc b/splash/SplashFontFile.cc
index de539d49..c3eace4b 100644
--- a/splash/SplashFontFile.cc
+++ b/splash/SplashFontFile.cc
@@ -68,18 +68,10 @@ void SplashFontFile::decRefCnt()
 SplashFontSrc::SplashFontSrc()
 {
     isFile = false;
-    buf = nullptr;
     refcnt = 1;
 }
 
-SplashFontSrc::~SplashFontSrc()
-{
-    if (!isFile) {
-        if (buf) {
-            gfree(buf);
-        }
-    }
-}
+SplashFontSrc::~SplashFontSrc() = default;
 
 void SplashFontSrc::ref()
 {
@@ -99,17 +91,8 @@ void SplashFontSrc::setFile(const std::string &file)
     fileName = file;
 }
 
-void SplashFontSrc::setBuf(char *bufA, int bufLenA)
-{
-    isFile = false;
-    buf = bufA;
-    bufLen = bufLenA;
-}
-
-void SplashFontSrc::setBuf(unsigned char *bufA, int bufLenA, bool del)
+void SplashFontSrc::setBuf(std::vector<unsigned char> &&bufA)
 {
     isFile = false;
-    buf = (char *)bufA;
-    bufLen = bufLenA;
-    deleteSrc = del;
+    buf = std::move(bufA);
 }
diff --git a/splash/SplashFontFile.h b/splash/SplashFontFile.h
index 7bc67948..7f55fdf0 100644
--- a/splash/SplashFontFile.h
+++ b/splash/SplashFontFile.h
@@ -24,6 +24,7 @@
 #define SPLASHFONTFILE_H
 
 #include <string>
+#include <vector>
 
 #include "SplashTypes.h"
 #include "poppler_private_export.h"
@@ -46,15 +47,14 @@ public:
 
     void setFile(const std::string &file);
     void setBuf(char *bufA, int buflenA);
-    void setBuf(unsigned char *bufA, int buflenA);
+    void setBuf(std::vector<unsigned char> &&bufA);
 
     void ref();
     void unref();
 
     bool isFile;
     std::string fileName;
-    char *buf;
-    int bufLen;
+    std::vector<unsigned char> buf;
 
 private:
     ~SplashFontSrc();
commit d3b0fd9a76e1f6ace83b50f8c1bc9db096a8fbc7
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Mar 14 11:43:37 2022 +0100

    Simplify method _ft_new_face_uncached
    
    It is only called if there is no font in memory (font_data == nullptr).
    
    Therefore, there is no need to pass font_data to the method.

diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index c8b411cb..d1a95eed 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -148,19 +148,13 @@ static void _ft_done_face_uncached(void *closure)
     FT_Done_Face(face);
 }
 
-static bool _ft_new_face_uncached(FT_Library lib, const char *filename, unsigned char *font_data, int font_data_len, FT_Face *face_out, cairo_font_face_t **font_face_out)
+static bool _ft_new_face_uncached(FT_Library lib, const char *filename, FT_Face *face_out, cairo_font_face_t **font_face_out)
 {
     FT_Face face;
     cairo_font_face_t *font_face;
 
-    if (font_data == nullptr) {
-        if (FT_New_Face(lib, filename, 0, &face)) {
-            return false;
-        }
-    } else {
-        if (FT_New_Memory_Face(lib, font_data, font_data_len, 0, &face)) {
-            return false;
-        }
+    if (FT_New_Face(lib, filename, 0, &face)) {
+        return false;
     }
 
     font_face = cairo_ft_font_face_create_for_ft_face(face, FT_LOAD_NO_HINTING | FT_LOAD_NO_BITMAP);
@@ -239,7 +233,7 @@ static bool _ft_new_face(FT_Library lib, const char *filename, Ref embFontID, un
         /* if we fail to open the file, just pass it to FreeType instead */
         std::ifstream font_data_fstream(filename, std::ios::binary);
         if (!font_data_fstream.is_open()) {
-            return _ft_new_face_uncached(lib, filename, font_data, font_data_len, face_out, font_face_out);
+            return _ft_new_face_uncached(lib, filename, face_out, font_face_out);
         }
 
         /* get length of file */
commit 6da92d028268aa92ed955905551bcc6c5acb26e4
Author: Oliver Sander <oliver.sander at tu-dresden.de>
Date:   Mon Mar 14 09:59:02 2022 +0100

    Pass around font memory buffers as unsigned char
    
    In FoFiBase, the memory buffer for fonts is stored as unsigned char.
    At the same time, the code in Stream hands out memory as unsigned char.
    Yet, the pointers to this memory is then casted to signed char,
    and passed around as that.
    
    This commit removes some of this casting, and uses more unsigned chars.

diff --git a/fofi/FoFiBase.cc b/fofi/FoFiBase.cc
index ad14df63..b8e6627d 100644
--- a/fofi/FoFiBase.cc
+++ b/fofi/FoFiBase.cc
@@ -37,9 +37,9 @@
 // FoFiBase
 //------------------------------------------------------------------------
 
-FoFiBase::FoFiBase(const char *fileA, int lenA, bool freeFileDataA)
+FoFiBase::FoFiBase(const unsigned char *fileA, int lenA, bool freeFileDataA)
 {
-    file = (const unsigned char *)fileA;
+    file = fileA;
     len = lenA;
     freeFileData = freeFileDataA;
 }
diff --git a/fofi/FoFiBase.h b/fofi/FoFiBase.h
index 862899d4..a6d3a96b 100644
--- a/fofi/FoFiBase.h
+++ b/fofi/FoFiBase.h
@@ -40,7 +40,7 @@ public:
     virtual ~FoFiBase();
 
 protected:
-    FoFiBase(const char *fileA, int lenA, bool freeFileDataA);
+    FoFiBase(const unsigned char *fileA, int lenA, bool freeFileDataA);
     static char *readFile(const char *fileName, int *fileLen);
 
     // S = signed / U = unsigned
diff --git a/fofi/FoFiTrueType.cc b/fofi/FoFiTrueType.cc
index 349ba278..4735a4fe 100644
--- a/fofi/FoFiTrueType.cc
+++ b/fofi/FoFiTrueType.cc
@@ -451,7 +451,7 @@ static const char *macGlyphNames[258] = { ".notdef",
 // FoFiTrueType
 //------------------------------------------------------------------------
 
-std::unique_ptr<FoFiTrueType> FoFiTrueType::make(const char *fileA, int lenA, int faceIndexA)
+std::unique_ptr<FoFiTrueType> FoFiTrueType::make(const unsigned char *fileA, int lenA, int faceIndexA)
 {
     // Cannot use std::make_unique, because the constructor is private
     auto ff = new FoFiTrueType(fileA, lenA, false, faceIndexA);
@@ -471,7 +471,7 @@ std::unique_ptr<FoFiTrueType> FoFiTrueType::load(const char *fileName, int faceI
         return nullptr;
     }
     // Cannot use std::make_unique, because the constructor is private
-    auto ff = new FoFiTrueType(fileA, lenA, true, faceIndexA);
+    auto ff = new FoFiTrueType((unsigned char *)fileA, lenA, true, faceIndexA);
     if (!ff->parsedOk) {
         delete ff;
         return nullptr;
@@ -479,7 +479,7 @@ std::unique_ptr<FoFiTrueType> FoFiTrueType::load(const char *fileName, int faceI
     return std::unique_ptr<FoFiTrueType>(ff);
 }
 
-FoFiTrueType::FoFiTrueType(const char *fileA, int lenA, bool freeFileDataA, int faceIndexA) : FoFiBase(fileA, lenA, freeFileDataA)
+FoFiTrueType::FoFiTrueType(const unsigned char *fileA, int lenA, bool freeFileDataA, int faceIndexA) : FoFiBase(fileA, lenA, freeFileDataA)
 {
     tables = nullptr;
     nTables = 0;
@@ -679,7 +679,7 @@ int *FoFiTrueType::getCIDToGIDMap(int *nCIDs) const
     if (!getCFFBlock(&start, &length)) {
         return nullptr;
     }
-    if (!(ff = FoFiType1C::make(start, length))) {
+    if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
         return nullptr;
     }
     map = ff->getCIDToGIDMap(nCIDs);
@@ -721,7 +721,7 @@ void FoFiTrueType::getFontMatrix(double *mat) const
     if (!getCFFBlock(&start, &length)) {
         return;
     }
-    if (!(ff = FoFiType1C::make(start, length))) {
+    if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
         return;
     }
     ff->getFontMatrix(mat);
@@ -774,7 +774,7 @@ void FoFiTrueType::convertToType1(const char *psName, const char **newEncoding,
     if (!getCFFBlock(&start, &length)) {
         return;
     }
-    if (!(ff = FoFiType1C::make(start, length))) {
+    if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
         return;
     }
     ff->convertToType1(psName, newEncoding, ascii, outputFunc, outputStream);
@@ -909,7 +909,7 @@ void FoFiTrueType::convertToCIDType0(const char *psName, int *cidMap, int nCIDs,
     if (!getCFFBlock(&start, &length)) {
         return;
     }
-    if (!(ff = FoFiType1C::make(start, length))) {
+    if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
         return;
     }
     ff->convertToCIDType0(psName, cidMap, nCIDs, outputFunc, outputStream);
@@ -1033,7 +1033,7 @@ void FoFiTrueType::convertToType0(const char *psName, int *cidMap, int nCIDs, Fo
     if (!getCFFBlock(&start, &length)) {
         return;
     }
-    if (!(ff = FoFiType1C::make(start, length))) {
+    if (!(ff = FoFiType1C::make((unsigned char *)start, length))) {
         return;
     }
     ff->convertToType0(psName, cidMap, nCIDs, outputFunc, outputStream);
diff --git a/fofi/FoFiTrueType.h b/fofi/FoFiTrueType.h
index 908438c0..def954a6 100644
--- a/fofi/FoFiTrueType.h
+++ b/fofi/FoFiTrueType.h
@@ -47,7 +47,7 @@ class POPPLER_PRIVATE_EXPORT FoFiTrueType : public FoFiBase
 {
 public:
     // Create a FoFiTrueType object from a memory buffer.
-    static std::unique_ptr<FoFiTrueType> make(const char *fileA, int lenA, int faceIndexA = 0);
+    static std::unique_ptr<FoFiTrueType> make(const unsigned char *fileA, int lenA, int faceIndexA = 0);
 
     // Create a FoFiTrueType object from a file on disk.
     static std::unique_ptr<FoFiTrueType> load(const char *fileName, int faceIndexA = 0);
@@ -155,7 +155,7 @@ public:
     int setupGSUB(const char *scriptName, const char *languageName);
 
 private:
-    FoFiTrueType(const char *fileA, int lenA, bool freeFileDataA, int faceIndexA);
+    FoFiTrueType(const unsigned char *fileA, int lenA, bool freeFileDataA, int faceIndexA);
     void cvtEncoding(char **encoding, FoFiOutputFunc outputFunc, void *outputStream) const;
     void cvtCharStrings(char **encoding, const int *codeToGID, FoFiOutputFunc outputFunc, void *outputStream) const;
     void cvtSfnts(FoFiOutputFunc outputFunc, void *outputStream, const GooString *name, bool needVerticalMetrics, int *maxUsedGlyph) const;
diff --git a/fofi/FoFiType1.cc b/fofi/FoFiType1.cc
index ea4c8744..d498bc82 100644
--- a/fofi/FoFiType1.cc
+++ b/fofi/FoFiType1.cc
@@ -41,7 +41,7 @@
 // FoFiType1
 //------------------------------------------------------------------------
 
-FoFiType1 *FoFiType1::make(const char *fileA, int lenA)
+FoFiType1 *FoFiType1::make(const unsigned char *fileA, int lenA)
 {
     return new FoFiType1(fileA, lenA, false);
 }
@@ -54,10 +54,10 @@ FoFiType1 *FoFiType1::load(const char *fileName)
     if (!(fileA = FoFiBase::readFile(fileName, &lenA))) {
         return nullptr;
     }
-    return new FoFiType1(fileA, lenA, true);
+    return new FoFiType1((unsigned char *)fileA, lenA, true);
 }
 
-FoFiType1::FoFiType1(const char *fileA, int lenA, bool freeFileDataA) : FoFiBase(fileA, lenA, freeFileDataA)
+FoFiType1::FoFiType1(const unsigned char *fileA, int lenA, bool freeFileDataA) : FoFiBase(fileA, lenA, freeFileDataA)
 {
     name = nullptr;
     encoding = nullptr;
diff --git a/fofi/FoFiType1.h b/fofi/FoFiType1.h
index 59d54a16..06100bf3 100644
--- a/fofi/FoFiType1.h
+++ b/fofi/FoFiType1.h
@@ -33,7 +33,7 @@ class FoFiType1 : public FoFiBase
 {
 public:
     // Create a FoFiType1 object from a memory buffer.
-    static FoFiType1 *make(const char *fileA, int lenA);
+    static FoFiType1 *make(const unsigned char *fileA, int lenA);
 
     // Create a FoFiType1 object from a file on disk.
     static FoFiType1 *load(const char *fileName);
@@ -54,7 +54,7 @@ public:
     void writeEncoded(const char **newEncoding, FoFiOutputFunc outputFunc, void *outputStream) const;
 
 private:
-    FoFiType1(const char *fileA, int lenA, bool freeFileDataA);
+    FoFiType1(const unsigned char *fileA, int lenA, bool freeFileDataA);
 
     char *getNextLine(char *line) const;
     void parse();
diff --git a/fofi/FoFiType1C.cc b/fofi/FoFiType1C.cc
index 89919a4f..3e73bd85 100644
--- a/fofi/FoFiType1C.cc
+++ b/fofi/FoFiType1C.cc
@@ -45,11 +45,9 @@ static const char hexChars[17] = "0123456789ABCDEF";
 // FoFiType1C
 //------------------------------------------------------------------------
 
-FoFiType1C *FoFiType1C::make(const char *fileA, int lenA)
+FoFiType1C *FoFiType1C::make(const unsigned char *fileA, int lenA)
 {
-    FoFiType1C *ff;
-
-    ff = new FoFiType1C(fileA, lenA, false);
+    FoFiType1C *ff = new FoFiType1C(fileA, lenA, false);
     if (!ff->parse()) {
         delete ff;
         return nullptr;
@@ -66,7 +64,7 @@ FoFiType1C *FoFiType1C::load(const char *fileName)
     if (!(fileA = FoFiBase::readFile(fileName, &lenA))) {
         return nullptr;
     }
-    ff = new FoFiType1C(fileA, lenA, true);
+    ff = new FoFiType1C((unsigned char *)fileA, lenA, true);
     if (!ff->parse()) {
         delete ff;
         return nullptr;
@@ -74,7 +72,7 @@ FoFiType1C *FoFiType1C::load(const char *fileName)
     return ff;
 }
 
-FoFiType1C::FoFiType1C(const char *fileA, int lenA, bool freeFileDataA) : FoFiBase(fileA, lenA, freeFileDataA)
+FoFiType1C::FoFiType1C(const unsigned char *fileA, int lenA, bool freeFileDataA) : FoFiBase(fileA, lenA, freeFileDataA)
 {
     name = nullptr;
     encoding = nullptr;
diff --git a/fofi/FoFiType1C.h b/fofi/FoFiType1C.h
index ad7a4c3f..d2998dd6 100644
--- a/fofi/FoFiType1C.h
+++ b/fofi/FoFiType1C.h
@@ -154,7 +154,7 @@ class POPPLER_PRIVATE_EXPORT FoFiType1C : public FoFiBase
 {
 public:
     // Create a FoFiType1C object from a memory buffer.
-    static FoFiType1C *make(const char *fileA, int lenA);
+    static FoFiType1C *make(const unsigned char *fileA, int lenA);
 
     // Create a FoFiType1C object from a file on disk.
     static FoFiType1C *load(const char *fileName);
@@ -209,7 +209,7 @@ public:
     void convertToType0(const char *psName, const int *codeMap, int nCodes, FoFiOutputFunc outputFunc, void *outputStream);
 
 private:
-    FoFiType1C(const char *fileA, int lenA, bool freeFileDataA);
+    FoFiType1C(const unsigned char *fileA, int lenA, bool freeFileDataA);
     void eexecCvtGlyph(Type1CEexecBuf *eb, const char *glyphName, int offset, int nBytes, const Type1CIndex *subrIdx, const Type1CPrivateDict *pDict);
     void cvtGlyph(int offset, int nBytes, GooString *charBuf, const Type1CIndex *subrIdx, const Type1CPrivateDict *pDict, bool top, std::set<int> &offsetBeingParsed);
     void cvtGlyphWidth(bool useOp, GooString *charBuf, const Type1CPrivateDict *pDict);
diff --git a/poppler/CairoFontEngine.cc b/poppler/CairoFontEngine.cc
index 4d8609ee..c8b411cb 100644
--- a/poppler/CairoFontEngine.cc
+++ b/poppler/CairoFontEngine.cc
@@ -148,7 +148,7 @@ static void _ft_done_face_uncached(void *closure)
     FT_Done_Face(face);
 }
 
-static bool _ft_new_face_uncached(FT_Library lib, const char *filename, char *font_data, int font_data_len, FT_Face *face_out, cairo_font_face_t **font_face_out)
+static bool _ft_new_face_uncached(FT_Library lib, const char *filename, unsigned char *font_data, int font_data_len, FT_Face *face_out, cairo_font_face_t **font_face_out)
 {
     FT_Face face;
     cairo_font_face_t *font_face;
@@ -158,7 +158,7 @@ static bool _ft_new_face_uncached(FT_Library lib, const char *filename, char *fo
             return false;
         }
     } else {
-        if (FT_New_Memory_Face(lib, (unsigned char *)font_data, font_data_len, 0, &face)) {
+        if (FT_New_Memory_Face(lib, font_data, font_data_len, 0, &face)) {
             return false;
         }
     }
@@ -230,7 +230,7 @@ static void _ft_done_face(void *closure)
     delete data;
 }
 
-static bool _ft_new_face(FT_Library lib, const char *filename, Ref embFontID, char *font_data, int font_data_len, FT_Face *face_out, cairo_font_face_t **font_face_out)
+static bool _ft_new_face(FT_Library lib, const char *filename, Ref embFontID, unsigned char *font_data, int font_data_len, FT_Face *face_out, cairo_font_face_t **font_face_out)
 {
     struct _ft_face_data ft_face_data(lib, filename, embFontID);
 
@@ -246,7 +246,7 @@ static bool _ft_new_face(FT_Library lib, const char *filename, Ref embFontID, ch
         font_data_fstream.seekg(0, font_data_fstream.end);
         ft_face_data.size = font_data_fstream.tellg();
     } else {
-        ft_face_data.bytes = (unsigned char *)font_data;
+        ft_face_data.bytes = font_data;
         ft_face_data.size = font_data_len;
     }
 
@@ -302,7 +302,7 @@ CairoFreeTypeFont::~CairoFreeTypeFont() { }
 CairoFreeTypeFont *CairoFreeTypeFont::create(GfxFont *gfxFont, XRef *xref, FT_Library lib, bool useCIDs)
 {
     const char *fileNameC;
-    char *font_data;
+    unsigned char *font_data;
     int font_data_len;
     int i, n;
     GfxFontType fontType;
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index b3408c0d..48b1081c 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -830,9 +830,8 @@ std::optional<GfxFontLoc> GfxFont::getExternalFont(GooString *path, bool cid)
     return std::move(fontLoc); // std::move only required to please g++-7
 }
 
-char *GfxFont::readEmbFontFile(XRef *xref, int *len)
+unsigned char *GfxFont::readEmbFontFile(XRef *xref, int *len)
 {
-    char *buf;
     Stream *str;
 
     Object obj1(embFontID);
@@ -845,7 +844,7 @@ char *GfxFont::readEmbFontFile(XRef *xref, int *len)
     }
     str = obj2.getStream();
 
-    buf = (char *)str->toUnsignedChars(len);
+    unsigned char *buf = str->toUnsignedChars(len);
     str->close();
 
     return buf;
@@ -966,7 +965,6 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     const BuiltinFont *builtinFont;
     const char **baseEnc;
     bool baseEncFromFontFile;
-    char *buf;
     int len;
     FoFiType1 *ffT1;
     FoFiType1C *ffT1C;
@@ -1137,7 +1135,7 @@ Gfx8BitFont::Gfx8BitFont(XRef *xref, const char *tagA, Ref idA, GooString *nameA
     // TrueType font is a losing proposition)
     ffT1 = nullptr;
     ffT1C = nullptr;
-    buf = nullptr;
+    unsigned char *buf = nullptr;
     if (type == fontType1 && embFontID != Ref::INVALID()) {
         if ((buf = readEmbFontFile(xref, &len))) {
             if ((ffT1 = FoFiType1::make(buf, len))) {
diff --git a/poppler/GfxFont.h b/poppler/GfxFont.h
index 7d2666c7..e3459ba3 100644
--- a/poppler/GfxFont.h
+++ b/poppler/GfxFont.h
@@ -282,7 +282,7 @@ public:
     static std::optional<GfxFontLoc> locateBase14Font(const GooString *base14Name);
 
     // Read an external or embedded font file into a buffer.
-    char *readEmbFontFile(XRef *xref, int *len);
+    unsigned char *readEmbFontFile(XRef *xref, int *len);
 
     // Get the next char from a string <s> of <len> bytes, returning the
     // char <code>, its Unicode mapping <u>, its displacement vector
diff --git a/poppler/PSOutputDev.cc b/poppler/PSOutputDev.cc
index 2e3c9124..da12142b 100644
--- a/poppler/PSOutputDev.cc
+++ b/poppler/PSOutputDev.cc
@@ -2374,7 +2374,7 @@ void PSOutputDev::setupExternalType1Font(const GooString *fileName, GooString *p
 
 void PSOutputDev::setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    char *fontBuf;
+    unsigned char *fontBuf;
     int fontLen;
     FoFiType1C *ffT1C;
     int i;
@@ -2416,7 +2416,7 @@ void PSOutputDev::setupEmbeddedType1CFont(GfxFont *font, Ref *id, GooString *psN
 
 void PSOutputDev::setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    char *fontBuf;
+    unsigned char *fontBuf;
     int fontLen;
     int i;
 
@@ -2458,7 +2458,7 @@ void PSOutputDev::setupEmbeddedOpenTypeT1CFont(GfxFont *font, Ref *id, GooString
 
 void PSOutputDev::setupEmbeddedTrueTypeFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    char *fontBuf;
+    unsigned char *fontBuf;
     int fontLen;
     int *codeToGID;
 
@@ -2580,7 +2580,7 @@ void PSOutputDev::setupExternalCIDTrueTypeFont(GfxFont *font, const GooString *f
 
 void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *psName)
 {
-    char *fontBuf;
+    unsigned char *fontBuf;
     int fontLen;
     FoFiType1C *ffT1C;
     int i;
@@ -2628,7 +2628,7 @@ void PSOutputDev::setupEmbeddedCIDType0Font(GfxFont *font, Ref *id, GooString *p
 
 void PSOutputDev::setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString *psName, bool needVerticalMetrics)
 {
-    char *fontBuf;
+    unsigned char *fontBuf;
     int fontLen;
 
     // beginning comment
@@ -2659,7 +2659,7 @@ void PSOutputDev::setupEmbeddedCIDTrueTypeFont(GfxFont *font, Ref *id, GooString
 
 void PSOutputDev::setupEmbeddedOpenTypeCFFFont(GfxFont *font, Ref *id, GooString *psName)
 {
-    char *fontBuf;
+    unsigned char *fontBuf;
     int fontLen;
     int i;
 
diff --git a/poppler/SplashOutputDev.cc b/poppler/SplashOutputDev.cc
index 23284f6b..8f362b55 100644
--- a/poppler/SplashOutputDev.cc
+++ b/poppler/SplashOutputDev.cc
@@ -1845,7 +1845,7 @@ void SplashOutputDev::doUpdateFont(GfxState *state)
     SplashOutFontFileID *id = nullptr;
     SplashFontFile *fontFile;
     SplashFontSrc *fontsrc = nullptr;
-    char *tmpBuf;
+    unsigned char *tmpBuf;
     int tmpBufLen;
     const double *textMat;
     double m11, m12, m21, m22, fontSize;
diff --git a/qt5/src/QPainterOutputDev.cc b/qt5/src/QPainterOutputDev.cc
index 6741fce7..fce35ecb 100644
--- a/qt5/src/QPainterOutputDev.cc
+++ b/qt5/src/QPainterOutputDev.cc
@@ -463,9 +463,9 @@ void QPainterOutputDev::updateFont(GfxState *state)
             switch (fontLoc->locType) {
             case gfxFontLocEmbedded: { // if there is an embedded font, read it to memory
                 int fontDataLen;
-                const char *fontData = gfxFont->readEmbFontFile(xref, &fontDataLen);
+                const unsigned char *fontData = gfxFont->readEmbFontFile(xref, &fontDataLen);
 
-                m_rawFont = new QRawFont(QByteArray(fontData, fontDataLen), fontSize, m_hintingPreference);
+                m_rawFont = new QRawFont(QByteArray((const char *)fontData, fontDataLen), fontSize, m_hintingPreference);
                 m_rawFontCache.insert(std::make_pair(fontID, std::unique_ptr<QRawFont>(m_rawFont)));
 
                 // Free the font data, it was copied in the QByteArray constructor
@@ -521,7 +521,7 @@ void QPainterOutputDev::updateFont(GfxState *state)
 
     } else {
 
-        std::unique_ptr<char[], void (*)(char *)> tmpBuf(nullptr, [](char *b) { free(b); });
+        std::unique_ptr<unsigned char[], void (*)(unsigned char *)> tmpBuf(nullptr, [](unsigned char *b) { free(b); });
         int tmpBufLen = 0;
 
         std::optional<GfxFontLoc> fontLoc = gfxFont->locateFont(xref, nullptr);
diff --git a/splash/SplashFontFile.cc b/splash/SplashFontFile.cc
index 429858e7..de539d49 100644
--- a/splash/SplashFontFile.cc
+++ b/splash/SplashFontFile.cc
@@ -105,3 +105,11 @@ void SplashFontSrc::setBuf(char *bufA, int bufLenA)
     buf = bufA;
     bufLen = bufLenA;
 }
+
+void SplashFontSrc::setBuf(unsigned char *bufA, int bufLenA, bool del)
+{
+    isFile = false;
+    buf = (char *)bufA;
+    bufLen = bufLenA;
+    deleteSrc = del;
+}
diff --git a/splash/SplashFontFile.h b/splash/SplashFontFile.h
index 1e1e4fe1..7bc67948 100644
--- a/splash/SplashFontFile.h
+++ b/splash/SplashFontFile.h
@@ -46,6 +46,7 @@ public:
 
     void setFile(const std::string &file);
     void setBuf(char *bufA, int buflenA);
+    void setBuf(unsigned char *bufA, int buflenA);
 
     void ref();
     void unref();


More information about the poppler mailing list