From 409a1c9125386b47a26613f794862773a2285499 Mon Sep 17 00:00:00 2001 From: Alexander O'Mara Date: Sun, 19 Jan 2025 20:38:47 -0500 Subject: [PATCH] Test read error condition --- macho/universal.test.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/macho/universal.test.ts b/macho/universal.test.ts index bf94045..e727a4d 100644 --- a/macho/universal.test.ts +++ b/macho/universal.test.ts @@ -196,6 +196,28 @@ Deno.test('open suspicious gap', async () => { assertEquals(uni.isSuspicious(), true); }); +Deno.test('open suspicious read error', async () => { + const data = new ArrayBuffer(512 + 1); + const header = new FatHeader(data); + header.magic = FAT_MAGIC; + header.nfatArch = 2; + + const arch1 = new FatArch(data, header.byteLength); + arch1.offset = 256; + arch1.size = 256 + 1; + arch1.align = 8; + + const arch2 = new FatArch(data, header.byteLength + arch1.byteLength); + arch2.offset = 256 * 3; + arch2.size = 256; + arch2.align = 8; + + const blob = new Blob([data]); + const uni = new Universal(); + await uni.open(blob); + assertEquals(uni.isSuspicious(), true); +}); + Deno.test('typeOf under header', async () => { const blob = new Blob([new ArrayBuffer(MachHeader.BYTE_LENGTH - 1)]); assertEquals(await Universal.typeOf(blob), 0);