mirror of
https://github.com/morluto/rea.git
synced 2026-11-20 05:32:44 +00:00
fix(pyinstaller): validate TOC record framing before capacity (#12622)
* fix(pyinstaller): validate TOC record framing before capacity * test(pyinstaller): assert TOC framing facts without prose
This commit is contained in:
1 parent
ba4205fe5e
commit
df375cc70d
2 files changed
+46
-7
No files matched your search
@@ -177,13 +177,6 @@ export const parseCArchiveToc = (
|
||||
),
|
||||
);
|
||||
while (offset < bytes.length) {
|
||||
if (entries.length >= MAX_TOC_ENTRIES)
|
||||
return err(
|
||||
pyInstallerFailure(
|
||||
"limit",
|
||||
"CArchive table of contents exceeds its entry bound",
|
||||
),
|
||||
);
|
||||
if (offset + TOC_HEADER_BYTES > bytes.length)
|
||||
return malformedEntry("CArchive table of contents entry is truncated");
|
||||
const entryLength = reader.u32(offset);
|
||||
@@ -191,6 +184,14 @@ export const parseCArchiveToc = (
|
||||
return malformedEntry(
|
||||
"CArchive table of contents entry extends outside the table",
|
||||
);
|
||||
// Only a framed record can exceed the retained entry allowance.
|
||||
if (entries.length >= MAX_TOC_ENTRIES)
|
||||
return err(
|
||||
pyInstallerFailure(
|
||||
"limit",
|
||||
"CArchive table of contents exceeds its entry bound",
|
||||
),
|
||||
);
|
||||
const nameBytes = bytes.subarray(
|
||||
offset + TOC_HEADER_BYTES,
|
||||
offset + entryLength,
|
||||
|
||||
@@ -17,6 +17,7 @@ import {
|
||||
PYTHON_39_MAGIC,
|
||||
} from "./CArchive.fixture.js";
|
||||
import { readPyzArchive } from "./PyzArchive.js";
|
||||
import { parseCArchiveToc } from "./CArchiveLayout.js";
|
||||
import { marshalCode } from "../../python/PythonPyc.fixture.js";
|
||||
import { createEvidence } from "../../domain/evidence.js";
|
||||
import { parseArtifactInventoryEvidence } from "../../domain/artifactInventoryEvidence.js";
|
||||
@@ -66,6 +67,43 @@ describe.each(["2.0", "2.1"] as const)(
|
||||
},
|
||||
);
|
||||
|
||||
describe("CArchive entry admission at the TOC record limit", () => {
|
||||
const entryCount = 100_000;
|
||||
const entry = Buffer.alloc(32);
|
||||
entry.writeUInt32BE(entry.length);
|
||||
entry[17] = 0x78;
|
||||
entry.write("member.txt", 18, "ascii");
|
||||
const boundary = entry.length * entryCount;
|
||||
const toc = Buffer.alloc(boundary + entry.length, entry);
|
||||
|
||||
it("accepts exactly the limit and refuses one more framed record", () => {
|
||||
const admitted = parseCArchiveToc(toc.subarray(0, boundary));
|
||||
if (!admitted.ok) throw new Error(admitted.error.message);
|
||||
expect(admitted.value).toHaveLength(entryCount);
|
||||
expect(parseCArchiveToc(toc)).toMatchObject({
|
||||
ok: false,
|
||||
error: { reason: "limit" },
|
||||
});
|
||||
});
|
||||
|
||||
it.each([4, 20])(
|
||||
"preserves framing failure for %i trailing bytes at the entry limit",
|
||||
(tailSize) => {
|
||||
expect(
|
||||
parseCArchiveToc(toc.subarray(0, boundary + tailSize)),
|
||||
).toMatchObject({
|
||||
ok: false,
|
||||
error: {
|
||||
reason: "format",
|
||||
message: expect.stringContaining(
|
||||
`table index ${entryCount} at TOC offset ${boundary}:`,
|
||||
),
|
||||
},
|
||||
});
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it.each([0, 1, 2])(
|
||||
"identifies malformed CArchive compression at table index %i",
|
||||
async (index) => {
|
||||
|
||||
Reference in new issue
Block a user