From c86e86d697cc00dd00367ee2a4e726d4552e637e Mon Sep 17 00:00:00 2001 From: ShuaixinHuang <1836656514@qq.com> Date: Mon, 30 Nov 2026 16:12:48 +0800 Subject: [PATCH] fix(artifacts): retain stored files in Godot PCK patches (#15180) * fix(artifacts): retain stored files in Godot PCK patches * docs(godot): distinguish stored member flags from removals --------- Co-authored-by: ShuaixinHuang <197200901+ShuaixinHuang@users.noreply.github.com> Co-authored-by: Vincent Koc --- docs/godot-pck.md | 9 +++-- src/artifacts/GodotPckArtifactReader.test.ts | 35 ++++++++++++++++++-- src/artifacts/GodotPckArtifactReader.ts | 25 ++++++++++++-- tests/acceptance/godotPck.test.ts | 29 ++++++++++++++++ 4 files changed, 90 insertions(+), 8 deletions(-) diff --git a/docs/godot-pck.md b/docs/godot-pck.md index 9912ee544b7..372c7406b71 100644 --- a/docs/godot-pck.md +++ b/docs/godot-pck.md @@ -39,8 +39,8 @@ stored `source_path` would mark every member changed between such exports. REA normalizes Unicode to NFC, so a member renamed only between Unicode forms compares unchanged, although Godot treats it as another path. Godot reads `\` as `/` and REA keeps it literal, so a member spelled with backslashes compares -as removed and added. Directory order and offsets are layout. The encryption -bit, the only member flag REA admits, is the occurrence's `encrypted` field. A +as removed and added. Directory order and offsets are layout. For stored +members, the encryption flag is the occurrence's `encrypted` field. A member whose encryption changes compares `unknown` in `metadata` and `availability`: the change is known, but REA does not read encrypted bytes, so whether the script changed is unknown. Godot's exporter @@ -143,7 +143,10 @@ are not evidence of absence. Encrypted directories retain their header and declared file count with unknown entry coverage. Individually encrypted members retain directory metadata with unknown content identity; REA does not decrypt them. Sparse bundles likewise -retain header facts with unknown member coverage. Extraction refuses an +retain header facts with unknown member coverage. For formats 2–4, +flagged patch removal records are omitted from the stored-file inventory. +The reader reports their count and unknown coverage, and keeps the ordinary +members available. Extraction refuses an unreadable directory or encrypted member. This capability does not recover keys, decode Godot resources, decompile GDScript bytecode, analyze signals, apply patch/removal entries or execute targets. diff --git a/src/artifacts/GodotPckArtifactReader.test.ts b/src/artifacts/GodotPckArtifactReader.test.ts index 32f7c32bef5..99f27d747f1 100644 --- a/src/artifacts/GodotPckArtifactReader.test.ts +++ b/src/artifacts/GodotPckArtifactReader.test.ts @@ -371,10 +371,41 @@ describe("GodotPckArtifactReader", () => { }); }); + it.each([2, 3, 4] as const)( + "keeps stored files on both sides of a format %s patch removal record", + async (version) => { + const patch = buildGodotPck(version, [ + { path: "first.gd", data: "one" }, + { path: "gone.gd", data: "", flags: 2 }, + { path: "last.gd", data: "two" }, + ]); + await withReader(patch, async (reader) => { + const coverage: ArtifactReaderTraversal[] = []; + const entries = await list(reader, { + onCoverage: (facts) => coverage.push(facts), + }); + expect(entries.map((entry) => entry.path)).toEqual([ + "first.gd", + "last.gd", + ]); + expect(await text(await reader.open(entries[1]!))).toBe("two"); + expect(coverage).toEqual([ + { + status: "unknown", + limitations: [expect.stringContaining("1 Godot PCK patch removal")], + }, + ]); + expect(reader.formatMetadata()).toMatchObject({ + declared_file_count: 3, + }); + }); + }, + ); + it.each([ [ - "a patch removal entry", - buildGodotPck(3, [{ path: "gone.gd", data: "", flags: 2 }]), + "unknown member flags", + buildGodotPck(3, [{ path: "gone.gd", data: "", flags: 8 }]), "unavailable", ], [ diff --git a/src/artifacts/GodotPckArtifactReader.ts b/src/artifacts/GodotPckArtifactReader.ts index ad1ec9397e7..e2da200f4bc 100644 --- a/src/artifacts/GodotPckArtifactReader.ts +++ b/src/artifacts/GodotPckArtifactReader.ts @@ -38,6 +38,7 @@ const PACK_DIR_ENCRYPTED = 1; const PACK_REL_FILEBASE = 2; const PACK_SPARSE_BUNDLE = 4; const PACK_FILE_ENCRYPTED = 1; +const PACK_FILE_REMOVAL = 2; const DIRECTORY_CHUNK_BYTES = 64 * 1024; const UTF8 = strictUtf8Decoder("preserve"); @@ -98,6 +99,7 @@ export class GodotPckArtifactReader extends PositionalArtifactReader { ); const entries: PositionalArtifactEntry[] = []; let retainedBytes = 0; + let removalRecords = 0; let declaredPlaintextBytes = 0n; const expansionBudget = BigInt( this.expandedBytes ?? @@ -112,6 +114,10 @@ export class GodotPckArtifactReader extends PositionalArtifactReader { index, retainedBytes, ); + if (metadata === undefined) { + removalRecords++; + continue; + } // Aliases are valid, but each path causes another hash/copy. Admit the // complete directory before yielding anything, including all-zero claims. if (!metadata.encrypted) { @@ -145,7 +151,18 @@ export class GodotPckArtifactReader extends PositionalArtifactReader { ); } await this.verifyCarrier(signal); - return { entries, coverage: { status: "complete", limitations: [] } }; + return { + entries, + coverage: + removalRecords === 0 + ? { status: "complete", limitations: [] } + : { + status: "unknown", + limitations: [ + `${String(removalRecords)} Godot PCK patch removal record(s) were omitted from the stored-file inventory.`, + ], + }, + }; } async #readEntry( cursor: PckCursor, @@ -166,12 +183,14 @@ export class GodotPckArtifactReader extends PositionalArtifactReader { const md5 = (await cursor.bytes(16)).toString("hex"); // Godot 3's format 1 has neither per-file flags nor a file-base field. const flags = header.format_version === 1 ? 0 : await cursor.uint32(); - if ((flags & ~PACK_FILE_ENCRYPTED) !== 0) + if ((flags & ~(PACK_FILE_ENCRYPTED | PACK_FILE_REMOVAL)) !== 0) throw new ArtifactReaderFailure( "unavailable", - `Godot patch or unknown member flags are unsupported: 0x${flags.toString(16)}`, + `Godot unknown member flags are unsupported: 0x${flags.toString(16)}`, ); const sourcePath = pckMemberPath(rawPath); + // A format 2–4 removal references a path in an overlay, with no member bytes. + if ((flags & PACK_FILE_REMOVAL) !== 0) return undefined; if (header.format_version === 1 && offset === 0n) throw new ArtifactReaderFailure( "unavailable", diff --git a/tests/acceptance/godotPck.test.ts b/tests/acceptance/godotPck.test.ts index f8c39f40a72..aed01677957 100644 --- a/tests/acceptance/godotPck.test.ts +++ b/tests/acceptance/godotPck.test.ts @@ -34,6 +34,35 @@ const graphFrom = (reply: unknown) => { ); }; +cliTest( + "retains the ordinary files in a Godot patch inspection", + async ({ cli }) => { + const root = await createTestTempDirectory("rea-pck-removal-cli-"); + const source = join(root, "patch.pck"); + await writeFile( + source, + buildGodotPck(3, [ + { path: "res://first.txt", data: "one" }, + { path: "res://gone.txt", data: "", flags: 2 }, + { path: "res://last.txt", data: "two" }, + ]), + ); + const inspected = await cli.run({ + arguments: ["inspect-artifact", source, "--json"], + environment: { TMPDIR: root, TMP: root, TEMP: root }, + }); + expect(inspected.exitCode, inspected.stdout + inspected.stderr).toBe(0); + const graph = graphFrom(inspected.json); + expect(graph.coverage.status).toBe("unknown"); + expect(graph.limitations.join(" ")).toContain("1 Godot PCK patch removal"); + expect(graph.occurrences.map((row) => row.logical_path).sort()).toEqual([ + ".", + "first.txt", + "last.txt", + ]); + }, +); + cliTest.for([1, 2, 3, 4] as const)( "inspects and safely extracts format %s PCK through the compiled CLI", async (version, { cli }) => {