[poppler] fofi/FoFiBase.cc poppler/GfxFont.cc

Albert Astals Cid aacid at kemper.freedesktop.org
Sat Mar 22 05:56:23 PDT 2008


 fofi/FoFiBase.cc   |   14 ++++++++++++--
 poppler/GfxFont.cc |   12 ++++++++++--
 2 files changed, 22 insertions(+), 4 deletions(-)

New commits:
commit 23b6475463f8973b5ac83bb21a6b7b6000cc435b
Author: Ed Avis <eda at waniasset.com>
Date:   Sat Mar 22 13:55:59 2008 +0100

    Check for fseek return values

diff --git a/fofi/FoFiBase.cc b/fofi/FoFiBase.cc
index ef8992a..1174f3a 100644
--- a/fofi/FoFiBase.cc
+++ b/fofi/FoFiBase.cc
@@ -14,6 +14,7 @@
 
 #include <stdio.h>
 #include "goo/gmem.h"
+#include "Error.h"
 #include "FoFiBase.h"
 
 //------------------------------------------------------------------------
@@ -38,11 +39,20 @@ char *FoFiBase::readFile(char *fileName, int *fileLen) {
   int n;
 
   if (!(f = fopen(fileName, "rb"))) {
+    error(-1, "Cannot open '%s'", fileName);
+    return NULL;
+  }
+  if (fseek(f, 0, SEEK_END) != 0) {
+    error(-1, "Cannot seek to end of '%s'", fileName);
+    fclose(f);
     return NULL;
   }
-  fseek(f, 0, SEEK_END);
   n = (int)ftell(f);
-  fseek(f, 0, SEEK_SET);
+  if (fseek(f, 0, SEEK_SET) != 0) {
+    error(-1, "Cannot seek to start of '%s'", fileName);
+    fclose(f);
+    return NULL;
+  }
   buf = (char *)gmalloc(n);
   if ((int)fread(buf, 1, n, f) != n) {
     gfree(buf);
diff --git a/poppler/GfxFont.cc b/poppler/GfxFont.cc
index 655e259..d4c2170 100644
--- a/poppler/GfxFont.cc
+++ b/poppler/GfxFont.cc
@@ -408,9 +408,17 @@ char *GfxFont::readExtFontFile(int *len) {
     error(-1, "External font file '%s' vanished", extFontFile->getCString());
     return NULL;
   }
-  fseek(f, 0, SEEK_END);
+  if (fseek(f, 0, SEEK_END) != 0) {
+    error(-1, "Cannot seek to end of '%s'", extFontFile->getCString());
+    fclose(f);
+    return NULL;
+  }
   *len = (int)ftell(f);
-  fseek(f, 0, SEEK_SET);
+  if (fseek(f, 0, SEEK_SET) != 0) {
+    error(-1, "Cannot seek to start of '%s'", extFontFile->getCString());
+    fclose(f);
+    return NULL;
+  }
   buf = (char *)gmalloc(*len);
   if ((int)fread(buf, 1, *len, f) != *len) {
     error(-1, "Error reading external font file '%s'",


More information about the poppler mailing list