Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specrec: better handle unexpected PS (CVE-2018-20360/CVE-2018-20199) #38

Merged
merged 2 commits into from
Aug 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions libfaad/ps_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1508,6 +1508,20 @@ static void ps_mix_phase(ps_info *ps, qmf_t X_left[38][64], qmf_t X_right[38][64

//printf("%d\n", ps->iid_index[env][bk]);

/* index range is supposed to be -7...7 or -15...15 depending on iid_mode
(Table 8.24, ISO/IEC 14496-3:2005).
if it is outside these boundaries, this is most likely an error. sanitize
it and try to process further. */
if (ps->iid_index[env][bk] < -no_iid_steps) {
fprintf(stderr, "Warning: invalid iid_index: %d < %d\n", ps->iid_index[env][bk],
-no_iid_steps);
ps->iid_index[env][bk] = -no_iid_steps;
} else if (ps->iid_index[env][bk] > no_iid_steps) {
fprintf(stderr, "Warning: invalid iid_index: %d > %d\n", ps->iid_index[env][bk],
no_iid_steps);
ps->iid_index[env][bk] = no_iid_steps;
}

/* calculate the scalefactors c_1 and c_2 from the intensity differences */
c_1 = sf_iid[no_iid_steps + ps->iid_index[env][bk]];
c_2 = sf_iid[no_iid_steps - ps->iid_index[env][bk]];
Expand Down
18 changes: 9 additions & 9 deletions libfaad/specrec.c
Original file line number Diff line number Diff line change
Expand Up @@ -915,18 +915,18 @@ uint8_t reconstruct_single_channel(NeAACDecStruct *hDecoder, ic_stream *ics,
/* element_output_channels not set yet */
hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
} else if (hDecoder->element_output_channels[hDecoder->fr_ch_ele] != output_channels) {
/* element inconsistency */

/* this only happens if PS is actually found but not in the first frame
/* element inconsistency
* this only happens if PS is actually found but not in the first frame
* this means that there is only 1 bitstream element!
*/

/* reset the allocation */
hDecoder->element_alloced[hDecoder->fr_ch_ele] = 0;

hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;

//return 21;
if (hDecoder->fr_channels == 1) {
/* reset the allocation */
hDecoder->element_alloced[hDecoder->fr_ch_ele] = 0;
hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
} else {
return 21;
}
}

if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0)
Expand Down