syntax.c: check for syntax element inconsistencies
Implicit channel mapping reconfiguration is explicitely forbidden by
ISO/IEC 13818-7:2006 (8.5.3.3). Decoders should be able to detect such
files and reject them. FAAD2 does not perform any kind of checks
regarding this.
This leads to security vulnerabilities when processing crafted AAC
files performing such reconfigurations.
Add checks to decode_sce_lfe and decode_cpe to make sure such
inconsistencies are detected as early as possible.
These checks first read hDecoder->frame: if this is not the first
frame then we make sure that the syntax element at the same position
in the previous frame also had element_id id_syn_ele. If not, return
21 as this is a fatal file structure issue.
This patch addresses CVE-2018-20362 (fixes #26) and possibly other
related issues.
Hugo Lefeuvre authored 5 years ago
Hugo Lefeuvre committed 5 years ago
343 | 343 | can become 2 when some form of Parametric Stereo coding is used |
344 | 344 | */ |
345 | 345 | |
346 | if (hDecoder->frame && hDecoder->element_id[hDecoder->fr_ch_ele] != id_syn_ele) { | |
347 | /* element inconsistency */ | |
348 | hInfo->error = 21; | |
349 | return; | |
350 | } | |
351 | ||
346 | 352 | /* save the syntax element id */ |
347 | 353 | hDecoder->element_id[hDecoder->fr_ch_ele] = id_syn_ele; |
348 | 354 | |
389 | 395 | /* element_output_channels not set yet */ |
390 | 396 | hDecoder->element_output_channels[hDecoder->fr_ch_ele] = 2; |
391 | 397 | } else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != 2) { |
398 | /* element inconsistency */ | |
399 | hInfo->error = 21; | |
400 | return; | |
401 | } | |
402 | ||
403 | if (hDecoder->frame && hDecoder->element_id[hDecoder->fr_ch_ele] != id_syn_ele) { | |
392 | 404 | /* element inconsistency */ |
393 | 405 | hInfo->error = 21; |
394 | 406 | return; |