Skip to content

Commit

Permalink
Test make unknown type
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Jan 20, 2025
1 parent 2d4f2f3 commit 52d656e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions macho/universal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ import {
FAT_MAGIC,
MH_DYLIB,
MH_EXECUTE,
MH_MAGIC_64,
} from '../const.ts';
import { FatArch } from '../mach/fatarch.ts';
import { FatHeader } from '../mach/fatheader.ts';
import { LoadCommand } from '../mach/loadcommand.ts';
import { MachHeader } from '../mach/machheader.ts';
import { MachHeader64 } from '../mach/machheader64.ts';
import { fixtureMacho, fixtureMachos } from '../spec/fixture.ts';
import { Architecture } from './architecture.ts';
import { Universal } from './universal.ts';
Expand Down Expand Up @@ -422,6 +425,33 @@ Deno.test('findArch case 4: accept equal type as last resort', async () => {
);
});

Deno.test('make unknown type', async () => {
const data = new ArrayBuffer(512);
const header = new FatHeader(data);
header.magic = FAT_MAGIC;
header.nfatArch = 1;

const arch = new FatArch(data, header.byteLength);
arch.offset = 256;
arch.size = 256;
arch.align = 8;

const mach = new MachHeader64(data, 256);
mach.magic = MH_MAGIC_64;
mach.sizeofcmds = 8;
const command = new LoadCommand(data, 256 + MachHeader64.BYTE_LENGTH);
command.cmdsize = 8;

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

await assertRejects(
() => uni.architecture(256),
RangeError,
'Unknown 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 52d656e

Please sign in to comment.