History

lavc/tak: do not store invalid values in stream info

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.

Anton Khirnov committed 3 years ago

Commit a59b4ac1 parent ecdf1ac1 file · +13 −7Browse files

Unified · Split

libavcodec/tak.c+13−7
@@ -92,10 +92,10 @@ int ff_tak_check_crc(const uint8_t *buf, unsigned int buf_size) · 91 unmodified lines
9292 return 0;
9393 }
9494
95−static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb)
95+static int tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb)
9696 {
9797 uint64_t channel_mask = 0;
98− int frame_type, i;
98+ int frame_type, i, ret;
9999
100100 s->codec = get_bits(gb, TAK_ENCODER_CODEC_BITS);
101101 skip_bits(gb, TAK_ENCODER_PROFILE_BITS);
@@ -124,7 +124,13 @@ static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb) · 22 unmodified lines
124124 }
125125
126126 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;
128134 }
129135
130136 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
135141 if (ret < 0)
136142 return AVERROR_INVALIDDATA;
137143
138− tak_parse_streaminfo(s, &gb);
139−
140− return 0;
144+ return tak_parse_streaminfo(s, &gb);
141145 }
142146
143147 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
159163 }
160164
161165 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;
163169
164170 if (get_bits(gb, 6))
165171 skip_bits(gb, 25);

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