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.
Unified · Split
| @@ -92,10 +92,10 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size) · 91 unmodified lines | ||
| 92 | 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 | 97 | uint64_t channel_mask = 0; |
| 98 | − int frame_type, i; | |
| 98 | + int frame_type, i, ret; | |
| 99 | 99 | |
| 100 | 100 | s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS); |
| 101 | 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 | 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 | 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 | 141 | if (ret < 0) |
| 136 | 142 | return AVERROR_INVALIDDATA; |
| 137 | 143 | |
| 138 | − tak_parse_streaminfo(s, &gb); | |
| 139 | − | |
| 140 | − return 0; | |
| 144 | + return tak_parse_streaminfo(s, &gb); | |
| 141 | 145 | } |
| 142 | 146 | |
| 143 | 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 | 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 | 170 | if (get_bits(gb, 6)) |
| 165 | 171 | skip_bits(gb, 25); |