Skip to content

Commit

Permalink
Fix crash (#94)
Browse files Browse the repository at this point in the history
* When version bytes are out of bounds a crash would occur
  • Loading branch information
joeljfischer authored Nov 13, 2022
1 parent cf09b99 commit 7297a74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
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

0 comments on commit 7297a74

Please sign in to comment.