fix(android): validate engine archive prerequisites (#1145)

* fix(android): validate engine archive prerequisites

* fix(android): bound engine metadata reads before allocation
This commit is contained in:
Ysopwnable
2026-10-09 09:15:33 +08:00
committed by GitHub
parent 13935077ba
commit e9ebfb94ef
9 changed files with 180 additions and 17 deletions
@@ -9,8 +9,32 @@ import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
import { parseBinaryTarget } from "../../../src/application/BinaryTargetResolver.js";
import { ArtifactProvider } from "../../../src/artifacts/ArtifactProvider.js";
import { ZipArtifactReader } from "../../../src/artifacts/ZipArtifactReader.js";
import { artifactInventoryResultSchema } from "../../../src/domain/artifactGraph.js";
it("bounds a requested metadata read without rejecting the underlying valid ZIP", async () => {
const root = await createTestTempDirectory("rea-zip-metadata-budget-");
const path = join(root, "large-directory.zip");
const name = `${"a".repeat(8192)}.class`;
await writeOrderedZip(path, [name]);
const bounded = new ZipArtifactReader(path, "zip", 4096);
const control = new ZipArtifactReader(path, "zip");
const collect = async (reader: ZipArtifactReader): Promise<string[]> => {
const names: string[] = [];
for await (const entry of reader.entries()) names.push(entry.path);
return names;
};
try {
await expect(collect(bounded)).rejects.toMatchObject({
reason: "limit",
message: expect.stringContaining("4096-byte read budget"),
});
await expect(collect(control)).resolves.toEqual([name]);
} finally {
await Promise.all([bounded.close(), control.close()]);
}
});
it("rejects overlapping ZIP member data ranges through artifact inventory", async () => {
const root = await createTestTempDirectory("rea-zip-overlap-");
const path = join(root, "overlap.zip");