Skip to content

Commit

Permalink
Cover typeOf
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderOMara committed Jan 19, 2025
1 parent 3fbe11f commit bba4332
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion macho/universal.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import {
assertLessOrEqual,
assertThrows,
} from '@std/assert';
import { MH_DYLIB, MH_EXECUTE } from '../const.ts';
import { FAT_MAGIC, MH_DYLIB, MH_EXECUTE } from '../const.ts';
import { FatArch } from '../mach/fatarch.ts';
import { FatHeader } from '../mach/fatheader.ts';
import { MachHeader } from '../mach/machheader.ts';
import { fixtureMacho, fixtureMachos } from '../spec/fixture.ts';
import { Architecture } from './architecture.ts';
import { Universal } from './universal.ts';
Expand Down Expand Up @@ -74,3 +77,33 @@ for (const { kind, arch, file, archs } of fixtures) {
}
});
}

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

Deno.test('typeOf unknown magic', async () => {
const blob = new Blob([new ArrayBuffer(MachHeader.BYTE_LENGTH)]);
assertEquals(await Universal.typeOf(blob), 0);
});

Deno.test('typeOf fat arch under', async () => {
const data = new ArrayBuffer(FatHeader.BYTE_LENGTH + FatArch.BYTE_LENGTH);
const header = new FatHeader(data);
header.magic = FAT_MAGIC;
header.nfatArch = 1;
const arch = new FatArch(data, FatHeader.BYTE_LENGTH);
arch.offset = data.byteLength;
const blob = new Blob([data]);
assertEquals(await Universal.typeOf(blob), 0);
});

Deno.test('typeOf fat infinite loop', async () => {
const data = new ArrayBuffer(FatHeader.BYTE_LENGTH + FatArch.BYTE_LENGTH);
const header = new FatHeader(data);
header.magic = FAT_MAGIC;
header.nfatArch = 1;
const blob = new Blob([data]);
assertEquals(await Universal.typeOf(blob), 0);
});

0 comments on commit bba4332

Please sign in to comment.