mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-28 20:53:54 +02:00
Merge commit '212c6a1d70df011b6f2a2aa02f7677503287bd00'
* commit '212c6a1d70df011b6f2a2aa02f7677503287bd00': mjpegdec: Check return values of functions that may fail Merged-by: Clément Bœsch <u@pkh.me>
This commit is contained in:
commit
9c7ee37490
@ -71,20 +71,36 @@ static int build_vlc(VLC *vlc, const uint8_t *bits_table,
|
||||
huff_code, 2, 2, huff_sym, 2, 2, use_static);
|
||||
}
|
||||
|
||||
static void build_basic_mjpeg_vlc(MJpegDecodeContext *s)
|
||||
static int build_basic_mjpeg_vlc(MJpegDecodeContext *s)
|
||||
{
|
||||
build_vlc(&s->vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
|
||||
avpriv_mjpeg_val_dc, 12, 0, 0);
|
||||
build_vlc(&s->vlcs[0][1], avpriv_mjpeg_bits_dc_chrominance,
|
||||
avpriv_mjpeg_val_dc, 12, 0, 0);
|
||||
build_vlc(&s->vlcs[1][0], avpriv_mjpeg_bits_ac_luminance,
|
||||
avpriv_mjpeg_val_ac_luminance, 251, 0, 1);
|
||||
build_vlc(&s->vlcs[1][1], avpriv_mjpeg_bits_ac_chrominance,
|
||||
avpriv_mjpeg_val_ac_chrominance, 251, 0, 1);
|
||||
build_vlc(&s->vlcs[2][0], avpriv_mjpeg_bits_ac_luminance,
|
||||
avpriv_mjpeg_val_ac_luminance, 251, 0, 0);
|
||||
build_vlc(&s->vlcs[2][1], avpriv_mjpeg_bits_ac_chrominance,
|
||||
avpriv_mjpeg_val_ac_chrominance, 251, 0, 0);
|
||||
int ret;
|
||||
|
||||
if ((ret = build_vlc(&s->vlcs[0][0], avpriv_mjpeg_bits_dc_luminance,
|
||||
avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
|
||||
return ret;
|
||||
|
||||
if ((ret = build_vlc(&s->vlcs[0][1], avpriv_mjpeg_bits_dc_chrominance,
|
||||
avpriv_mjpeg_val_dc, 12, 0, 0)) < 0)
|
||||
return ret;
|
||||
|
||||
if ((ret = build_vlc(&s->vlcs[1][0], avpriv_mjpeg_bits_ac_luminance,
|
||||
avpriv_mjpeg_val_ac_luminance, 251, 0, 1)) < 0)
|
||||
return ret;
|
||||
|
||||
if ((ret = build_vlc(&s->vlcs[1][1], avpriv_mjpeg_bits_ac_chrominance,
|
||||
avpriv_mjpeg_val_ac_chrominance, 251, 0, 1)) < 0)
|
||||
return ret;
|
||||
|
||||
if ((ret = build_vlc(&s->vlcs[2][0], avpriv_mjpeg_bits_ac_luminance,
|
||||
avpriv_mjpeg_val_ac_luminance, 251, 0, 0)) < 0)
|
||||
return ret;
|
||||
|
||||
if ((ret = build_vlc(&s->vlcs[2][1], avpriv_mjpeg_bits_ac_chrominance,
|
||||
avpriv_mjpeg_val_ac_chrominance, 251, 0, 0)) < 0)
|
||||
return ret;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void parse_avid(MJpegDecodeContext *s, uint8_t *buf, int len)
|
||||
@ -110,6 +126,7 @@ static void init_idct(AVCodecContext *avctx)
|
||||
av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
|
||||
{
|
||||
MJpegDecodeContext *s = avctx->priv_data;
|
||||
int ret;
|
||||
|
||||
if (!s->picture_ptr) {
|
||||
s->picture = av_frame_alloc();
|
||||
@ -131,11 +148,13 @@ av_cold int ff_mjpeg_decode_init(AVCodecContext *avctx)
|
||||
avctx->chroma_sample_location = AVCHROMA_LOC_CENTER;
|
||||
avctx->colorspace = AVCOL_SPC_BT470BG;
|
||||
|
||||
build_basic_mjpeg_vlc(s);
|
||||
if ((ret = build_basic_mjpeg_vlc(s)) < 0)
|
||||
return ret;
|
||||
|
||||
if (s->extern_huff) {
|
||||
av_log(avctx, AV_LOG_INFO, "using external huffman table\n");
|
||||
init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8);
|
||||
if ((ret = init_get_bits(&s->gb, avctx->extradata, avctx->extradata_size * 8)) < 0)
|
||||
return ret;
|
||||
if (ff_mjpeg_decode_dht(s)) {
|
||||
av_log(avctx, AV_LOG_ERROR,
|
||||
"error using external huffman table, switching back to internal\n");
|
||||
@ -307,7 +326,7 @@ int ff_mjpeg_decode_sof(MJpegDecodeContext *s)
|
||||
height= s->height;
|
||||
|
||||
av_log(s->avctx, AV_LOG_DEBUG, "sof0: picture: %dx%d\n", width, height);
|
||||
if (av_image_check_size(width, height, 0, s->avctx))
|
||||
if (av_image_check_size(width, height, 0, s->avctx) < 0)
|
||||
return AVERROR_INVALIDDATA;
|
||||
|
||||
nb_components = get_bits(&s->gb, 8);
|
||||
@ -969,6 +988,9 @@ static int ljpeg_decode_rgb_scan(MJpegDecodeContext *s, int nb_components, int p
|
||||
|
||||
av_fast_malloc(&s->ljpeg_buffer, &s->ljpeg_buffer_size,
|
||||
(unsigned)s->mb_width * 4 * sizeof(s->ljpeg_buffer[0][0]));
|
||||
if (!s->ljpeg_buffer)
|
||||
return AVERROR(ENOMEM);
|
||||
|
||||
buffer = s->ljpeg_buffer;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
@ -2116,19 +2138,22 @@ int ff_mjpeg_decode_frame(AVCodecContext *avctx, void *data, int *got_frame,
|
||||
av_log(avctx, AV_LOG_DEBUG, "startcode: %X\n", start_code);
|
||||
|
||||
/* process markers */
|
||||
if (start_code >= 0xd0 && start_code <= 0xd7)
|
||||
if (start_code >= 0xd0 && start_code <= 0xd7) {
|
||||
av_log(avctx, AV_LOG_DEBUG,
|
||||
"restart marker: %d\n", start_code & 0x0f);
|
||||
/* APP fields */
|
||||
else if (start_code >= APP0 && start_code <= APP15)
|
||||
mjpeg_decode_app(s);
|
||||
} else if (start_code >= APP0 && start_code <= APP15) {
|
||||
if ((ret = mjpeg_decode_app(s)) < 0)
|
||||
return ret;
|
||||
/* Comment */
|
||||
else if (start_code == COM) {
|
||||
} else if (start_code == COM) {
|
||||
ret = mjpeg_decode_com(s);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
} else if (start_code == DQT) {
|
||||
ff_mjpeg_decode_dqt(s);
|
||||
ret = ff_mjpeg_decode_dqt(s);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = -1;
|
||||
@ -2256,7 +2281,8 @@ eoi_parser:
|
||||
goto fail;
|
||||
break;
|
||||
case DRI:
|
||||
mjpeg_decode_dri(s);
|
||||
if ((ret = mjpeg_decode_dri(s)) < 0)
|
||||
return ret;
|
||||
break;
|
||||
case SOF5:
|
||||
case SOF6:
|
||||
|
Loading…
Reference in New Issue
Block a user