# HG changeset patch # User ib # Date 1302009156 0 # Node ID 36fdc061b4a813b2c4c4c08c50f623ff86c17cea # Parent ffe524b8b8f31c5c14dc728e7ee8afc256e10be4 Prevent segmentation faults. Check alloc pointers. Besides, issue debug messages. diff -r ffe524b8b8f3 -r 36fdc061b4a8 gui/util/bitmap.c --- a/gui/util/bitmap.c Tue Apr 05 12:50:56 2011 +0000 +++ b/gui/util/bitmap.c Tue Apr 05 13:12:36 2011 +0000 @@ -34,7 +34,7 @@ FILE *file; long len; void *data; - int decode_ok; + int decode_ok, bpl; AVCodecContext *avctx; AVFrame *frame; AVPacket pkt; @@ -57,6 +57,12 @@ 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 @@ } 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 @@ 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);