blacktop / ipsw

iOS/macOS Research Swiss Army Knife
https://blacktop.github.io/ipsw
MIT License
1.78k stars 139 forks source link

crash when trying to extract a binary from a FAT image when the image is not FAT #537

Closed doronz88 closed 2 weeks ago

doronz88 commented 3 weeks ago

What happened?

Trying to extract the following kernelcache:

ipsw macho lipo -a arm64 iPhone16,2_18.1_22B5023e_Restore/System/Library/Caches/com.apple.kernelcaches/kernelcache.release.iphone16

The command is expected to fail with an invalid file error. Instead I get:

   ⨯ input file is not a universal/fat MachO
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x20 pc=0x1014eb164]
              |
goroutine 1 [running]:
github.com/blacktop/go-macho.(*FatFile).Close(...)
              github.com/blacktop/go-macho@v1.1.232/fat.go:242
github.com/blacktop/ipsw/cmd/ipsw/cmd/macho.init.func10(0x103a401c0?, {0x14000904540, 0x1, 0x10225267e?})
              github.com/blacktop/ipsw/cmd/ipsw/cmd/macho/macho_lipo.go:82 +0x264
github.com/spf13/cobra.(*Command).execute(0x103a401c0, {0x140009044e0, 0x3, 0x3})
              github.com/spf13/cobra@v1.8.1/command.go:985 +0x840
github.com/spf13/cobra.(*Command).ExecuteC(0x103a1aea0)
              github.com/spf13/cobra@v1.8.1/command.go:1117 +0x344
github.com/spf13/cobra.(*Command).Execute(...)
              github.com/spf13/cobra@v1.8.1/command.go:1041
github.com/blacktop/ipsw/cmd/ipsw/cmd.Execute()
              github.com/blacktop/ipsw/cmd/ipsw/cmd/root.go:67 +0x24
main.main()
              github.com/blacktop/ipsw/cmd/ipsw/main.go:27 +0x1c

How can we reproduce this?

Try to extract arm64 macho from a arm64 macho (which should just fail)

ipsw version

Version: 3.1.535, BuildCommit: 034b367f9c2ec4b6f7fe066ccd0fdba2f88dc9f4

Search

Code of Conduct

Additional context

No response

blacktop commented 3 weeks ago

thank you for reporting 👍