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

Add some length checks #15

Merged
merged 1 commit into from
Feb 18, 2022
Merged
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
36 changes: 36 additions & 0 deletions src/anlz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1140,6 +1140,15 @@ impl Content {

fn parse_waveform_detail<'a>(input: &'a [u8], header: &Header) -> IResult<&'a [u8], Self> {
let (input, len_entry_bytes) = nom::number::complete::be_u32(input)?;
// All waveform detail entries should be 1 byte long. If we see other values here,
// some reverse-engineering is needed.
if len_entry_bytes != 2 {
return Err(Err::Error(nom::error::Error::from_error_kind(
input,
ErrorKind::LengthValue,
)));
}

let (input, len_entries) = nom::number::complete::be_u32(input)?;
let (input, unknown) = nom::number::complete::be_u32(input)?;
let (input, content_data_slice) = nom::bytes::complete::take(header.content_size())(input)?;
Expand All @@ -1165,6 +1174,15 @@ impl Content {
_header: &Header,
) -> IResult<&'a [u8], Self> {
let (input, len_entry_bytes) = nom::number::complete::be_u32(input)?;
// All waveform color preview entries should be 6 bytes long. If we see other values here,
// some reverse-engineering is needed.
if len_entry_bytes != 2 {
return Err(Err::Error(nom::error::Error::from_error_kind(
input,
ErrorKind::LengthValue,
)));
}

let (input, len_entries) = nom::number::complete::be_u32(input)?;
let entry_count = match usize::try_from(len_entries) {
Ok(x) => x,
Expand Down Expand Up @@ -1196,6 +1214,15 @@ impl Content {
_header: &Header,
) -> IResult<&'a [u8], Self> {
let (input, len_entry_bytes) = nom::number::complete::be_u32(input)?;
// All waveform color detail entries should be 2 bytes long. If we see other values here,
// some reverse-engineering is needed.
if len_entry_bytes != 2 {
return Err(Err::Error(nom::error::Error::from_error_kind(
input,
ErrorKind::LengthValue,
)));
}

let (input, len_entries) = nom::number::complete::be_u32(input)?;
let entry_count = match usize::try_from(len_entries) {
Ok(x) => x,
Expand Down Expand Up @@ -1224,6 +1251,15 @@ impl Content {

fn parse_song_structure<'a>(input: &'a [u8], _header: &Header) -> IResult<&'a [u8], Self> {
let (input, len_entry_bytes) = nom::number::complete::be_u32(input)?;
// All phrase entries should be 24 bytes long. If we see other values here, some
// reverse-engineering is needed.
if len_entry_bytes != 24 {
return Err(Err::Error(nom::error::Error::from_error_kind(
input,
ErrorKind::LengthValue,
)));
}

let (input, len_entries) = nom::number::complete::be_u16(input)?;
let entry_count = match usize::try_from(len_entries) {
Ok(x) => x,
Expand Down