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

Fix an out of bounds crash #94

Merged
merged 1 commit into from
Nov 13, 2022
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
2 changes: 2 additions & 0 deletions Source/Parse/ID3TagVersionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ class ID3TagVersionParser: TagVersionParser {
}

private func tryToGetVersionFrom(mp3: Data) -> ID3Version? {
guard mp3.count > versionBytesOffset else { return nil }

let version = [UInt8](mp3)[versionBytesOffset]
return ID3Version(rawValue: version)
}
Expand Down
5 changes: 5 additions & 0 deletions Tests/Parse/ID3TagVersionParserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class ID3TagVersionParserTest: XCTestCase {
XCTAssertEqual(.version3, id3VersionParser.parse(mp3: mp3WithV2Tag))
}

func testShortData() throws {
let shortData = Data(capacity: 2)
XCTAssertEqual(.version3, id3VersionParser.parse(mp3: shortData))
}

func testDefaultVersion() throws {
let mp3WithV2Tag = try Data(
contentsOf: URL(fileURLWithPath: PathLoader().pathFor(name: "example-to-be-modified", fileType: "mp3"))
Expand Down