ruby-macho icon indicating copy to clipboard operation
ruby-macho copied to clipboard

Fat parser should fail on mismatched CPU types

Open woodruffw opened this issue 6 years ago • 0 comments

Currently, ruby-macho will happily parse a fat Mach-O whose fat_archs and internal slices have mismatching (i.e., not 1-to-1) CPU types and subtypes.

Reference this LLVM object: https://github.com/llvm-mirror/llvm/blob/master/test/Object/Inputs/macho-invalid-fat_cputype

Observed behavior:

>> MachO.open('macho-invalid-fat_cputype')
#<MachO::FatFile:0x000055776df7b0e0 @filename="macho-invalid-fat_cputype", @options={}, @raw_data="\xCA\xFE\xBA\xBE\x00\x00\x00\x01\x00\x00\x00\f\x00\x00\x00\x00\x00\x00\x00\x1C\x00\x00\x00\x1C\x00\x00\x00\x02\xCE\xFA\xED\xFE\a\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", @header=#<MachO::Headers::FatHeader:0x000055776df7af50 @magic=3405691582, @nfat_arch=1>, @fat_archs=[#<MachO::Headers::FatArch:0x000055776df7ae10 @cputype=12, @cpusubtype=0, @offset=28, @size=28, @align=2>], @machos=[#<MachO::MachOFile:0x000055776df7ad20 @filename=nil, @options={}, @raw_data="\xCE\xFA\xED\xFE\a\x00\x00\x00\x03\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", @endianness=:little, @header=#<MachO::Headers::MachHeader:0x000055776df7ab18 @magic=4277009102, @cputype=7, @cpusubtype=3, @filetype=1, @ncmds=0, @sizeofcmds=0, @flags=0>, @load_commands=[]>]>

Expected behavior:

An exception.

woodruffw avatar Mar 15 '19 02:03 woodruffw