1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

avcodec/mpegvideo_dec: Avoid implicit NULL + offset

Happens since 4fc874ef08
when this code is called via error resilience.
Also do the same for wmv2dec.c.
Fixes the vsynth_{1,2,3,_lena}-mpeg4-error and wmv2-drm-dec FATE-tests.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt
2025-07-03 22:32:15 +02:00
parent 9139edfdd3
commit fadadb56e6
2 changed files with 33 additions and 32 deletions

View File

@@ -851,10 +851,10 @@ unhandled:
/* add block[] to dest[] */ /* add block[] to dest[] */
static inline void add_dct(MpegEncContext *s, static inline void add_dct(MpegEncContext *s,
int16_t *block, int i, uint8_t *dest, int line_size) int16_t block[][64], int i, uint8_t *dest, int line_size)
{ {
if (s->block_last_index[i] >= 0) { if (s->block_last_index[i] >= 0) {
s->idsp.idct_add(dest, line_size, block); s->idsp.idct_add(dest, line_size, block[i]);
} }
} }
@@ -867,12 +867,12 @@ static inline void put_dct(MpegEncContext *s,
} }
static inline void add_dequant_dct(MpegEncContext *s, static inline void add_dequant_dct(MpegEncContext *s,
int16_t *block, int i, uint8_t *dest, int line_size, int qscale) int16_t block[][64], int i, uint8_t *dest, int line_size, int qscale)
{ {
if (s->block_last_index[i] >= 0) { if (s->block_last_index[i] >= 0) {
s->dct_unquantize_inter(s, block, i, qscale); s->dct_unquantize_inter(s, block[i], i, qscale);
s->idsp.idct_add(dest, line_size, block); s->idsp.idct_add(dest, line_size, block[i]);
} }
} }
@@ -959,44 +959,44 @@ void mpv_reconstruct_mb_internal(MpegEncContext *s, int16_t block[12][64],
/* add dct residue */ /* add dct residue */
if (is_mpeg12 != DEFINITELY_MPEG12_H261 && s->dct_unquantize_inter) { if (is_mpeg12 != DEFINITELY_MPEG12_H261 && s->dct_unquantize_inter) {
// H.263, H.263+, H.263I, FLV, RV10, RV20 and MPEG-4 with MPEG-2 quantization // H.263, H.263+, H.263I, FLV, RV10, RV20 and MPEG-4 with MPEG-2 quantization
add_dequant_dct(s, block[0], 0, dest_y , dct_linesize, s->qscale); add_dequant_dct(s, block, 0, dest_y , dct_linesize, s->qscale);
add_dequant_dct(s, block[1], 1, dest_y + block_size, dct_linesize, s->qscale); add_dequant_dct(s, block, 1, dest_y + block_size, dct_linesize, s->qscale);
add_dequant_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize, s->qscale); add_dequant_dct(s, block, 2, dest_y + dct_offset , dct_linesize, s->qscale);
add_dequant_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale); add_dequant_dct(s, block, 3, dest_y + dct_offset + block_size, dct_linesize, s->qscale);
if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
av_assert2(s->chroma_y_shift); av_assert2(s->chroma_y_shift);
add_dequant_dct(s, block[4], 4, dest_cb, uvlinesize, s->chroma_qscale); add_dequant_dct(s, block, 4, dest_cb, uvlinesize, s->chroma_qscale);
add_dequant_dct(s, block[5], 5, dest_cr, uvlinesize, s->chroma_qscale); add_dequant_dct(s, block, 5, dest_cr, uvlinesize, s->chroma_qscale);
} }
} else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) { } else if (is_mpeg12 == DEFINITELY_MPEG12_H261 || lowres_flag || (s->codec_id != AV_CODEC_ID_WMV2)) {
// H.261, MPEG-1, MPEG-2, MPEG-4 with H.263 quantization, // H.261, MPEG-1, MPEG-2, MPEG-4 with H.263 quantization,
// MSMP4V1-3 and WMV1. // MSMP4V1-3 and WMV1.
// Also RV30, RV40 and the VC-1 family when performing error resilience, // Also RV30, RV40 and the VC-1 family when performing error resilience,
// but all blocks are skipped in this case. // but all blocks are skipped in this case.
add_dct(s, block[0], 0, dest_y , dct_linesize); add_dct(s, block, 0, dest_y , dct_linesize);
add_dct(s, block[1], 1, dest_y + block_size, dct_linesize); add_dct(s, block, 1, dest_y + block_size, dct_linesize);
add_dct(s, block[2], 2, dest_y + dct_offset , dct_linesize); add_dct(s, block, 2, dest_y + dct_offset , dct_linesize);
add_dct(s, block[3], 3, dest_y + dct_offset + block_size, dct_linesize); add_dct(s, block, 3, dest_y + dct_offset + block_size, dct_linesize);
if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) { if (!CONFIG_GRAY || !(s->avctx->flags & AV_CODEC_FLAG_GRAY)) {
if (s->chroma_y_shift) {//Chroma420 if (s->chroma_y_shift) {//Chroma420
add_dct(s, block[4], 4, dest_cb, uvlinesize); add_dct(s, block, 4, dest_cb, uvlinesize);
add_dct(s, block[5], 5, dest_cr, uvlinesize); add_dct(s, block, 5, dest_cr, uvlinesize);
} else { } else {
//chroma422 //chroma422
dct_linesize = uvlinesize << s->interlaced_dct; dct_linesize = uvlinesize << s->interlaced_dct;
dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size; dct_offset = s->interlaced_dct ? uvlinesize : uvlinesize*block_size;
add_dct(s, block[4], 4, dest_cb, dct_linesize); add_dct(s, block, 4, dest_cb, dct_linesize);
add_dct(s, block[5], 5, dest_cr, dct_linesize); add_dct(s, block, 5, dest_cr, dct_linesize);
add_dct(s, block[6], 6, dest_cb + dct_offset, dct_linesize); add_dct(s, block, 6, dest_cb + dct_offset, dct_linesize);
add_dct(s, block[7], 7, dest_cr + dct_offset, dct_linesize); add_dct(s, block, 7, dest_cr + dct_offset, dct_linesize);
if (!s->chroma_x_shift) {//Chroma444 if (!s->chroma_x_shift) {//Chroma444
add_dct(s, block[8], 8, dest_cb + block_size, dct_linesize); add_dct(s, block, 8, dest_cb + block_size, dct_linesize);
add_dct(s, block[9], 9, dest_cr + block_size, dct_linesize); add_dct(s, block, 9, dest_cr + block_size, dct_linesize);
add_dct(s, block[10], 10, dest_cb + block_size + dct_offset, dct_linesize); add_dct(s, block, 10, dest_cb + block_size + dct_offset, dct_linesize);
add_dct(s, block[11], 11, dest_cr + block_size + dct_offset, dct_linesize); add_dct(s, block, 11, dest_cr + block_size + dct_offset, dct_linesize);
} }
} }
} //fi gray } //fi gray

