Created
October 17, 2023 17:08
-
-
Save liscio/32a4f2710a8248605d9556c7ca4e7548 to your computer and use it in GitHub Desktop.
It doesn't take much to corrupt the FPU state on Intel machines running macOS Sonoma!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <Cocoa/Cocoa.h> | |
#import <iostream> | |
static long double _giantValue = 0.0; | |
void writeGiantValue(long double inValue) { | |
_giantValue = inValue; | |
} | |
long double readGiantValue() { | |
return _giantValue; | |
} | |
static void interactWithGiantValue(void) { | |
writeGiantValue(1.0); | |
long double gv = readGiantValue(); | |
if ( gv != 1.0 ) { | |
std::cout << "ERROR: Giant value should be 1, but it is instead " << gv << std::endl; | |
} else { | |
std::cout << "All good. Giant value is " << gv << std::endl; | |
} | |
} | |
int main(int argc, char *argv[]) { | |
/* | |
Before decoding the troublesome image, we can interact with Float80 | |
values, and not encounter any problems. | |
*/ | |
interactWithGiantValue(); | |
/* | |
Load the image, and force it to be decoded. | |
*/ | |
NSImage *songAlbumArt = [[NSImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL fileURLWithPath:@"artwork.jpg"]]]; | |
id imageRef = [songAlbumArt TIFFRepresentation]; | |
/* | |
On Intel machines running macOS Sonoma, this will report a NaN value being | |
read from _giantValue. This is likely a result of someone corrupting---or, | |
failing to restore---the FPU state. | |
*/ | |
interactWithGiantValue(); | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment