Skip to content

Commit 8c58494

Browse files
committed
ID3v2: Fix panic on empty UTF-16 strings with no BOM
1 parent aa58485 commit 8c58494

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

lofty/src/id3/v2/items/language_frame.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::error::{Id3v2Error, Id3v2ErrorKind, Result};
22
use crate::id3::v2::frame::content::verify_encoding;
33
use crate::id3::v2::header::Id3v2Version;
44
use crate::id3::v2::{FrameFlags, FrameHeader, FrameId};
5+
use crate::macros::err;
56
use crate::tag::items::Lang;
67
use crate::util::text::{
78
DecodeTextResult, TextDecodeOptions, TextEncoding, decode_text, encode_text,
@@ -55,8 +56,7 @@ impl LanguageFrame {
5556
endianness = match bom {
5657
[0xFF, 0xFE] => u16::from_le_bytes,
5758
[0xFE, 0xFF] => u16::from_be_bytes,
58-
// The BOM has to be valid for `decode_text` to succeed
59-
_ => unreachable!("Bad BOM {bom:?}"),
59+
_ => err!(TextDecode("UTF-16 string missing a BOM")),
6060
};
6161
}
6262

lofty/src/id3/v2/items/sync_text.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,8 +166,7 @@ impl SynchronizedTextFrame<'_> {
166166
endianness = match bom {
167167
[0xFF, 0xFE] => u16::from_le_bytes,
168168
[0xFE, 0xFF] => u16::from_be_bytes,
169-
// Since the description was already read, we can assume the BOM was valid
170-
_ => unreachable!("Bad BOM {bom:?}"),
169+
_ => err!(TextDecode("UTF-16 string missing a BOM")),
171170
};
172171
}
173172

lofty/tests/fuzz/mpegfile_read_from.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ fn crash5() {
4040
let _ = MpegFile::read_from(&mut reader, ParseOptions::new());
4141
}
4242

43+
#[test_log::test]
44+
fn crash6() {
45+
let mut reader = get_reader(
46+
"mpegfile_read_from/00. Dzienniki \
47+
Gwiazdowe_IDX_4_RAND_1362730390282399020432565_minimized_242.mp3",
48+
);
49+
let _ = MpegFile::read_from(&mut reader, ParseOptions::new());
50+
}
51+
4352
#[test_log::test]
4453
fn oom1() {
4554
oom_test::<MpegFile>("mpegfile_read_from/oom-f8730cbfa5682ab12343ccb70de9b71a061ef4d0");

0 commit comments

Comments
 (0)