File tree Expand file tree Collapse file tree 1 file changed +15
-0
lines changed
src/Microsoft.TestPlatform.CoreUtilities/Helpers Expand file tree Collapse file tree 1 file changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,13 @@ public class DotnetHostHelper : IDotnetHostHelper
23
23
{
24
24
public const string MONOEXENAME = "mono" ;
25
25
26
+ // Mach-O magic numbers from https://en.wikipedia.org/wiki/Mach-O
27
+ private const uint MachOMagic32BigEndian = 0xfeedface ; // 32-bit big-endian
28
+ private const uint MachOMagic64BigEndian = 0xfeedfacf ; // 64-bit big-endian
29
+ private const uint MachOMagic32LittleEndian = 0xcefaedfe ; // 32-bit little-endian
30
+ private const uint MachOMagic64LittleEndian = 0xcffaedfe ; // 64-bit little-endian
31
+ private const uint MachOMagicFatBigEndian = 0xcafebabe ; // Multi-architecture big-endian
32
+
26
33
private readonly IFileHelper _fileHelper ;
27
34
private readonly IEnvironment _environment ;
28
35
private readonly IWindowsRegistryHelper _windowsRegistryHelper ;
@@ -414,6 +421,14 @@ public bool TryGetDotnetPathByArchitecture(
414
421
ReadExactly ( headerReader , cpuInfoBytes , 0 , cpuInfoBytes . Length ) ;
415
422
416
423
var magic = BitConverter . ToUInt32 ( magicBytes , 0 ) ;
424
+
425
+ // Validate magic bytes to ensure this is a valid Mach-O binary
426
+ if ( magic is not ( MachOMagic32BigEndian or MachOMagic64BigEndian or MachOMagic32LittleEndian or MachOMagic64LittleEndian or MachOMagicFatBigEndian ) )
427
+ {
428
+ EqtTrace . Error ( $ "DotnetHostHelper.GetMuxerArchitectureByMachoOnMac: Invalid Mach-O magic bytes: 0x{ magic : X8} ") ;
429
+ return null ;
430
+ }
431
+
417
432
var cpuInfo = BitConverter . ToUInt32 ( cpuInfoBytes , 0 ) ;
418
433
PlatformArchitecture ? architecture = ( MacOsCpuType ) cpuInfo switch
419
434
{
You can’t perform that action at this time.
0 commit comments