fix(android-ota): report bytes beyond the declared payload (#15113)

* fix(android-ota): report bytes beyond the declared payload

* test(android-ota): exercise an unsigned payload suffix

---------

Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com>
This commit is contained in:
ShuaixinHuangandShuaixinHuang authored and GitHub committed 2026-11-30 13:06:16 +08:00
1 parent c552392248
commit 18dfe17425
4 files changed
+63 -3

No files matched your search

@@ -61,6 +61,10 @@ facts, not a cryptographic check. `payload_properties.txt` and
that already lists `payload.bin` still classifies that member by `CrAU`
magic; zip inventory does not recurse into its partitions.
Bytes beyond all declared operation data and any payload signature leave the
inventory coverage `unknown`. REA reports their file offset and length while
retaining the declared partition entries.
## Extraction
A partition is reconstructed only when every install operation is REPLACE,
@@ -162,6 +162,49 @@ it("keeps partition inventory when the blob is truncated", async () => {
]);
});
it.each([false, true])(
"reports bytes after the declared OTA payload (signature present: %s)",
async (signed) => {
const signature = Buffer.from(
new BinaryWriter()
.tag(1, WireType.LengthDelimited)
.bytes(new Uint8Array([0xaa, 0xbb]))
.finish(),
);
const payload = buildAndroidOtaPayload({
partitions: [
{ name: "boot", operations: [{ type: 0, data: Buffer.from("BOOT") }] },
],
...(signed
? { payloadSignature: signature }
: {
payloadSignature: Buffer.alloc(0),
signaturesOffset: null,
signaturesSize: null,
}),
});
const snapshot = await scanCanonicalArtifactInventory(
await writeCarrier(
"unclaimed-tail.bin",
Buffer.concat([payload, Buffer.from("extra")]),
),
);
expect(snapshot.coverage.status).toBe("unknown");
expect(
snapshot.occurrences.find((row) => row.logical_path === ".")
?.format_metadata,
).toMatchObject({
payload_signature_blob_size: signed ? signature.length : null,
});
expect(snapshot.limitations.join(" ")).toContain(
`5 byte(s) at offset ${String(payload.length)}`,
);
expect(
snapshot.occurrences.find((row) => row.logical_path === "boot.img"),
).toMatchObject({ hash_status: "verified" });
},
);
it("reports unknown coverage when optional trailing payloadSignature is truncated", async () => {
const signature = Buffer.from(
new BinaryWriter()
@@ -253,9 +253,10 @@ export class AndroidOtaPayloadArtifactReader implements ArtifactReader {
: withAndroidOtaPayloadSignature(payload.value, payloadSignature);
if (parsed.ok) {
this.#payload = parsed.value;
this.#coverageStatus = parsed.value.blobTruncated
? "unknown"
: "complete";
this.#coverageStatus =
parsed.value.blobTruncated || parsed.value.unclaimedSuffixBytes > 0
? "unknown"
: "complete";
this.#limitations = [...parsed.value.limitations];
} else {
if (parsed.error.kind === "limit") throw parseFailure(parsed.error);
+12
View File
@@ -328,6 +328,7 @@ export interface AndroidOtaPayload {
readonly vabcCompressionParam: string | null;
readonly apexInfo: readonly AndroidOtaApexInfo[];
readonly blobTruncated: boolean;
readonly unclaimedSuffixBytes: number;
readonly limitations: readonly string[];
}
@@ -1024,6 +1025,7 @@ export const parseAndroidOtaPayload = (
: { blobOffset: signaturesOffset, size: signaturesSize };
let payloadSignatureRange: AndroidOtaPayload["payloadSignatureRange"] = null;
let blobTruncated = fileSize < header.blobOffset;
let declaredBlobEnd = 0;
if (signatureDeclaration !== null) {
const { blobOffset, size } = signatureDeclaration;
const offset = header.blobOffset + blobOffset;
@@ -1039,6 +1041,7 @@ export const parseAndroidOtaPayload = (
),
);
if (size > 0) payloadSignatureRange = { offset, bytes: size };
declaredBlobEnd = blobOffset + size;
}
}
@@ -1059,6 +1062,7 @@ export const parseAndroidOtaPayload = (
),
);
if (end > blobAvailable) blobTruncated = true;
declaredBlobEnd = Math.max(declaredBlobEnd, end);
}
}
@@ -1136,12 +1140,19 @@ export const parseAndroidOtaPayload = (
},
);
const unclaimedSuffixBytes = blobTruncated
? 0
: blobAvailable - declaredBlobEnd;
const limitations: string[] = [
ANDROID_OTA_PAYLOAD_LIMITATIONS.inventoryScope,
ANDROID_OTA_PAYLOAD_LIMITATIONS.signaturesUnverified,
];
if (blobTruncated)
limitations.push(ANDROID_OTA_PAYLOAD_LIMITATIONS.blobTruncated);
if (unclaimedSuffixBytes > 0)
limitations.push(
`Android OTA payload has ${String(unclaimedSuffixBytes)} byte(s) at offset ${String(fileSize - unclaimedSuffixBytes)} after the declared data and signature; they were not inventoried.`,
);
for (const refusal of new Set(
partitions.flatMap((partition) =>
partition.extractRefusal === null ? [] : [partition.extractRefusal],
@@ -1188,6 +1199,7 @@ export const parseAndroidOtaPayload = (
: null,
apexInfo: manifest.value.apex,
blobTruncated,
unclaimedSuffixBytes,
limitations,
});
};