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>
This commit is contained in:
Anurag SinghandAnurag Singh authored and GitHub committed 2026-11-27 22:10:04 +08:00
1 parent 54f2d5a4e3
commit 99d5ff7361
3 files changed
+58 -12

No files matched your search

+5
View File
@@ -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
@@ -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");
+32 -12
View File
@@ -133,20 +133,9 @@ export class UImageArtifactReader extends PositionalArtifactReader<UImageMetadat
}),
...subImages.map((sub) => 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<UImageMetadat
}
}
/**
* Coverage is complete only when the entries account for every file byte and
* any size table split them. U-Boot does not pad a legacy image, so bytes past
* the declared payload belong to no entry.
*/
const uImageCoverage = (
header: UImageHeaderFields,
fileBytes: number,
sizeTableLimitation: string | undefined,
): PositionalArtifactEntries<UImageMetadata>["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,