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
92 return 0;92 return 0;
93}93}
94 94
95static void tak_parse_streaminfo(TAKStreamInfo *s, GetBitContext *gb)95static 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
130int avpriv_tak_parse_streaminfo(TAKStreamInfo *s, const uint8_t *buf, int size)136int 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
143int ff_tak_decode_frame_header(AVCodecContext *avctx, GetBitContext *gb,147int 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);

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