From 641834a7cdd19bed445a6e0cd00bda39468662ed Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Thu, 19 Nov 2026 13:55:17 -0500 Subject: [PATCH] fix(fit): retain declared devicetree parser limits (#12474) --- src/artifacts/fit/FitStructure.ts | 8 +++-- tests/acceptance/fitImageCli.test.ts | 48 ++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 3 deletions(-) diff --git a/src/artifacts/fit/FitStructure.ts b/src/artifacts/fit/FitStructure.ts index 713ac7c647..a687d5528c 100644 --- a/src/artifacts/fit/FitStructure.ts +++ b/src/artifacts/fit/FitStructure.ts @@ -575,13 +575,15 @@ const parseFit = (fdt: Buffer, path: string) => { if (cause instanceof BinaryFormatFailure) throw formatFailure(cause.message); if (isParseLimit(cause, DEVICETREE_FORMAT)) { - const { name } = cause.failure.limit; + const { limit: parserLimit } = cause.failure; throw new ArtifactReaderFailure( "limit", - `FIT devicetree exceeds the fixed ${name} allowance`, + `FIT devicetree exceeds the fixed ${parserLimit.name} allowance`, { - boundary: name === "decoded_bytes" ? "memory" : "capacity", + boundary: + parserLimit.name === "decoded_bytes" ? "memory" : "capacity", cause, + parserLimit, }, ); } diff --git a/tests/acceptance/fitImageCli.test.ts b/tests/acceptance/fitImageCli.test.ts index e6bf6fe4f9..57f9992175 100644 --- a/tests/acceptance/fitImageCli.test.ts +++ b/tests/acceptance/fitImageCli.test.ts @@ -13,7 +13,9 @@ import { } from "../../src/artifacts/fit/FitImage.fixture.js"; import { cells, + devicetreeFixture, dtString, + type FixtureNode, } from "../../src/domain/firmware/devicetree.fixture.js"; import { parseEvidence } from "../../src/domain/evidence.js"; import { artifactInspectionResultSchema } from "../../src/domain/artifactInspection.js"; @@ -84,6 +86,52 @@ cliTest.for(cases)( }, ); +cliTest("reports the fixed FIT devicetree depth limit", async ({ cli }) => { + const directory = await createTestTempDirectory("rea-fit-depth-cli-"); + const source = join(directory, "boot.itb"); + const inspect = async (depth: number) => { + let metadata: FixtureNode = { name: "leaf" }; + for (let level = 2; level < depth; level++) + metadata = { name: "nested", children: [metadata] }; + await writeFile( + source, + devicetreeFixture({ + name: "", + children: [ + { + name: "images", + children: [{ name: "kernel", properties: { data: FIT_KERNEL } }], + }, + metadata, + ], + }), + ); + return await cli.run({ + arguments: ["inspect-artifact", source, "--json"], + }); + }; + const admitted = await inspect(64); + expect(admitted.exitCode, admitted.stdout + admitted.stderr).toBe(0); + const inspection = artifactInspectionResultSchema.parse( + parseEvidence(admitted.json).normalized_result, + ); + const graph = artifactInventoryResultSchema.parse( + inspection.substeps[0]?.evidence.normalized_result, + ); + expect(graph.manifest.root_format).toBe("fit"); + + const refused = await inspect(65); + expect(refused.json).toMatchObject({ + code: "truncated", + retryable: false, + details: { + boundary: "capacity", + detail: expect.stringContaining("fixed max_depth"), + reported_limits: { boundary: "max_depth", maximum: 64 }, + }, + }); +}); + cliTest("rejects a FIT hash mismatch through the CLI", async ({ cli }) => { const directory = await createTestTempDirectory("rea-fit-invalid-cli-"); const source = join(directory, "boot.itb");