test(C1.4): objectMagicOk — corrupt/truncated cache entries recompile, never poison the link

This commit is contained in:
agra
2026-06-12 16:48:27 +03:00
parent 053314b3ea
commit 2a2f43eada

View File

@@ -55,6 +55,15 @@ test "cSourceCacheKey: llvm version varies the key" {
try std.testing.expect(baseKey() != other);
}
test "objectMagicOk: accepts Mach-O and ELF, rejects garbage and truncation" {
try std.testing.expect(c_import.objectMagicOk(&.{ 0xcf, 0xfa, 0xed, 0xfe, 0x00 })); // Mach-O 64
try std.testing.expect(c_import.objectMagicOk(&.{ 0xce, 0xfa, 0xed, 0xfe })); // Mach-O 32
try std.testing.expect(c_import.objectMagicOk(&.{ 0x7f, 'E', 'L', 'F', 0x02 }));
try std.testing.expect(!c_import.objectMagicOk("not an object file"));
try std.testing.expect(!c_import.objectMagicOk(&.{ 0xcf, 0xfa, 0xed })); // truncated magic
try std.testing.expect(!c_import.objectMagicOk(&.{}));
}
test "cSourceCacheKey: triple and sysroot vary the key; absent is not empty" {
const other_triple = c_import.cSourceCacheKey(SRC, &.{HDR}, &.{"A=1"}, &.{"-O2"}, &.{"inc"}, VER, "x86_64-apple-darwin", "/sdk");
try std.testing.expect(baseKey() != other_triple);