Skip to content

Commit

Permalink
Report unexpected file size error
Browse files Browse the repository at this point in the history
  • Loading branch information
YuAo committed Apr 2, 2022
1 parent 0e29748 commit 4115e75
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Sources/MetalLibraryArchive/Archive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ public struct Archive: Hashable {
case unexpectedTargetPlatform(Int)
case unexpectedBitcodeSize
case unexpectedOperatingSystemType(Int)
case unexpectedFileSize

public var errorDescription: String? {
switch self {
Expand Down Expand Up @@ -145,6 +146,8 @@ public struct Archive: Hashable {
return "Unexpected bitcode size."
case .unexpectedOperatingSystemType(let value):
return "Unexpected OS type: \(value)."
case .unexpectedFileSize:
return "Unexpected file size."
}
}

Expand Down Expand Up @@ -225,7 +228,9 @@ public struct Archive: Hashable {

// 16...23
let fileSize = try dataScanner.scan(UInt64.self)
assert(fileSize == data.count)
guard fileSize == data.count else {
throw Error.unexpectedFileSize
}

let functionListOffset = try dataScanner.scan(UInt64.self) //24...31
let functionListSize = try dataScanner.scan(UInt64.self) //32...39
Expand Down

0 comments on commit 4115e75

Please sign in to comment.