mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 05:02:40 +00:00
fix(artifacts): accept Android boot images without final page padding (#11857)
* fix(artifacts): accept Android boot images without final page padding The truncation check required the file to reach the page-aligned end after the last component, so an image holding every declared byte but omitting the trailing zero padding was refused as truncated, and the message named the padded end. Bound truncation by the last declared header or component byte instead, keep the page-aligned end for locating an AVB footer, and check the AVB original image size against the declared bytes. Fixes #11854 * test(artifacts): check boot image declared ends against the fixture layout Derive each expected end from the fixture layout instead of the parser's dataEnd, so a declared structure dropped from the coverage check fails the test. --------- Co-authored-by: Anurag Singh <211784907+Anurag-5ingh@users.noreply.github.com>
This commit is contained in:
1 parent
84ee604c6d
commit
bb5278c7e2
7 files changed
+192
-17
No files matched your search
@@ -170,6 +170,68 @@ it("rejects an unsupported version, a bad page size, and a truncated image", ()
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts an image that ends at its last declared byte", () => {
|
||||
// Each end follows the layout: the last structure starts on a page and the
|
||||
// image ends at its final byte.
|
||||
const cases = [
|
||||
// 2048-byte pages: kernel, then the 7-byte ramdisk on page 2.
|
||||
{ image: buildBootImage({ version: 0 }), end: 2 * 2048 + 7 },
|
||||
// Recovery DTBO on page 3, then the 3-byte DTB on page 4.
|
||||
{
|
||||
image: buildBootImage({
|
||||
version: 2,
|
||||
recoveryDtbo: Buffer.from("dtbo"),
|
||||
dtb: Buffer.from("dtb"),
|
||||
}),
|
||||
end: 4 * 2048 + 3,
|
||||
},
|
||||
// 4096-byte pages: kernel, ramdisk, then the 9-byte signature on page 3.
|
||||
{
|
||||
image: buildBootImage({
|
||||
version: 4,
|
||||
signature: Buffer.from("signature"),
|
||||
}),
|
||||
end: 3 * 4096 + 9,
|
||||
},
|
||||
// Vendor ramdisk section on page 1, then the 3-byte DTB on page 2.
|
||||
{
|
||||
image: buildVendorBootImage({
|
||||
version: 3,
|
||||
ramdisk: Buffer.from("vendor-ramdisk"),
|
||||
dtb: Buffer.from("dtb"),
|
||||
}),
|
||||
end: 2 * 4096 + 3,
|
||||
},
|
||||
// Section, one 108-byte table entry, then 26 bootconfig bytes on page 3.
|
||||
{
|
||||
image: buildVendorBootImage({
|
||||
version: 4,
|
||||
ramdisks: [{ name: "one", type: 1, bytes: Buffer.from("aaa") }],
|
||||
bootconfig: Buffer.from("androidboot.hardware=test\n"),
|
||||
}),
|
||||
end: 3 * 4096 + 26,
|
||||
},
|
||||
// The 108-byte ramdisk table on page 2 is the last declared structure.
|
||||
{
|
||||
image: buildVendorBootImage({
|
||||
version: 4,
|
||||
ramdisks: [{ name: "one", type: 1, bytes: Buffer.from("aaa") }],
|
||||
}),
|
||||
end: 2 * 4096 + 108,
|
||||
},
|
||||
];
|
||||
for (const { image, end } of cases) {
|
||||
expect(image.subarray(end).every((byte) => byte === 0)).toBe(true);
|
||||
const padded = parsed(image);
|
||||
expect(padded).toMatchObject({ dataEnd: end, imageEnd: image.length });
|
||||
expect(parsed(image.subarray(0, end))).toEqual(padded);
|
||||
expect(failed(image.subarray(0, end - 1))).toMatchObject({
|
||||
kind: "truncated",
|
||||
message: `image is truncated: components end at byte ${String(end)} but the file is ${String(end - 1)} bytes`,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("aligns a kernel larger than 2^31 without allocating the image", () => {
|
||||
const header = Buffer.alloc(1632);
|
||||
header.write("ANDROID!", 0, "ascii");
|
||||
@@ -544,6 +606,7 @@ it("records an AVB footer and rejects vbmeta that overlaps a component", () => {
|
||||
const happy = appendAvbFooter(image);
|
||||
const footer = inspectAvbFooter({
|
||||
fileSize: happy.length,
|
||||
dataEnd: facts.dataEnd,
|
||||
imageEnd: facts.imageEnd,
|
||||
headerOccupied: facts.headerOccupied,
|
||||
components: facts.components,
|
||||
@@ -563,6 +626,7 @@ it("records an AVB footer and rejects vbmeta that overlaps a component", () => {
|
||||
});
|
||||
const bare = inspectAvbFooter({
|
||||
fileSize: image.length,
|
||||
dataEnd: facts.dataEnd,
|
||||
imageEnd: facts.imageEnd,
|
||||
headerOccupied: facts.headerOccupied,
|
||||
components: facts.components,
|
||||
@@ -575,6 +639,7 @@ it("records an AVB footer and rejects vbmeta that overlaps a component", () => {
|
||||
const short = Buffer.concat([image, Buffer.alloc(10)]);
|
||||
const shortFooter = inspectAvbFooter({
|
||||
fileSize: short.length,
|
||||
dataEnd: facts.dataEnd,
|
||||
imageEnd: facts.imageEnd,
|
||||
headerOccupied: facts.headerOccupied,
|
||||
components: facts.components,
|
||||
@@ -583,12 +648,53 @@ it("records an AVB footer and rejects vbmeta that overlaps a component", () => {
|
||||
expect(shortFooter.ok).toBe(true);
|
||||
if (!shortFooter.ok) return;
|
||||
expect(shortFooter.value.limitations[0]).toContain("10 trailing bytes");
|
||||
const unpadded = inspectAvbFooter({
|
||||
fileSize: facts.dataEnd,
|
||||
dataEnd: facts.dataEnd,
|
||||
imageEnd: facts.imageEnd,
|
||||
headerOccupied: facts.headerOccupied,
|
||||
components: facts.components,
|
||||
tail: null,
|
||||
});
|
||||
expect(unpadded).toMatchObject({
|
||||
ok: true,
|
||||
value: { present: false, limitations: [] },
|
||||
});
|
||||
const cut = inspectAvbFooter({
|
||||
fileSize: facts.dataEnd - 1,
|
||||
dataEnd: facts.dataEnd,
|
||||
imageEnd: facts.imageEnd,
|
||||
headerOccupied: facts.headerOccupied,
|
||||
components: facts.components,
|
||||
tail: null,
|
||||
});
|
||||
expect(cut).toMatchObject({ ok: false, error: { kind: "truncated" } });
|
||||
// avbtool records the unpadded size and places vbmeta on the next block.
|
||||
const signed = appendAvbFooter(image.subarray(0, facts.dataEnd), {
|
||||
vbmetaOffset: facts.imageEnd,
|
||||
originalImageSize: facts.dataEnd,
|
||||
partitionSize: 2 * facts.imageEnd,
|
||||
});
|
||||
expect(
|
||||
inspectAvbFooter({
|
||||
fileSize: signed.length,
|
||||
dataEnd: facts.dataEnd,
|
||||
imageEnd: facts.imageEnd,
|
||||
headerOccupied: facts.headerOccupied,
|
||||
components: facts.components,
|
||||
tail: signed.subarray(signed.length - 64),
|
||||
}),
|
||||
).toMatchObject({
|
||||
ok: true,
|
||||
value: { present: true, originalImageSize: facts.dataEnd },
|
||||
});
|
||||
const colliding = appendAvbFooter(image, {
|
||||
vbmetaOffset: 2048,
|
||||
vbmeta: Buffer.alloc(16),
|
||||
});
|
||||
const collision = inspectAvbFooter({
|
||||
fileSize: colliding.length,
|
||||
dataEnd: facts.dataEnd,
|
||||
imageEnd: facts.imageEnd,
|
||||
headerOccupied: facts.headerOccupied,
|
||||
components: facts.components,
|
||||
|
||||
Reference in new issue
Block a user