When tak_get_nb_samples() fails, it will currently write AVERROR_INVALIDDATA as TAKStreamInfo.frame_samples. The parser will then use this negative value as a frame duration, which leads to various breakage. Avoid this by returning the error code from tak_parse_streaminfo() directly; never store negative values in the parsed header.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -92,10 +92,10 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size) · 91 unmodified lines | |||
| 92 | return 0; | 92 | return 0; |
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) | 95 | static int tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) |
| 96 | { | 96 | { |
| 97 | uint64_t channel_mask = 0; | 97 | uint64_t channel_mask = 0; |
| 98 | int frame_type, i; | 98 | int frame_type, i, ret; |
| 99 | 99 | ||
| 100 | s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS); | 100 | s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS); |
| 101 | skip_bits(gb, TAK_ENCODER_PROFILE_BITS); | 101 | skip_bits(gb, TAK_ENCODER_PROFILE_BITS); |
| @@ -124,7 +124,13 @@ static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) · 22 unmodified lines | |||
| 124 | } | 124 | } |
| 125 | 125 | ||
| 126 | s->ch_layout = channel_mask; | 126 | s->ch_layout = channel_mask; |
| 127 | s->frame_samples = tak_get_nb_samples(s->sample_rate, frame_type); | 127 | |
| 128 | ret = tak_get_nb_samples(s->sample_rate, frame_type); | ||
| 129 | if (ret < 0) | ||
| 130 | return ret; | ||
| 131 | s->frame_samples = ret; | ||
| 132 | |||
| 133 | return 0; | ||
| 128 | } | 134 | } |
| 129 | 135 | ||
| 130 | int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size) | 136 | int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size) |
| @@ -135,9 +141,7 @@ int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size) · 4 unmodified lines | |||
| 135 | if (ret < 0) | 141 | if (ret < 0) |
| 136 | return AVERROR_INVALIDDATA; | 142 | return AVERROR_INVALIDDATA; |
| 137 | 143 | ||
| 138 | tak_parse_streaminfo(s, &gb); | 144 | return tak_parse_streaminfo(s, &gb); |
| 139 | |||
| 140 | return 0; | ||
| 141 | } | 145 | } |
| 142 | 146 | ||
| 143 | int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, | 147 | int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, |
| @@ -159,7 +163,9 @@ int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb, · 15 unmodified lines | |||
| 159 | } | 163 | } |
| 160 | 164 | ||
| 161 | if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) { | 165 | if (ti->flags & TAK_FRAME_FLAG_HAS_INFO) { |
| 162 | tak_parse_streaminfo(ti, gb); | 166 | int ret = tak_parse_streaminfo(ti, gb); |
| 167 | if (ret < 0) | ||
| 168 | return ret; | ||
| 163 | 169 | ||
| 164 | if (get_bits(gb, 6)) | 170 | if (get_bits(gb, 6)) |
| 165 | skip_bits(gb, 25); | 171 | skip_bits(gb, 25); |