fix(gpu): report the enforced parser limit (#12646)

This commit is contained in:
morluto authored and GitHub committed 2026-11-20 01:19:45 +00:00
1 parent a37fee0543
commit 939dd19efe
5 files changed
+87 -20

No files matched your search

@@ -83,7 +83,7 @@
"src/ghidra/GhidraInstallationProperties.ts": 1,
"src/ghidra/GhidraProviderClient.ts": 4,
"src/go/GoBinaryProvider.ts": 2,
"src/gpu/GpuCodeObjectsProvider.ts": 3,
"src/gpu/GpuCodeObjectsProvider.ts": 2,
"src/hopper/HopperCallerReconciliation.ts": 1,
"src/ida/IdaMcpConnection.ts": 1,
"src/il2cpp/Il2cppGhidraSeedWriter.ts": 1,
+19 -5
View File
@@ -24,6 +24,8 @@ export const CLANG_BUNDLE_MAGIC = Buffer.from("__CLANG_OFFLOAD_BUNDLE__");
export const CCOB_MAGIC = Buffer.from("CCOB");
const CLANG_BUNDLE_HEADER_BYTES = 32;
const CLANG_BUNDLE_ENTRY_BYTES = 24;
const CLANG_BUNDLE_MAX_ENTRIES = 65_536;
const CLANG_BUNDLE_MAX_ID_BYTES = 65_536;
export const readClangBundleDirectory = async (
source: GpuSource,
base: number,
@@ -49,13 +51,15 @@ export const readClangBundleDirectory = async (
)
rejectGpu("Clang offload bundle directory is truncated");
const count = gpuCount(declaredCount);
if (count > 65536)
if (count > CLANG_BUNDLE_MAX_ENTRIES)
throw new BinaryResourceFailure(
"structure",
65536,
CLANG_BUNDLE_MAX_ENTRIES,
"HIP bundle entry count exceeds the inventory budget",
"hip-bundle-entries",
"entries",
);
// One wrapper/identity per admitted entry (at most 65536). Processor text is
// One wrapper/identity per admitted entry. Processor text is
// no longer than its admitted name; cumulative name bytes remain
// within the 16 MiB directory bound before identities are allocated.
const declarations: {
@@ -96,11 +100,21 @@ export const readClangBundleDirectory = async (
if (minimumDirectoryEnd > firstPayload)
rejectGpu("HIP entry overlaps its bundle directory");
const nameSize = Number(rawNameSize);
if (nameSize > 65536 || nameOffset - base + nameSize > GPU_REPORT_BYTES)
if (nameSize > CLANG_BUNDLE_MAX_ID_BYTES)
throw new BinaryResourceFailure(
"structure",
CLANG_BUNDLE_MAX_ID_BYTES,
`HIP bundle ID exceeds ${String(CLANG_BUNDLE_MAX_ID_BYTES)} bytes`,
"hip-bundle-id-bytes",
"bytes",
);
if (nameOffset - base + nameSize > GPU_REPORT_BYTES)
throw new BinaryResourceFailure(
"structure",
GPU_REPORT_BYTES,
"HIP directory exceeds 16 MiB or its bundle ID exceeds 65536 bytes",
"HIP bundle directory exceeds its retained byte budget",
"hip-bundle-directory-bytes",
"bytes",
);
let name: string;
try {
+9 -12
View File
@@ -33,7 +33,10 @@ import {
cancelledBy,
carriedReason,
} from "../domain/analysisErrorCore.js";
import { parseFailureAnalysisError } from "../domain/parseFailureAnalysisError.js";
import {
parseFailureAnalysisError,
parseLimitConstraint,
} from "../domain/parseFailureAnalysisError.js";
import {
projectZstandardFrameAllowance,
ZstandardFrameAllowanceError,
@@ -133,20 +136,14 @@ export class GpuCodeObjectsProvider implements GpuCodeObjectsPort {
)
error = primary;
else if (primary instanceof BinaryResourceFailure)
error = new AnalysisResourceConstraintError(
OPERATION,
"memory",
primary.message,
{
error = parseLimitConstraint(OPERATION, "memory", primary, {
reportedLimitContext: {
maximum_object_bytes: GPU_OBJECT_BYTES,
maximum_report_bytes: GPU_REPORT_BYTES,
},
{
cause,
retryable: false,
remediationAction: `${primary.message} This release has no runtime override for that GPU byte allowance. The object allowance is ${String(GPU_OBJECT_BYTES)} bytes and the report allowance is ${String(GPU_REPORT_BYTES)} bytes. Additional host memory does not raise them. Repeating the unchanged request fails the same way.`,
},
);
retryable: false,
remediationAction: `${primary.message} This release has no runtime override for that GPU parser allowance. Additional host memory does not raise it. Repeating the unchanged request fails the same way.`,
});
else if (formatFailure !== undefined) error = formatFailure;
else if (
origin === "owned-or-classified" &&
+2
View File
@@ -23,6 +23,8 @@ export class GpuReportCapacityFailure extends BinaryResourceFailure {
"structure",
GPU_REPORT_BYTES,
"GPU facts exceed the 16 MiB retained report budget",
"gpu-retained-report-bytes",
"bytes",
);
}
}
+56 -2
View File
@@ -3,6 +3,7 @@ import { writeFile } from "node:fs/promises";
import { join } from "node:path";
import { deflateSync, zstdCompressSync } from "node:zlib";
import { createHash } from "node:crypto";
import { projectAnalysisError } from "../../../src/domain/analysisErrorProjection.js";
import { runWithAnalysisOperationSnapshot } from "../../../src/domain/analysisOperationSnapshot.js";
import {
MAXIMUM_ZSTD_MAX_FRAMES,
@@ -1495,6 +1496,14 @@ it("refuses escaped PTX report expansion while preserving bounded interrupted fa
error: { _tag: "AnalysisResourceConstraintError" },
});
if (result.ok) throw new Error("expected representation capacity refusal");
expect(projectAnalysisError(result.error)).toMatchObject({
details: {
reported_limits: {
boundary: "gpu-retained-report-bytes",
maximum: 16_777_216,
},
},
});
const partial = gpuCodeObjectsPartialSchema.parse(
parseEvidence(result.error.partialObservation).normalized_result,
);
@@ -1531,7 +1540,14 @@ it("distinguishes impossible Clang bundle counts from a framed over-capacity dir
}
const result = await inspect(framed, { analysis: "inventory" });
if (result.ok) throw new Error("Expected directory capacity failure");
expect(result.error._tag).toBe("AnalysisResourceConstraintError");
expect(projectAnalysisError(result.error)).toMatchObject({
code: "resource_constraint",
retryable: false,
details: {
resource: "memory",
reported_limits: { boundary: "hip-bundle-entries", maximum: 65_536 },
},
});
});
it("checks Clang bundle ID bounds before the retained directory allowance", async () => {
@@ -1545,7 +1561,19 @@ it("checks Clang bundle ID bounds before the retained directory allowance", asyn
const framed = Buffer.concat([header, Buffer.from(name), Buffer.alloc(1)]);
const limited = await inspect(framed, { analysis: "inventory" });
if (limited.ok) throw new Error("Expected a directory capacity failure");
expect(limited.error._tag).toBe("AnalysisResourceConstraintError");
expect(projectAnalysisError(limited.error)).toMatchObject({
code: "resource_constraint",
retryable: false,
details: {
resource: "memory",
reported_limits: {
boundary: "hip-bundle-id-bytes",
maximum: 65_536,
maximum_object_bytes: 134_217_728,
maximum_report_bytes: 16_777_216,
},
},
});
const short = Buffer.from(header);
short.writeBigUInt64LE(BigInt(short.length), 32);
@@ -1561,3 +1589,29 @@ it("checks Clang bundle ID bounds before the retained directory allowance", asyn
});
}
});
it("reports aggregate Clang directory capacity when every ID fits", async () => {
const count = 256;
const idBytes = 65_536;
const entryBytes = 24 + idBytes;
const directoryEnd = 32 + count * entryBytes;
const framed = Buffer.alloc(directoryEnd + 1, 0x78);
framed.write("__CLANG_OFFLOAD_BUNDLE__");
framed.writeBigUInt64LE(BigInt(count), 24);
for (let index = 0; index < count; index++) {
const row = 32 + index * entryBytes;
framed.writeBigUInt64LE(BigInt(directoryEnd), row);
framed.writeBigUInt64LE(1n, row + 8);
framed.writeBigUInt64LE(BigInt(idBytes), row + 16);
}
const result = await inspect(framed, { analysis: "inventory" });
if (result.ok) throw new Error("Expected directory capacity failure");
expect(projectAnalysisError(result.error)).toMatchObject({
details: {
reported_limits: {
boundary: "hip-bundle-directory-bytes",
maximum: 16_777_216,
},
},
});
});