From 99d5ff736136b6eda15a238538fd2ca3b0eee449 Mon Sep 17 00:00:00 2001 From: Anurag Singh Date: Fri, 27 Nov 2026 19:40:04 +0530 Subject: [PATCH] fix(artifacts): keep uImage coverage unknown when bytes follow the declared payload (#14896) U-Boot does not pad a legacy image, so bytes after the 64-byte header and the declared payload belong to no entry. The reader reported complete coverage for them, which hid a root filesystem appended after a kernel. Report unknown coverage with the length and starting offset of those bytes. Fixes #14893 Co-authored-by: Anurag Singh <211784907+Anurag-5ingh@users.noreply.github.com> --- docs/uimage.md | 5 +++ src/artifacts/UImageArtifactReader.test.ts | 21 +++++++++++ src/artifacts/UImageArtifactReader.ts | 44 ++++++++++++++++------ 3 files changed, 58 insertions(+), 12 deletions(-) diff --git a/docs/uimage.md b/docs/uimage.md index 125e9254181..6c46d02933f 100644 --- a/docs/uimage.md +++ b/docs/uimage.md @@ -24,6 +24,11 @@ ranges and content hashes retain precise provenance. Extraction writes the compl payload and every component, so multi-file output can approach twice the input size. Compressed payloads remain compressed. +U-Boot does not pad a legacy image, so the image ends at the 64-byte header plus +the declared payload size. Bytes after that point, such as a root filesystem +appended after a kernel or partition padding, belong to no entry. Coverage is +then unknown, and a limitation gives their length and starting offset. + The fixed 32-byte name field is retained as `name_bytes_hex`. `name` contains the UTF-8 bytes before the first NUL, or null when those bytes cannot be decoded exactly. For example, a producer can truncate a multibyte character at the diff --git a/src/artifacts/UImageArtifactReader.test.ts b/src/artifacts/UImageArtifactReader.test.ts index 52ed1ae83a5..e7e06ce8589 100644 --- a/src/artifacts/UImageArtifactReader.test.ts +++ b/src/artifacts/UImageArtifactReader.test.ts @@ -197,6 +197,27 @@ it("inventories a kernel image with its stored payload", async () => { } }); +it("keeps coverage unknown when bytes follow the declared payload", async () => { + const payload = Buffer.from("kernel-bytes"); + const image = buildUImage({ type: 2, payload }); + const appended = Buffer.from("appended-rootfs"); + const path = await writeCarrier( + "uimage-appended", + Buffer.concat([image, appended]), + ); + const snapshot = await scanCanonicalArtifactInventory(path); + expect(snapshot.manifest.root_format).toBe("uimage"); + expect( + snapshot.occurrences + .filter((row) => row.logical_path !== ".") + .map((row) => [row.logical_path, row.declared_size]), + ).toEqual([["payload.bin", payload.length]]); + expect(snapshot.coverage.status).toBe("unknown"); + expect(snapshot.limitations).toContain( + `${String(appended.length)} byte(s) after the uImage payload, starting at offset ${String(image.length)}, were not exposed as entries.`, + ); +}); + it("splits multi images and keeps compressed payloads as stored", async () => { const partA = Buffer.from("first-part"); const partB = Buffer.from("second-part-longer"); diff --git a/src/artifacts/UImageArtifactReader.ts b/src/artifacts/UImageArtifactReader.ts index 24b61c9575c..2dac2ea5184 100644 --- a/src/artifacts/UImageArtifactReader.ts +++ b/src/artifacts/UImageArtifactReader.ts @@ -133,20 +133,9 @@ export class UImageArtifactReader extends PositionalArtifactReader entryFor("sub-image", sub.index, sub)), ]; - const limitations: string[] = []; - if (sizeTableLimitation !== undefined) { - limitations.push(sizeTableLimitation); - } else if (hasUImageSizeTable(header.type)) { - limitations.push( - "Multi-image sub-images are split from the stored size table; the payload entry retains the full stored bytes.", - ); - } return { entries, - coverage: { - status: sizeTableLimitation === undefined ? "complete" : "unknown", - limitations, - }, + coverage: uImageCoverage(header, initial.size, sizeTableLimitation), formatMetadata: toMetadata(header, subImages.length, crcVerified), containerIntegrity: { algorithm: "crc32", @@ -157,6 +146,37 @@ export class UImageArtifactReader extends PositionalArtifactReader["coverage"] => { + const limitations: string[] = []; + if (sizeTableLimitation !== undefined) limitations.push(sizeTableLimitation); + else if (hasUImageSizeTable(header.type)) + limitations.push( + "Multi-image sub-images are split from the stored size table; the payload entry retains the full stored bytes.", + ); + const imageEnd = UIMAGE_HEADER_SIZE + header.payloadSize; + const trailingBytes = fileBytes - imageEnd; + if (trailingBytes > 0) + limitations.push( + `${String(trailingBytes)} byte(s) after the uImage payload, starting at offset ${String(imageEnd)}, were not exposed as entries.`, + ); + return { + status: + sizeTableLimitation === undefined && trailingBytes === 0 + ? "complete" + : "unknown", + limitations, + }; +}; + const formatFailure = ( detail: string, options?: ErrorOptions,