View File

@@ -56,12 +56,13 @@ typedef struct WMV2DecContext {
DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64]; DECLARE_ALIGNED(32, int16_t, abt_block2)[6][64];
} WMV2DecContext; } WMV2DecContext;
static void wmv2_add_block(WMV2DecContext *w, int16_t *block1, static void wmv2_add_block(WMV2DecContext *w, int16_t blocks1[][64],
uint8_t *dst, int stride, int n) uint8_t *dst, int stride, int n)
{ {
H263DecContext *const h = &w->ms.h; H263DecContext *const h = &w->ms.h;
if (h->c.block_last_index[n] >= 0) { if (h->c.block_last_index[n] >= 0) {
int16_t *block1 = blocks1[n];
switch (w->abt_type_table[n]) { switch (w->abt_type_table[n]) {
case 0: case 0:
w->common.wdsp.idct_add(dst, stride, block1); w->common.wdsp.idct_add(dst, stride, block1);
@@ -87,16 +88,16 @@ void ff_wmv2_add_mb(MpegEncContext *s, int16_t block1[6][64],
{ {
WMV2DecContext *const w = (WMV2DecContext *) s; WMV2DecContext *const w = (WMV2DecContext *) s;
wmv2_add_block(w, block1[0], dest_y, s->linesize, 0); wmv2_add_block(w, block1, dest_y, s->linesize, 0);
wmv2_add_block(w, block1[1], dest_y + 8, s->linesize, 1); wmv2_add_block(w, block1, dest_y + 8, s->linesize, 1);
wmv2_add_block(w, block1[2], dest_y + 8 * s->linesize, s->linesize, 2); wmv2_add_block(w, block1, dest_y + 8 * s->linesize, s->linesize, 2);
wmv2_add_block(w, block1[3], dest_y + 8 + 8 * s->linesize, s->linesize, 3); wmv2_add_block(w, block1, dest_y + 8 + 8 * s->linesize, s->linesize, 3);
if (s->avctx->flags & AV_CODEC_FLAG_GRAY) if (s->avctx->flags & AV_CODEC_FLAG_GRAY)
return; return;
wmv2_add_block(w, block1[4], dest_cb, s->uvlinesize, 4); wmv2_add_block(w, block1, dest_cb, s->uvlinesize, 4);
wmv2_add_block(w, block1[5], dest_cr, s->uvlinesize, 5); wmv2_add_block(w, block1, dest_cr, s->uvlinesize, 5);
} }
static int parse_mb_skip(WMV2DecContext *w) static int parse_mb_skip(WMV2DecContext *w)