Skip to content

ID3v2: fallback when BOM is not present in UTF-16 data#614

Merged
Serial-ATA merged 1 commit intoSerial-ATA:mainfrom
aschey:fix/bom-error
Feb 15, 2026
Merged

ID3v2: fallback when BOM is not present in UTF-16 data#614
Serial-ATA merged 1 commit intoSerial-ATA:mainfrom
aschey:fix/bom-error

Conversation

@aschey
Copy link
Contributor

@aschey aschey commented Feb 15, 2026

Resolves #613

This restores the behavior prior to #535 where language frames are still parsed successfully if the BOM is not present in UTF-16 data. I don't have any files that cause an issue here with text frames, but I updated it there too for consistently. I can revert that if desired.

@aschey aschey changed the title fix: fallback when BOM is not present in UTF-16 data ID3v2: fallback when BOM is not present in UTF-16 data Feb 15, 2026
Comment on lines +53 to +61
let endianness: Option<fn([u8; 2]) -> u16> = if encoding == TextEncoding::UTF16 {
match bom {
[0xFF, 0xFE] => Some(u16::from_le_bytes),
[0xFE, 0xFF] => Some(u16::from_be_bytes),
_ => None,
}
} else {
None
};
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example with a broken language frame? Not sure I understand what the solution here is. decode_text with an encoding of UTF16 should fail anyway if there isn't a valid BOM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, here's one that reproduces the problem. The frame does decode correctly with this change in place. I don't know much about id3 tags so maybe this is just a band-aid fix, but I was trying to preserve the behavior from 0.22 where this worked previously.

04 Blood on the Radio.zip - the lyrics tag is the one that fails here without this change

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yeah. #535 broke the case of empty descriptions which shouldn't have a BOM. This change makes sense then, I'll just update the comment

Co-authored-by: Serial <69764315+serial-ata@users.noreply.github.com>
@Serial-ATA Serial-ATA merged commit 5597270 into Serial-ATA:main Feb 15, 2026
4 checks passed
@Serial-ATA
Copy link
Owner

Thanks!

@aschey aschey deleted the fix/bom-error branch February 15, 2026 17:42
@Serial-ATA Serial-ATA added this to the 0.23.3 milestone Feb 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsing mp3 file fails when UTF-16 data has missing BOM

2 participants