Fix assert failure. Fix #11666.
Unified · Split
| @@ -1983,7 +1983,19 @@ static unsigned klv_fill_size(uint64_t size) · 1982 unmodified lines | |||
| 1983 | return pad & (KAG_SIZE-1); | 1983 | return pad & (KAG_SIZE-1); |
| 1984 | } | 1984 | } |
| 1985 | 1985 | ||
| 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) | ||
| 1987 | { | 1999 | { |
| 1988 | MXFContext *mxf = s->priv_data; | 2000 | MXFContext *mxf = s->priv_data; |
| 1989 | AVIOContext *pb = s->pb; | 2001 | AVIOContext *pb = s->pb; |
| @@ -1992,11 +2004,12 @@ static void mxf_write_index_table_segment(AVFormatContext *s) · 2 unmodified lines | |||
| 1992 | int prev_non_b_picture = 0; | 2004 | int prev_non_b_picture = 0; |
| 1993 | int audio_frame_size = 0; | 2005 | int audio_frame_size = 0; |
| 1994 | int64_t pos; | 2006 | int64_t pos; |
| 2007 | int err; | ||
| 1995 | 2008 | ||
| 1996 | av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count); | 2009 | av_log(s, AV_LOG_DEBUG, "edit units count %d\n", mxf->edit_units_count); |
| 1997 | 2010 | ||
| 1998 | if (!mxf->edit_units_count && !mxf->edit_unit_byte_count) | 2011 | if (!mxf->edit_units_count && !mxf->edit_unit_byte_count) |
| 1999 | return; | 2012 | return 0; |
| 2000 | 2013 | ||
| 2001 | avio_write(pb, index_table_segment_key, 16); | 2014 | avio_write(pb, index_table_segment_key, 16); |
| 2002 | 2015 | ||
| @@ -2095,15 +2108,26 @@ static void mxf_write_index_table_segment(AVFormatContext *s) · 92 unmodified lines | |||
| 2095 | if (j == mxf->edit_units_count) | 2108 | if (j == mxf->edit_units_count) |
| 2096 | av_log(s, AV_LOG_WARNING, "missing frames\n"); | 2109 | av_log(s, AV_LOG_WARNING, "missing frames\n"); |
| 2097 | temporal_offset = j - key_index - pic_num_in_gop; | 2110 | 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; | ||
| 2098 | } | 2114 | } |
| 2099 | } | 2115 | } |
| 2100 | avio_w8(pb, temporal_offset); | 2116 | avio_w8(pb, temporal_offset); |
| 2101 | 2117 | ||
| 2102 | if ((mxf->index_entries[i].flags & 0x30) == 0x30) { // back and forward prediction | 2118 | 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; | ||
| 2103 | sc->b_picture_count = FFMAX(sc->b_picture_count, i - prev_non_b_picture); | 2123 | 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); |
| 2105 | } else { | 2125 | } 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 | ||
| 2107 | if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward | 2131 | if ((mxf->index_entries[i].flags & 0x20) == 0x20) // only forward |
| 2108 | mxf->last_key_index = key_index; | 2132 | mxf->last_key_index = key_index; |
| 2109 | prev_non_b_picture = i; | 2133 | prev_non_b_picture = i; |
| @@ -2127,6 +2151,8 @@ static void mxf_write_index_table_segment(AVFormatContext *s) · 17 unmodified lines | |||
| 2127 | } | 2151 | } |
| 2128 | 2152 | ||
| 2129 | mxf_update_klv_size(pb, pos); | 2153 | mxf_update_klv_size(pb, pos); |
| 2154 | |||
| 2155 | return 0; | ||
| 2130 | } | 2156 | } |
| 2131 | 2157 | ||
| 2132 | static void mxf_write_klv_fill(AVFormatContext *s) | 2158 | static void mxf_write_klv_fill(AVFormatContext *s) |
| @@ -3354,7 +3380,9 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) · 1221 unmodified lines | |||
| 3354 | if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0) | 3380 | if ((err = mxf_write_partition(s, 1, 2, header_open_partition_key, 1)) < 0) |
| 3355 | return err; | 3381 | return err; |
| 3356 | mxf_write_klv_fill(s); | 3382 | 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; | ||
| 3358 | } else { | 3386 | } else { |
| 3359 | if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0) | 3387 | if ((err = mxf_write_partition(s, 0, 0, header_open_partition_key, 1)) < 0) |
| 3360 | return err; | 3388 | return err; |
| @@ -3370,7 +3398,9 @@ static int mxf_write_packet(AVFormatContext *s, AVPacket *pkt) · 9 unmodified lines | |||
| 3370 | if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0) | 3398 | if ((err = mxf_write_partition(s, 1, 2, body_partition_key, 0)) < 0) |
| 3371 | return err; | 3399 | return err; |
| 3372 | mxf_write_klv_fill(s); | 3400 | 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; | ||
| 3374 | } | 3404 | } |
| 3375 | 3405 | ||
| 3376 | mxf_write_klv_fill(s); | 3406 | mxf_write_klv_fill(s); |
| @@ -3455,7 +3485,9 @@ static int mxf_write_footer(AVFormatContext *s) · 78 unmodified lines | |||
| 3455 | if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0) | 3485 | if ((err = mxf_write_partition(s, 0, 2, footer_partition_key, 0)) < 0) |
| 3456 | return err; | 3486 | return err; |
| 3457 | mxf_write_klv_fill(s); | 3487 | 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; | ||
| 3459 | } | 3491 | } |
| 3460 | 3492 | ||
| 3461 | mxf_write_klv_fill(s); | 3493 | mxf_write_klv_fill(s); |
| @@ -3474,7 +3506,9 @@ static int mxf_write_footer(AVFormatContext *s) · 12 unmodified lines | |||
| 3474 | if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0) | 3506 | if ((err = mxf_write_partition(s, 1, 2, header_closed_partition_key, 1)) < 0) |
| 3475 | return err; | 3507 | return err; |
| 3476 | mxf_write_klv_fill(s); | 3508 | 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; | ||
| 3478 | } else { | 3512 | } else { |
| 3479 | if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0) | 3513 | if ((err = mxf_write_partition(s, 0, 0, header_closed_partition_key, 1)) < 0) |
| 3480 | return err; | 3514 | return err; |