Skip to content

Commit

Permalink
Test make mismatched type
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Jan 20, 2025
1 parent 52d656e commit 54abe9f
Showing 1 changed file with 43 additions and 2 deletions.
45 changes: 43 additions & 2 deletions macho/universal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,19 +439,60 @@ Deno.test('make unknown type', async () => {
const mach = new MachHeader64(data, 256);
mach.magic = MH_MAGIC_64;
mach.sizeofcmds = 8;
const command = new LoadCommand(data, 256 + MachHeader64.BYTE_LENGTH);
const command = new LoadCommand(data, 256 + mach.byteLength);
command.cmdsize = 8;

const uni = new Universal();
await uni.open(new Blob([data]));

await assertRejects(
() => uni.architecture(256),
RangeError,
'Unknown type',
);
});

Deno.test('make mismatched type', async () => {
const data = new ArrayBuffer(256 * 3);
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;
arch1.align = 8;
{
const mach = new MachHeader64(data, 256);
mach.magic = MH_MAGIC_64;
mach.filetype = MH_EXECUTE;
mach.sizeofcmds = 8;
const command = new LoadCommand(data, 256 + mach.byteLength);
command.cmdsize = 8;
}

const arch2 = new FatArch(data, arch1.byteOffset + arch1.byteLength);
arch2.offset = 512;
arch2.size = 512;
arch2.align = 8;
{
const mach = new MachHeader64(data, 512);
mach.magic = MH_MAGIC_64;
mach.filetype = MH_DYLIB;
mach.sizeofcmds = 8;
const command = new LoadCommand(data, 512 + mach.byteLength);
command.cmdsize = 8;
}

const uni = new Universal();
await uni.open(new Blob([data]));
await uni.architecture(256);
await assertRejects(
() => uni.architecture(512),
RangeError,
'Mismatched type',
);
});

Deno.test('typeOf under header', async () => {
const blob = new Blob([new ArrayBuffer(MachHeader.BYTE_LENGTH - 1)]);
assertEquals(await Universal.typeOf(blob), 0);
Expand Down

0 comments on commit 54abe9f

Please sign in to comment.