mjpegdec: Properly fail on malloc failure

Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: Anton Khirnov <anton@khirnov.net>
This commit is contained in:
Derek Buitenhuis 2016-05-09 13:59:51 +01:00 committed by Anton Khirnov
parent 85ce9636e4
commit d68fb14758

View File

@ -1327,9 +1327,11 @@ static int mjpeg_decode_com(MJpegDecodeContext *s)
{
int len = get_bits(&s->gb, 16);
if (len >= 2 && 8 * len - 16 <= get_bits_left(&s->gb)) {
char *cbuf = av_malloc(len - 1);
if (cbuf) {
int i;
char *cbuf = av_malloc(len - 1);
if (!cbuf)
return AVERROR(ENOMEM);
for (i = 0; i < len - 2; i++)
cbuf[i] = get_bits(&s->gb, 8);
if (i > 0 && cbuf[i - 1] == '\n')
@ -1351,7 +1353,6 @@ static int mjpeg_decode_com(MJpegDecodeContext *s)
av_free(cbuf);
}
}
return 0;
}
@ -1525,8 +1526,11 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
else if (start_code >= APP0 && start_code <= APP15)
mjpeg_decode_app(s);
/* Comment */
else if (start_code == COM)
mjpeg_decode_com(s);
else if (start_code == COM) {
ret = mjpeg_decode_com(s);
if (ret < 0)
return ret;
}
if (!CONFIG_JPEGLS_DECODER &&
(start_code == SOF48 || start_code == LSE)) {