Skip to content

Commit

Permalink
apple-codesign: properly look for sniffed Mach-O header metadata
Browse files Browse the repository at this point in the history
Before, we would detect pretty much any file as a Mach-O. Oof.
  • Loading branch information
indygreg committed Nov 5, 2023
1 parent 5978ac8 commit 1c63bca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
1 change: 1 addition & 0 deletions apple-codesign/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Released on ReleaseDate.
* The `generate-self-signed-certificate` command gained a
`--pem-unified-filename` argument to write a PEM encoded file containing
both the private key and public certificate.
* Fixed a bug where files would be identified as Mach-O when they weren't.
* aws crates 0.53 -> 0.57.
* bitflags 1.3 -> 2.0.
* cryptographic-message-syntax 0.19 -> 0.25.
Expand Down
10 changes: 6 additions & 4 deletions apple-codesign/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ impl MachOType {

let magic = goblin::mach::peek(&header, 0)?;

match magic {
FAT_MAGIC => Ok(Some(Self::Mach)),
_ if parse_magic_and_ctx(&header, 0).is_ok() => Ok(Some(Self::MachO)),
_ => Ok(None),
if magic == FAT_MAGIC {
Ok(Some(Self::Mach))
} else if let Ok((_, Some(_))) = parse_magic_and_ctx(&header, 0) {
Ok(Some(Self::MachO))
} else {
Ok(None)
}
}
}
Expand Down

0 comments on commit 1c63bca

Please sign in to comment.