X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmxpegdec.c;h=8283a3976a6dff40e5879fc75f7ead9f6473a09d;hb=a247ac640df3da573cd661065bf53f37863e2b46;hp=2e3ebe6e70ec620d887295b0a455484bf0aa4843;hpb=5ca7eb36b7353f9e6af05a5a952eead5f6d326dd;p=ffmpeg diff --git a/libavcodec/mxpegdec.c b/libavcodec/mxpegdec.c index 2e3ebe6e70e..8283a3976a6 100644 --- a/libavcodec/mxpegdec.c +++ b/libavcodec/mxpegdec.c @@ -67,10 +67,8 @@ static av_cold int mxpeg_decode_init(AVCodecContext *avctx) s->picture[0] = av_frame_alloc(); s->picture[1] = av_frame_alloc(); - if (!s->picture[0] || !s->picture[1]) { - mxpeg_decode_end(avctx); + if (!s->picture[0] || !s->picture[1]) return AVERROR(ENOMEM); - } s->jpg.picture_ptr = s->picture[0]; return ff_mjpeg_decode_init(avctx); @@ -199,6 +197,7 @@ static int mxpeg_decode_frame(AVCodecContext *avctx, buf_end = buf + buf_size; jpg->got_picture = 0; s->got_mxm_bitmask = 0; + jpg->seen_sof = s->got_sof_data = !!s->got_sof_data; while (buf_ptr < buf_end) { start_code = ff_mjpeg_find_marker(jpg, &buf_ptr, buf_end, &unescaped_buf_ptr, &unescaped_buf_size); @@ -241,19 +240,25 @@ static int mxpeg_decode_frame(AVCodecContext *avctx, return ret; break; case SOF0: - s->got_sof_data = 0; + if (s->got_sof_data > 1) { + av_log(avctx, AV_LOG_ERROR, + "Multiple SOF in a frame\n"); + return AVERROR_INVALIDDATA; + } ret = ff_mjpeg_decode_sof(jpg); if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "SOF data decode error\n"); + s->got_sof_data = 0; return ret; } if (jpg->interlaced) { av_log(avctx, AV_LOG_ERROR, "Interlaced mode not supported in MxPEG\n"); + s->got_sof_data = 0; return AVERROR(EINVAL); } - s->got_sof_data = 1; + s->got_sof_data ++; break; case SOS: if (!s->got_sof_data) { @@ -334,7 +339,7 @@ the_end: return buf_ptr - buf; } -AVCodec ff_mxpeg_decoder = { +const AVCodec ff_mxpeg_decoder = { .name = "mxpeg", .long_name = NULL_IF_CONFIG_SMALL("Mobotix MxPEG video"), .type = AVMEDIA_TYPE_VIDEO, @@ -345,5 +350,5 @@ AVCodec ff_mxpeg_decoder = { .decode = mxpeg_decode_frame, .capabilities = AV_CODEC_CAP_DR1, .max_lowres = 3, - .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE, + .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, };