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

ib subversion at mplayerhq.hu
Tue Apr 5 15:12:36 CEST 2011


Author: ib
Date: Tue Apr  5 15:12:36 2011
New Revision: 33222

Log:
Prevent segmentation faults.

Check alloc pointers. Besides, issue debug messages.

Modified:
   trunk/gui/util/bitmap.c

Modified: trunk/gui/util/bitmap.c
==============================================================================
--- trunk/gui/util/bitmap.c	Tue Apr  5 14:50:56 2011	(r33221)
+++ trunk/gui/util/bitmap.c	Tue Apr  5 15:12:36 2011	(r33222)
@@ -34,7 +34,7 @@ static int pngRead(unsigned char *fname,
     FILE *file;
     long len;
     void *data;
-    int decode_ok;
+    int decode_ok, bpl;
     AVCodecContext *avctx;
     AVFrame *frame;
     AVPacket pkt;
@@ -57,6 +57,12 @@ static int pngRead(unsigned char *fname,
 
     data = av_malloc(len + FF_INPUT_BUFFER_PADDING_SIZE);
 
+    if (!data) {
+        fclose(file);
+        mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", len + FF_INPUT_BUFFER_PADDING_SIZE);
+        return 3;
+    }
+
     fseek(file, 0, SEEK_SET);
     fread(data, len, 1, file);
     fclose(file);
@@ -98,14 +104,14 @@ static int pngRead(unsigned char *fname,
     }
 
     if (decode_ok && bf->BPP) {
-        int bpl;
-
         bf->Width  = avctx->width;
         bf->Height = avctx->height;
         bpl = bf->Width * (bf->BPP / 8);
         bf->ImageSize = bpl * bf->Height;
         bf->Image     = malloc(bf->ImageSize);
-        memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]);
+
+        if (bf->Image)
+            memcpy_pic(bf->Image, frame->data[0], bpl, bf->Height, bpl, frame->linesize[0]);
     }
 
     avcodec_close(avctx);
@@ -113,6 +119,11 @@ static int pngRead(unsigned char *fname,
     av_freep(&avctx);
     av_freep(&data);
 
+    if (decode_ok && bf->BPP && !bf->Image) {
+        mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] not enough memory: %lu\n", bf->ImageSize);
+        return 4;
+    }
+
     mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap] file: %s\n", fname);
     mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap]  size: %lux%lu, color depth: %u\n", bf->Width, bf->Height, bf->BPP);
     mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[bitmap]  image size: %lu\n", bf->ImageSize);


More information about the MPlayer-cvslog mailing list