[MPlayer-cvslog] r35453 - trunk/gui/util/bitmap.c

ib subversion at mplayerhq.hu
Fri Nov 23 11:24:10 CET 2012


Author: ib
Date: Fri Nov 23 11:24:10 2012
New Revision: 35453

Log:
Check return value after reading file.

Reading may fail.

Additionally, adjust error codes.

Modified:
   trunk/gui/util/bitmap.c

Modified: trunk/gui/util/bitmap.c
==============================================================================
--- trunk/gui/util/bitmap.c	Fri Nov 23 11:15:43 2012	(r35452)
+++ trunk/gui/util/bitmap.c	Fri Nov 23 11:24:10 2012	(r35453)
@@ -42,12 +42,12 @@
  * @param img pointer suitable to store the image data
  *
  * @return 0 (ok), 1 (decoding error), 2 (open error), 3 (file too big),
- *                 4 (out of memory), 5 (avcodec alloc error)
+ *                 4 (out of memory), 5 (read error), 6 (avcodec alloc error)
  */
 static int pngRead(const char *fname, guiImage *img)
 {
     FILE *file;
-    size_t len;
+    size_t len, l;
     void *data;
     int decode_ok, bpl;
     AVCodecContext *avctx;
@@ -75,9 +75,14 @@ static int pngRead(const char *fname, gu
     }
 
     fseek(file, 0, SEEK_SET);
-    fread(data, len, 1, file);
+    l = fread(data, len, 1, file);
     fclose(file);
 
+    if (l != 1) {
+        av_free(data);
+        return 5;
+    }
+
     avctx = avcodec_alloc_context3(NULL);
     frame = avcodec_alloc_frame();
 
@@ -85,7 +90,7 @@ static int pngRead(const char *fname, gu
         av_free(frame);
         av_free(avctx);
         av_free(data);
-        return 5;
+        return 6;
     }
 
     avcodec_register_all();


More information about the MPlayer-cvslog mailing list