History

avformat/mxfenc: Ensure frame offset in valid range

Fix assert failure. Fix #11666.

Zhao Zhili committed 1 year ago

Commit 631bb6c1 parent dc0ac811 file · +42 −8Browse files

Unified · Split

libavformat/mxfenc.c+42−8
@@ -1983,7 +1983,19 @@ static unsigned klv_fill_size(uint64_t size) · 1982 unmodified lines
19831983 return pad & (KAG_SIZE-1);
19841984 }
19851985
1986−static void mxf_write_index_table_segment(AVFormatContext *s)
1986+static int mxf_check_frame_offset(AVFormatContext *s, int offset)
1987+{
1988+ if (offset >= INT8_MIN && offset <= INT8_MAX)
1989+ return 0;
1990+
1991+ av_log(s, AV_LOG_ERROR, "Current implementation requires frame offset (%d) "
1992+ "to be within the range of [%d,%d]. Please reduce encoder GOP size, "
1993+ "or add support for wider frame offset ranges.\n",
1994+ offset, INT8_MIN, INT8_MAX);
1995+ return AVERROR_PATCHWELCOME;
1996+}
1997+
1998+static int mxf_write_index_table_segment(AVFormatContext *s)
19871999 {
19882000 MXFContext *mxf = s->priv_data;
19892001 AVIOContext *pb = s->pb;
@@ -1992,11 +2004,12 @@ static void mxf_write_index_table_segment(AVFormatContext *s) · 2 unmodified lines
19922004 int prev_non_b_picture = 0;
19932005 int audio_frame_size = 0;
19942006 int64_t pos;
2007+ int err;
19952008
19962009 av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count);
19972010
19982011 if (!mxf->edit_units_count && !mxf->edit_unit_byte_count)
1999− return;
2012+ return 0;
20002013
20012014 avio_write(pb, index_table_segment_key, 16);
20022015
@@ -2095,15 +2108,26 @@ static void mxf_write_index_table_segment(AVFormatContext *s) · 92 unmodified lines
20952108 if (j == mxf->edit_units_count)
20962109 av_log(s, AV_LOG_WARNING, "missing frames\n");
20972110 temporal_offset = j - key_index - pic_num_in_gop;
2111+ err = mxf_check_frame_offset(s, temporal_offset);
2112+ if (err < 0)
2113+ return err;
20982114 }
20992115 }
21002116 avio_w8(pb, temporal_offset);
21012117
21022118 if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction
2119+ int offset = mxf->last_key_index - i;
2120+ err = mxf_check_frame_offset(s, offset);
2121+ if (err < 0)
2122+ return err;
21032123 sc->b_picture_count = FFMAX(sc->b_picture_count, i - prev_non_b_picture);
2104− avio_w8(pb, mxf->last_key_index - i);
2124+ avio_w8(pb, offset);
21052125 } else {
2106− avio_w8(pb, key_index - i); // key frame offset
2126+ int offset = key_index - i;
2127+ err = mxf_check_frame_offset(s, offset);
2128+ if (err < 0)
2129+ return err;
2130+ avio_w8(pb, offset); // key frame offset
21072131 if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward
21082132 mxf->last_key_index = key_index;
21092133 prev_non_b_picture = i;
@@ -2127,6 +2151,8 @@ static void mxf_write_index_table_segment(AVFormatContext *s) · 17 unmodified lines
21272151 }
21282152
21292153 mxf_update_klv_size(pb, pos);
2154+
2155+ return 0;
21302156 }
21312157
21322158 static void mxf_write_klv_fill(AVFormatContext *s)
@@ -3354,7 +3380,9 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) · 1221 unmodified lines
33543380 if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0)
33553381 return err;
33563382 mxf_write_klv_fill(s);
3357− mxf_write_index_table_segment(s);
3383+ err = mxf_write_index_table_segment(s);
3384+ if (err < 0)
3385+ return err;
33583386 } else {
33593387 if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0)
33603388 return err;
@@ -3370,7 +3398,9 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) · 9 unmodified lines
33703398 if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0)
33713399 return err;
33723400 mxf_write_klv_fill(s);
3373− mxf_write_index_table_segment(s);
3401+ err = mxf_write_index_table_segment(s);
3402+ if (err < 0)
3403+ return err;
33743404 }
33753405
33763406 mxf_write_klv_fill(s);
@@ -3455,7 +3485,9 @@ static int mxf_write_footer(AVFormatContext *s) · 78 unmodified lines
34553485 if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0)
34563486 return err;
34573487 mxf_write_klv_fill(s);
3458− mxf_write_index_table_segment(s);
3488+ err = mxf_write_index_table_segment(s);
3489+ if (err < 0)
3490+ return err;
34593491 }
34603492
34613493 mxf_write_klv_fill(s);
@@ -3474,7 +3506,9 @@ static int mxf_write_footer(AVFormatContext *s) · 12 unmodified lines
34743506 if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0)
34753507 return err;
34763508 mxf_write_klv_fill(s);
3477− mxf_write_index_table_segment(s);
3509+ err = mxf_write_index_table_segment(s);
3510+ if (err < 0)
3511+ return err;
34783512 } else {
34793513 if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0)
34803514 return err;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t