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

ID3v2: Fix overflow with large RVA2 peak #364

Merged
merged 1 commit into from
Apr 3, 2024
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- **Vorbis**: Fix panic when reading properties of zero-length files ([issue](https://github.com/Serial-ATA/lofty-rs/issues/342)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/365))
- **ID3v2**: Fix panic when reading an RVA2 frame with a peak larger than 248 bits ([issue](https://github.com/Serial-ATA/lofty-rs/issues/295)) ([PR](https://github.com/Serial-ATA/lofty-rs/pull/364))

## [0.18.2] - 2024-01-23

Expand Down
8 changes: 4 additions & 4 deletions src/id3/v2/items/relative_volume_adjustment_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ impl RelativeVolumeAdjustmentFrame {

let mut peak_volume = None;
if bits_representing_peak > 0 {
let bytes_representing_peak = (bits_representing_peak + 7) >> 3;
let bytes_representing_peak = (u16::from(bits_representing_peak) + 7) >> 3;

let mut peak_volume_bytes = try_vec![0; bytes_representing_peak as usize];
reader.read_exact(&mut peak_volume_bytes)?;
Expand Down Expand Up @@ -169,7 +169,7 @@ impl RelativeVolumeAdjustmentFrame {

for (channel_type, info) in &self.channels {
let mut bits_representing_peak = info.bits_representing_peak;
let expected_peak_byte_length = (bits_representing_peak + 7) >> 3;
let expected_peak_byte_length = (u16::from(bits_representing_peak) + 7) >> 3;

content.push(*channel_type as u8);
content.extend(info.volume_adjustment.to_be_bytes());
Expand All @@ -186,13 +186,13 @@ impl RelativeVolumeAdjustmentFrame {
bits_representing_peak = 0;

// Max out at 255 bits
for b in peak.iter().copied().take(31) {
for b in peak.iter().copied().take(32) {
bits_representing_peak += b.leading_ones() as u8;
}
}

content.push(bits_representing_peak);
content.extend(peak.iter().take(31));
content.extend(peak.iter().take(32));
}
}

Expand Down
6 changes: 0 additions & 6 deletions src/id3/v2/tag/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1338,9 +1338,3 @@ fn flag_item_conversion() {
Some("0")
);
}

#[test]
fn regression_295_fuzzing_id3v24_parse_extended_text_frame_unreachable_panic() {
let data = [1, 0, 0, 0];
assert!(ExtendedTextFrame::parse(&mut &data[..], Id3v2Version::V4).is_err());
}
26 changes: 26 additions & 0 deletions tests/fuzz/id3v2.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#[test]
fn unreachable1() {
// https://github.com/Serial-ATA/lofty-rs/issues/295
let data = [1, 0, 0, 0];
let _local0 = lofty::id3::v2::Id3v2Tag::new();
let _local1_param0_helper1 = &(_local0);
let _local1 = lofty::id3::v2::Id3v2Tag::original_version(_local1_param0_helper1);
let _local2_param0_helper1 = &mut (&data[..]);
let _: lofty::error::Result<std::option::Option<lofty::id3::v2::ExtendedTextFrame>> =
lofty::id3::v2::ExtendedTextFrame::parse(_local2_param0_helper1, _local1);
}

#[test]
fn overflow1() {
// https://github.com/Serial-ATA/lofty-rs/issues/295
let data = [
57, 25, 25, 0, 4, 1, 54, 0, 51, 6, 6, 6, 25, 25, 25, 129, 6, 151, 28, 25, 25, 0, 51, 51,
50, 5, 5, 5, 26, 5, 5, 25, 6, 6, 25, 26, 246, 25, 25, 129, 6, 151, 3, 252, 56, 0, 53, 56,
55, 52,
];
let _local0 = <lofty::ParsingMode as std::default::Default>::default();
let _local1_param0_helper1 = &mut (&data[..]);
let _: lofty::error::Result<
std::option::Option<lofty::id3::v2::RelativeVolumeAdjustmentFrame>,
> = lofty::id3::v2::RelativeVolumeAdjustmentFrame::parse(_local1_param0_helper1, _local0);
}
1 change: 1 addition & 0 deletions tests/fuzz/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::time::Instant;

mod aifffile_read_from;
mod flacfile_read_from;
mod id3v2;
mod mp4file_read_from;
mod mpegfile_read_from;
mod opusfile_read_from;
Expand Down