diff --git a/src/domain/firmware/androidSparseImage.ts b/src/domain/firmware/androidSparseImage.ts index 3fdef48de02..d42b39a1fa2 100644 --- a/src/domain/firmware/androidSparseImage.ts +++ b/src/domain/firmware/androidSparseImage.ts @@ -539,43 +539,33 @@ export class AndroidSparseImageAccumulator { this.#walked += 1; this.#blocks += BigInt(chunk.outputBytes) / BigInt(this.#header.blockSize); this.#end += chunk.totalSize; - if (chunk.kind === "raw") { - this.#counts.raw += 1; - this.#covered.raw += chunk.outputBytes; - if (chunk.outputBytes > 0) - this.#runs.push({ - kind: "raw", - offset: chunk.dataOffset, - length: chunk.outputBytes, - }); - } else if (chunk.kind === "fill") { - this.#counts.fill += 1; - this.#covered.fill += chunk.outputBytes; - const pattern = Buffer.from(chunk.pattern).toString("hex"); - if (!this.#fillPatterns.has(pattern)) { - if (this.#fillPatterns.size < ANDROID_SPARSE_LISTED_CHUNKS) - this.#fillPatterns.add(pattern); - else this.#fillPatternsOmitted = true; - } - if (chunk.outputBytes > 0) - this.#runs.push({ - kind: "fill", - pattern: chunk.pattern, - length: chunk.outputBytes, - }); - } else if (chunk.kind === "dont-care") { - this.#counts.dontCare += 1; - this.#covered.dontCare += chunk.outputBytes; - if (chunk.outputBytes > 0) - this.#runs.push({ kind: "dont-care", length: chunk.outputBytes }); - } else { + if (chunk.kind === "crc32") { this.#counts.crc32 += 1; if (this.#crc32Chunks.length < ANDROID_SPARSE_LISTED_CHUNKS) this.#crc32Chunks.push({ fileOffset: chunk.fileOffset, value: chunk.value, }); + return; } + const key = chunk.kind === "dont-care" ? "dontCare" : chunk.kind; + const length = chunk.outputBytes; + this.#counts[key] += 1; + this.#covered[key] += length; + if (chunk.kind === "fill") { + const pattern = Buffer.from(chunk.pattern).toString("hex"); + if (!this.#fillPatterns.has(pattern)) { + if (this.#fillPatterns.size < ANDROID_SPARSE_LISTED_CHUNKS) + this.#fillPatterns.add(pattern); + else this.#fillPatternsOmitted = true; + } + } + if (length <= 0) return; + if (chunk.kind === "raw") + this.#runs.push({ kind: "raw", offset: chunk.dataOffset, length }); + else if (chunk.kind === "fill") + this.#runs.push({ kind: "fill", pattern: chunk.pattern, length }); + else this.#runs.push({ kind: "dont-care", length }); } /** Check the walked chunks against the header and build the image. */