From 2a31e064f35e53b40915cfc3ee3d698295d93715 Mon Sep 17 00:00:00 2001 From: morluto <76467478+morluto@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:54:31 +0800 Subject: [PATCH] feat(flutter): carry the value of each fixed Flutter allowance (#11641) * feat(flutter): carry the value of each fixed Flutter allowance Each Flutter fixed allowance now passes limit and unit, so details.refusal states the ceiling. The ABI inventory refusal names the ceiling that was exceeded: the ABI count or the library path bytes. * fix(artifacts): name the ZIP decoder window ceiling in Flutter and trace refusals A Zstandard member whose window exceeds the ZIP reader's fixed 128 MiB allowance now carries that ceiling as a typed fixed allowance (limit, unit, and the recompression narrowing). Flutter reported any ZIP reader limit as its APK metadata read allowance, and Playwright trace import as a recorder-chunk limit; both now keep the reader's ceiling. * fix(flutter): report the APK expansion ceiling and keep JNI recompression advice A ZIP reader limit with a reader-owned parameter (the size-derived expansion budget) is no longer reported as the Flutter metadata read allowance; Flutter exposes no control for it, so it is a fixed ceiling with the reader's effective value. The JNI library failure message carries the reader-named ceiling's narrowing, since that report has no refusal field. * test(artifacts): compare decoder-window advice with its owning ceiling --- src/android/AndroidJniLibraries.ts | 9 +- .../PlaywrightTraceDecoder.test.ts | 41 ++++++ .../history/playwrightTrace/TraceFailure.ts | 12 +- src/flutter/FlutterBuildProvider.ts | 124 +++++++++++++---- src/resources/ZipArtifactReader.ts | 13 +- .../android/androidJniLibraries.test.ts | 23 ++++ .../cli/artifactZstandardWindow.test.ts | 19 ++- .../filesystem/flutterBuildProvider.test.ts | 130 ++++++++++++++++-- tests/fixtures/zipZstandard.ts | 3 +- 9 files changed, 330 insertions(+), 44 deletions(-) diff --git a/src/android/AndroidJniLibraries.ts b/src/android/AndroidJniLibraries.ts index a318a2f35c..d3de29cf3f 100644 --- a/src/android/AndroidJniLibraries.ts +++ b/src/android/AndroidJniLibraries.ts @@ -45,7 +45,14 @@ const jniReadFailure = ( ): NonNullable => { const message = errorMessage(cause); if (!(cause instanceof ArtifactReaderFailure)) return { kind: "io", message }; - if (cause.reason !== "integrity") return { kind: cause.reason, message }; + // The library report has only a message, so a reader-named ceiling's + // narrowing (such as recompressing a Zstandard member) travels in it. + const narrowing = cause.fixedAllowance?.narrowing; + if (cause.reason !== "integrity") + return { + kind: cause.reason, + message: narrowing === undefined ? message : `${message} ${narrowing}`, + }; if (cause.integrityCheck === undefined) throw invariantViolation( "An integrity reader failure reached the JNI inventory without its check.", diff --git a/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts b/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts index 0dde853cef..bab8f91b78 100644 --- a/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts +++ b/src/browser/history/playwrightTrace/PlaywrightTraceDecoder.test.ts @@ -9,6 +9,14 @@ import { playwrightTraceFixture, playwrightTracePathFixture, } from "../../../../tests/fixtures/playwrightTrace.js"; +import { createTestTempDirectory } from "../../../../tests/fixtures/temporaryDirectory.js"; +import { + zstandardWindowFrameFixture, + zstandardZipFixture, +} from "../../../../tests/fixtures/zipZstandard.js"; +import { join } from "node:path"; +import { analysisRefusalRemediation } from "../../../domain/analysisRefusal.js"; +import { ZIP_ZSTANDARD_WINDOW_CEILING } from "../../../resources/ZipArtifactReader.js"; it("imports real v10 recorder text with per-stream identity and resource presence, preserving source bytes", async () => { const fixture = await playwrightTraceFixture({ resources: true }); @@ -476,3 +484,36 @@ it("keeps duplicate resource names ambiguous instead of selecting one ZIP occurr await resources.close(); } }); + +it("names the ZIP decoder window for a large-window recorder stream", async () => { + const root = await createTestTempDirectory("rea-trace-zstd-"); + const path = join(root, "trace.zip"); + // Window descriptor 0x90 declares 256 MiB, above the ZIP reader's window. + const { content, compressed } = zstandardWindowFrameFixture(0x90); + await writeFile( + path, + zstandardZipFixture(content, { compressed, name: "trace.trace" }), + ); + const resources = new ArtifactResourceScope(); + try { + const result = await new PlaywrightTraceDecoder(resources).inspect(path); + if (result.ok) throw new Error("Expected decoder window refusal"); + const projected = projectAnalysisError(result.error); + expect(projected.code).toBe("resource_constraint"); + expect(projected.details?.refusal).toMatchObject({ + kind: "fixed_ceiling", + allowance: "The ZIP Zstandard decoder window allowance", + limit: 2 ** 27, + }); + // The recovery is the reader's ceiling through the refusal formatter. + expect(projected.remediation.action).toBe( + analysisRefusalRemediation({ + kind: "fixed_ceiling", + operation: "inspect_playwright_trace", + ceiling: ZIP_ZSTANDARD_WINDOW_CEILING, + }), + ); + } finally { + await resources.close(); + } +}); diff --git a/src/browser/history/playwrightTrace/TraceFailure.ts b/src/browser/history/playwrightTrace/TraceFailure.ts index ab175f4319..521f16e24d 100644 --- a/src/browser/history/playwrightTrace/TraceFailure.ts +++ b/src/browser/history/playwrightTrace/TraceFailure.ts @@ -33,11 +33,13 @@ export const traceFailure = (cause: unknown, path: string): AnalysisError => { cause.boundary ?? "memory", cause.message, null, - { - cause, - remediationAction: - "Select a smaller complete recorder chunk. Reply selection does not increase archive parsing allowances.", - }, + cause.fixedAllowance === undefined + ? { + cause, + remediationAction: + "Select a smaller complete recorder chunk. Reply selection does not increase archive parsing allowances.", + } + : { cause, retryable: false, fixedAllowance: cause.fixedAllowance }, ); if (cause.reason === "format" || cause.reason === "path") return stableArtifactInputFailure(cause, operation); diff --git a/src/flutter/FlutterBuildProvider.ts b/src/flutter/FlutterBuildProvider.ts index 03d966b286..6f3d46fc7e 100644 --- a/src/flutter/FlutterBuildProvider.ts +++ b/src/flutter/FlutterBuildProvider.ts @@ -46,7 +46,7 @@ import { carriedReason, } from "../domain/analysisErrorCore.js"; import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js"; -import { fixedAllowanceOptions as flutterBudget } from "../domain/fixedAllowanceRemediation.js"; +import { fixedAllowanceOptions } from "../domain/fixedAllowanceRemediation.js"; import { AnalysisError, type AnalysisPartialObservation, @@ -89,6 +89,45 @@ const MAX_FLUTTER_ABIS = 32; const SYMBOL_PAIR_COUNT = 2; const IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/u; +/** Each release-fixed Flutter ceiling with the value that refused the input. */ +const FLUTTER_ALLOWANCES = { + apkMetadataRead: fixedAllowanceOptions( + "The Flutter APK metadata read allowance", + "parser", + { limit: APK_METADATA_READ_MAX_BYTES, unit: "bytes" }, + ), + abiInventory: fixedAllowanceOptions( + "The Flutter ABI inventory allowance", + "parser", + { limit: MAX_FLUTTER_ABIS, unit: "ABIs" }, + ), + libraryPath: fixedAllowanceOptions( + "The Flutter library path allowance", + "parser", + { limit: MAX_FLUTTER_LIBRARY_PATH_BYTES, unit: "bytes" }, + ), + apkSnapshot: fixedAllowanceOptions( + "the Flutter APK snapshot allowance", + "input", + { limit: APK_MAX_BYTES, unit: "bytes" }, + ), + libraryRead: fixedAllowanceOptions( + "the Flutter library read allowance", + "input", + { limit: LIBRARY_MAX_BYTES, unit: "bytes" }, + ), + cumulativeExtraction: fixedAllowanceOptions( + "the Flutter cumulative extraction allowance", + "input", + { limit: TOTAL_EXTRACTION_MAX_BYTES, unit: "bytes" }, + ), + snapshotHashCandidates: fixedAllowanceOptions( + "The Flutter snapshot-hash candidate allowance", + "parser", + { limit: MAX_SNAPSHOT_HASH_CANDIDATES, unit: "candidates" }, + ), +} as const; + /** * Stream a local file digest without retaining large files in memory. * Aborts between chunks so a cancellation cannot run a digest to completion. @@ -207,16 +246,7 @@ const mapInputFailure = ( cause, }); if (cause instanceof ArtifactReaderFailure && cause.reason === "limit") - return new AnalysisResourceConstraintError( - operation, - "memory", - cause.message, - { max_metadata_read_bytes: APK_METADATA_READ_MAX_BYTES }, - { - cause, - ...flutterBudget("The Flutter APK metadata read allowance", "parser"), - }, - ); + return readerLimitFailure(operation, cause); return new AnalysisInputError(operation, { cause }, [ { path: ["path"], @@ -226,6 +256,52 @@ const mapInputFailure = ( ]); }; +/** + * Report the ZIP reader ceiling that refused the APK. A ceiling the reader + * names (the Zstandard decoder window) keeps its name. The archive expansion + * budget is derived from the APK's size, and Flutter offers no control that + * raises it, so it is fixed for this request. The ZIP reader's remaining limit + * is the metadata read budget this provider selects. + */ +const readerLimitFailure = ( + operation: string, + cause: ArtifactReaderFailure, +): AnalysisError => { + if (cause.fixedAllowance !== undefined) + return new AnalysisResourceConstraintError( + operation, + cause.boundary === "file-size" ? "file-size" : "memory", + cause.message, + null, + { cause, retryable: false, fixedAllowance: cause.fixedAllowance }, + ); + if (cause.readerLimit !== undefined) { + const { effective_value: limit, required_value: required } = + cause.readerLimit; + return new AnalysisResourceConstraintError( + operation, + "memory", + `The APK's declared member sizes${required === undefined ? "" : ` (${String(required)} bytes)`} exceed its ${String(limit)}-byte expansion allowance.`, + { max_expanded_bytes: limit }, + { + cause, + ...fixedAllowanceOptions( + "The Flutter APK expansion allowance (derived from the APK size)", + "parser", + { limit, unit: cause.readerLimit.unit }, + ), + }, + ); + } + return new AnalysisResourceConstraintError( + operation, + "memory", + cause.message, + { max_metadata_read_bytes: APK_METADATA_READ_MAX_BYTES }, + { cause, ...FLUTTER_ALLOWANCES.apkMetadataRead }, + ); +}; + /** Name a missing or non-file selection instead of blaming package bytes. */ const inputFailureMessage = (path: string, cause: unknown): string => { if ( @@ -325,7 +401,9 @@ const collectFlutterLibraries = async ( max_flutter_abis: MAX_FLUTTER_ABIS, max_library_path_bytes: MAX_FLUTTER_LIBRARY_PATH_BYTES, }, - flutterBudget("The Flutter ABI inventory allowance", "parser"), + abis.size > MAX_FLUTTER_ABIS + ? FLUTTER_ALLOWANCES.abiInventory + : FLUTTER_ALLOWANCES.libraryPath, ); libraries.push({ entry, @@ -361,7 +439,7 @@ const checkApkSize = (operation: string, bytes: number): void => { "file-size", `The selected APK exceeds the ${String(APK_MAX_BYTES)}-byte snapshot budget`, { max_apk_bytes: APK_MAX_BYTES, observed_bytes: bytes }, - flutterBudget("the Flutter APK snapshot allowance", "input"), + FLUTTER_ALLOWANCES.apkSnapshot, ); }; @@ -810,7 +888,7 @@ export class FlutterBuildProvider { "file-size", `${entry.path} exceeds the library read budget`, { max_library_bytes: LIBRARY_MAX_BYTES, entry_path: entry.path }, - flutterBudget("the Flutter library read allowance", "input"), + FLUTTER_ALLOWANCES.libraryRead, ), ); } @@ -831,7 +909,7 @@ export class FlutterBuildProvider { max_total_bytes: TOTAL_EXTRACTION_MAX_BYTES, declared_total: declaredTotal, }, - flutterBudget("the Flutter cumulative extraction allowance", "input"), + FLUTTER_ALLOWANCES.cumulativeExtraction, ), ); @@ -879,7 +957,7 @@ export class FlutterBuildProvider { max_library_bytes: LIBRARY_MAX_BYTES, entry_path: entry.path, }, - flutterBudget("the Flutter library read allowance", "input"), + FLUTTER_ALLOWANCES.libraryRead, ), ); hash.update(view); @@ -897,10 +975,7 @@ export class FlutterBuildProvider { "file-size", `cumulative library extraction across ${String(flutterEntries.length)} entries exceeds the ${String(TOTAL_EXTRACTION_MAX_BYTES)}-byte budget`, { max_total_bytes: TOTAL_EXTRACTION_MAX_BYTES }, - flutterBudget( - "the Flutter cumulative extraction allowance", - "input", - ), + FLUTTER_ALLOWANCES.cumulativeExtraction, ), ); } @@ -919,10 +994,7 @@ export class FlutterBuildProvider { max_snapshot_hash_candidates: MAX_SNAPSHOT_HASH_CANDIDATES, entry_path: entry.path, }, - flutterBudget( - "The Flutter snapshot-hash candidate allowance", - "parser", - ), + FLUTTER_ALLOWANCES.snapshotHashCandidates, ), ); facts.set(abi, { @@ -1124,7 +1196,7 @@ export class FlutterBuildProvider { "file-size", `lib/${selected.abi}/libapp.so declares ${String(declared)} bytes, exceeding the ${String(LIBRARY_MAX_BYTES)}-byte read budget`, { max_library_bytes: LIBRARY_MAX_BYTES }, - flutterBudget("the Flutter library read allowance", "input"), + FLUTTER_ALLOWANCES.libraryRead, ), ); const imagePath = join(snapshot.root, "libapp.so"); @@ -1154,7 +1226,7 @@ export class FlutterBuildProvider { "file-size", `lib/${selected.abi}/libapp.so exceeds the ${String(LIBRARY_MAX_BYTES)}-byte read budget while streaming`, { max_library_bytes: LIBRARY_MAX_BYTES }, - flutterBudget("the Flutter library read allowance", "input"), + FLUTTER_ALLOWANCES.libraryRead, ), ); imageHash.update(view); diff --git a/src/resources/ZipArtifactReader.ts b/src/resources/ZipArtifactReader.ts index b4462de9af..33f12de7f9 100644 --- a/src/resources/ZipArtifactReader.ts +++ b/src/resources/ZipArtifactReader.ts @@ -55,6 +55,7 @@ import { readFileHandleRange } from "../filesystem/readFileHandleRange.js"; import { strictUtf8Decoder } from "../domain/strictUtf8.js"; import { decodeZipCp437 } from "../domain/zip/zipEntryText.js"; import { invariantViolation } from "../domain/internalInvariant.js"; +import type { FixedAllowance } from "../domain/fixedAllowanceRemediation.js"; const ZIP_UTF8_DECODER = strictUtf8Decoder("preserve"); @@ -64,7 +65,16 @@ const ZIP_ZSTANDARD_WINDOW_LOG_MAX = 27; const ZIP_ZSTANDARD_WINDOW_ALLOWANCE = `${String(2 ** (ZIP_ZSTANDARD_WINDOW_LOG_MAX - 20))} MiB`; /** A frame above the window cap is a deliberate resource refusal, not damage. */ -const ZIP_ZSTANDARD_WINDOW_LIMIT = `ZIP Zstandard member requires a decoder window above REA's fixed ${ZIP_ZSTANDARD_WINDOW_ALLOWANCE} allowance; the archive is not necessarily corrupt, and this limit cannot be raised at runtime. Recompress the member with a window of at most ${ZIP_ZSTANDARD_WINDOW_ALLOWANCE}, or decompress it with a tool that admits larger windows, then retry.`; +const ZIP_ZSTANDARD_WINDOW_LIMIT = `ZIP Zstandard member requires a decoder window above REA's fixed ${ZIP_ZSTANDARD_WINDOW_ALLOWANCE} allowance; the archive is not necessarily corrupt.`; + +/** The fixed method-93 decoder window ceiling, with the request change that fits it. */ +export const ZIP_ZSTANDARD_WINDOW_CEILING: FixedAllowance = { + name: "The ZIP Zstandard decoder window allowance", + kind: "parser", + limit: 2 ** ZIP_ZSTANDARD_WINDOW_LOG_MAX, + unit: "bytes", + narrowing: `Recompress the member with a window of at most ${ZIP_ZSTANDARD_WINDOW_ALLOWANCE}, or decompress it with a tool that admits larger windows, then retry.`, +}; /** Keep zip.js's framing, CRC, size checks and backpressure for method 93. */ class ZipZstandardDecompressionStream { @@ -632,6 +642,7 @@ const typedZipFailure = ( return new ArtifactReaderFailure("limit", ZIP_ZSTANDARD_WINDOW_LIMIT, { cause, boundary: "memory", + fixedAllowance: ZIP_ZSTANDARD_WINDOW_CEILING, }); const invalidZstandard = compressionMethod === 93 && diff --git a/tests/boundary/android/androidJniLibraries.test.ts b/tests/boundary/android/androidJniLibraries.test.ts index a51368d7f1..3f58fb60ea 100644 --- a/tests/boundary/android/androidJniLibraries.test.ts +++ b/tests/boundary/android/androidJniLibraries.test.ts @@ -25,6 +25,11 @@ import { } from "../../../src/domain/android/androidJniBindings.js"; import { androidPartialObservationSchema } from "../../../src/domain/android/androidPartialObservation.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { ZIP_ZSTANDARD_WINDOW_CEILING } from "../../../src/resources/ZipArtifactReader.js"; +import { + zstandardWindowFrameFixture, + zstandardZipFixture, +} from "../../fixtures/zipZstandard.js"; import { jniElfFixture } from "../../fixtures/android/jniElf.js"; import { ArtifactReaderFailure, @@ -217,6 +222,24 @@ it("retains a malformed selected library's exact carrier identity and digest", a expect(source.resources.hasPending).toBe(false); }); +it("keeps the ZIP decoder window's recompression advice in the library failure", async () => { + const directory = await createTestTempDirectory("rea-android-jni-zstd-"); + const snapshot = join(directory, "window.apk"); + // Window descriptor 0x90 declares 256 MiB, above the ZIP reader's window. + const { content, compressed } = zstandardWindowFrameFixture(0x90); + const bytes = zstandardZipFixture(content, { compressed, name: LIBRARY }); + await writeFile(snapshot, bytes); + const resources = new ArtifactResourceScope(); + onTestFinished(async () => { + await resources.close(); + }); + const result = await read({ snapshot, apkSha256: digest(bytes), resources }); + expect(result.libraries[0]?.failure).toMatchObject({ + kind: "limit", + message: expect.stringContaining(ZIP_ZSTANDARD_WINDOW_CEILING.narrowing!), + }); +}); + it("preserves declared capacity metadata without presenting unread bytes as verified", async () => { const source = await fixture(); const originalEntries = ZipArtifactReader.prototype.entries; diff --git a/tests/boundary/cli/artifactZstandardWindow.test.ts b/tests/boundary/cli/artifactZstandardWindow.test.ts index bde4a60299..9d6b243d41 100644 --- a/tests/boundary/cli/artifactZstandardWindow.test.ts +++ b/tests/boundary/cli/artifactZstandardWindow.test.ts @@ -11,6 +11,8 @@ import { zstandardZipFixture, } from "../../fixtures/zipZstandard.js"; import { cliTest } from "../../support/cli/cliFixture.js"; +import { analysisRefusalRemediation } from "../../../src/domain/analysisRefusal.js"; +import { ZIP_ZSTANDARD_WINDOW_CEILING } from "../../../src/resources/ZipArtifactReader.js"; const expectRefusal = (diagnostic: unknown, large: boolean): void => { expect(diagnostic).toMatchObject({ @@ -23,8 +25,23 @@ const expectRefusal = (diagnostic: unknown, large: boolean): void => { if (large) { expect(diagnostic).toMatchObject({ message: expect.stringContaining("fixed 128 MiB allowance"), + details: { + refusal: { + kind: "fixed_ceiling", + allowance: ZIP_ZSTANDARD_WINDOW_CEILING.name, + limit: 2 ** 27, + unit: "bytes", + narrowing: ZIP_ZSTANDARD_WINDOW_CEILING.narrowing, + }, + }, + // The recovery is the reader's ceiling through the refusal formatter. remediation: { - action: expect.stringContaining("cannot be raised at runtime"), + action: analysisRefusalRemediation({ + kind: "fixed_ceiling", + operation: (diagnostic as { details: { operation: string } }).details + .operation, + ceiling: ZIP_ZSTANDARD_WINDOW_CEILING, + }), }, }); expect(JSON.stringify(diagnostic)).not.toContain("fresh copy"); diff --git a/tests/boundary/filesystem/flutterBuildProvider.test.ts b/tests/boundary/filesystem/flutterBuildProvider.test.ts index ae5bc353e7..e09c1ab927 100644 --- a/tests/boundary/filesystem/flutterBuildProvider.test.ts +++ b/tests/boundary/filesystem/flutterBuildProvider.test.ts @@ -47,6 +47,12 @@ import { realRm, } from "../../fixtures/flutterCleanup.js"; import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js"; +import { analysisRefusalRemediation } from "../../../src/domain/analysisRefusal.js"; +import { ZIP_ZSTANDARD_WINDOW_CEILING } from "../../../src/resources/ZipArtifactReader.js"; +import { + zstandardWindowFrameFixture, + zstandardZipFixture, +} from "../../fixtures/zipZstandard.js"; import { ZipArtifactReader } from "../../../src/resources/index.js"; vi.mock("node:fs", async (importOriginal) => { @@ -1102,6 +1108,12 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)( expect(projected.code).toBe("resource_constraint"); expect(projected.retryable).toBe(false); expect(projected.remediation.action).toContain("APK snapshot allowance"); + expect(projected.details?.refusal).toMatchObject({ + kind: "fixed_ceiling", + allowance_kind: "input", + limit: 2 * 1024 ** 3, + unit: "bytes", + }); expect(projected.remediation.action).not.toMatch(/evidence reply/u); expect(result.error).toMatchObject({ operation, @@ -1268,6 +1280,82 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)( reportedLimits: { max_metadata_read_bytes: 8 * 1024 ** 2 }, }); expect(result.error.message).toContain("ZIP metadata read requires"); + expect(projectAnalysisError(result.error).details?.refusal).toMatchObject({ + kind: "fixed_ceiling", + limit: 8 * 1024 ** 2, + unit: "bytes", + }); + }, +); + +it.each(["identify_flutter_build", "inspect_dart_aot"] as const)( + "%s names the APK expansion allowance, not the metadata read allowance, for oversized declared members", + async (operation) => { + const root = await createTestTempDirectory("rea-flutter-expansion-"); + const path = join(root, "declared.apk"); + // A small archive declaring a 300 MiB member exceeds the 256 MiB floor + // of its size-derived expansion budget while its metadata fits. + await writeFile( + path, + zstandardZipFixture(Buffer.from("x"), { + method: 0, + compressed: Buffer.from("x"), + declaredSize: 300 * 1024 ** 2, + name: "assets/declared.bin", + }), + ); + const provider = new FlutterBuildProvider(); + onTestFinished(() => provider.close()); + const result = await provider.execute({ operation, input: { path } }); + if (result.ok) throw new Error("expected an expansion refusal"); + const projected = projectAnalysisError(result.error); + expect(projected.code).toBe("resource_constraint"); + expect(projected.details?.refusal).toMatchObject({ + kind: "fixed_ceiling", + allowance_kind: "parser", + limit: 256 * 1024 ** 2, + unit: "bytes", + }); + expect(projected.details?.reported_limits).toEqual({ + max_expanded_bytes: 256 * 1024 ** 2, + }); + }, +); + +it.each(["identify_flutter_build", "inspect_dart_aot"] as const)( + "%s names the ZIP decoder window, not the metadata read allowance, for a large-window library", + async (operation) => { + const root = await createTestTempDirectory("rea-flutter-zstd-"); + const path = join(root, "zstd-window.apk"); + // Window descriptor 0x90 declares 256 MiB, above the ZIP reader's window. + const { content, compressed } = zstandardWindowFrameFixture(0x90); + await writeFile( + path, + zstandardZipFixture(content, { + compressed, + name: "lib/arm64-v8a/libapp.so", + }), + ); + const provider = new FlutterBuildProvider(); + onTestFinished(() => provider.close()); + const result = await provider.execute({ operation, input: { path } }); + if (result.ok) throw new Error("expected a decoder window refusal"); + const projected = projectAnalysisError(result.error); + expect(projected.code).toBe("resource_constraint"); + expect(projected.details?.refusal).toMatchObject({ + kind: "fixed_ceiling", + allowance: "The ZIP Zstandard decoder window allowance", + limit: 128 * 1024 ** 2, + unit: "bytes", + }); + // The recovery is the reader's ceiling through the refusal formatter. + expect(projected.remediation.action).toBe( + analysisRefusalRemediation({ + kind: "fixed_ceiling", + operation, + ceiling: ZIP_ZSTANDARD_WINDOW_CEILING, + }), + ); }, ); @@ -1467,15 +1555,26 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)( }, ); -it.each(["identify_flutter_build", "inspect_dart_aot"] as const)( - "%s refuses ABI metadata expansion before opening empty libraries", - async (operation) => { +it.each([ + ["identify_flutter_build", "ABI", 32, "ABIs"], + ["inspect_dart_aot", "ABI", 32, "ABIs"], + ["identify_flutter_build", "path", 1024, "bytes"], +] as const)( + "%s refuses %s metadata expansion before opening empty libraries", + async (operation, shape, limit, unit) => { const path = await buildApk( "many-abis.apk", - Array.from({ length: 33 }, (_, index) => ({ - path: `lib/abi_${String(index)}/libapp.so`, - bytes: Buffer.alloc(0), - })), + shape === "ABI" + ? Array.from({ length: 33 }, (_, index) => ({ + path: `lib/abi_${String(index)}/libapp.so`, + bytes: Buffer.alloc(0), + })) + : [ + { + path: `lib/${"a".repeat(1024)}/libapp.so`, + bytes: Buffer.alloc(0), + }, + ], ); const extract = vi.spyOn(ZipArtifactReader.prototype, "open"); onTestFinished(() => extract.mockRestore()); @@ -1483,7 +1582,14 @@ it.each(["identify_flutter_build", "inspect_dart_aot"] as const)( onTestFinished(() => provider.close()); const result = await provider.execute({ operation, input: { path } }); if (result.ok) throw new Error("ABI expansion must be refused"); - expect(projectAnalysisError(result.error).code).toBe("resource_constraint"); + const projected = projectAnalysisError(result.error); + expect(projected.code).toBe("resource_constraint"); + expect(projected.details?.refusal).toMatchObject({ + kind: "fixed_ceiling", + allowance_kind: "parser", + limit, + unit, + }); expect(extract).not.toHaveBeenCalled(); }, ); @@ -1697,7 +1803,13 @@ it("refuses truncated hash-candidate evidence and includes five-character tokens input: { path }, }); if (result.ok) throw new Error("Incomplete candidate set must be explicit"); - expect(projectAnalysisError(result.error).code).toBe("resource_constraint"); + const projected = projectAnalysisError(result.error); + expect(projected.code).toBe("resource_constraint"); + expect(projected.details?.refusal).toMatchObject({ + kind: "fixed_ceiling", + limit: 64, + unit: "candidates", + }); }); it.each([ diff --git a/tests/fixtures/zipZstandard.ts b/tests/fixtures/zipZstandard.ts index ee7c149871..daf195a0e1 100644 --- a/tests/fixtures/zipZstandard.ts +++ b/tests/fixtures/zipZstandard.ts @@ -19,9 +19,10 @@ export const zstandardZipFixture = ( readonly crc?: number; readonly declaredSize?: number; readonly compressed?: Buffer; + readonly name?: string; } = {}, ): Buffer => { - const name = Buffer.from("member.txt"); + const name = Buffer.from(options.name ?? "member.txt"); const compressed = options.compressed ?? zstdCompressSync(content); const method = options.method ?? 93; const checksum = options.crc ?? crc32(content);