about summary refs log tree commit diff
path: root/converter/pbm
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-02-17 03:39:44 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2018-02-17 03:39:44 +0000
commitcb67625e5a190c8dcc106efc2fbb0499fa563d11 (patch)
tree8d0658bbe13a53de828806793cca5c0cfb3efc4b /converter/pbm
parent98d2c5f4e801093a3c81d2ab200ead5a2c4eabf7 (diff)
downloadnetpbm-mirror-cb67625e5a190c8dcc106efc2fbb0499fa563d11.tar.gz
netpbm-mirror-cb67625e5a190c8dcc106efc2fbb0499fa563d11.tar.xz
netpbm-mirror-cb67625e5a190c8dcc106efc2fbb0499fa563d11.zip
Fix handling of unexpected EOF in input
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@3153 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'converter/pbm')
-rw-r--r--converter/pbm/mrftopbm.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/converter/pbm/mrftopbm.c b/converter/pbm/mrftopbm.c
index 51281028..32f36ef3 100644
--- a/converter/pbm/mrftopbm.c
+++ b/converter/pbm/mrftopbm.c
@@ -31,7 +31,12 @@ bit_init(void) {
 static int 
 bit_input(FILE * const in) {
     if (bitsleft == 0)   {
-        bitbox = fgetc(in);
+        int rc;
+        rc = fgetc(in);
+        if (rc == EOF)
+            pm_error("Unexpected EOF reading image data.");
+
+        bitbox = rc;
         bitsleft = 8;
     }
     --bitsleft;
@@ -133,11 +138,15 @@ readMrfImage(FILE *           const ifP,
     unsigned int w64, h64;
 
     unsigned char * image;
+    unsigned int bytesRead;
 
-    fread(buf, 1, 13, ifP);
+    bytesRead = fread(buf, 1, 13, ifP);
+    if (bytesRead != 13)
+        pm_error("Input in not an MRF image.  We know this because it is less "
+                 "than 13 bytes, the size of an MRF header");
 
     if (memcmp(buf, "MRF1", 4) != 0)
-        pm_error("Input is not an mrf image.  "
+        pm_error("Input is not an MRF image.  "
                  "We know this because it does not start with 'MRF1'.");
 
     if (buf[12] != 0)