From 006581b838fe64cd2a1b5b22d508c525e92bdf2d Mon Sep 17 00:00:00 2001 From: gensokyo-dev Date: Sat, 21 Nov 2026 18:26:58 +0000 Subject: [PATCH] refactor(desktop): read OpenPGP packet lengths through BinaryReader OpenPGP packet headers read their one-, two- and four-byte lengths with raw Buffer reads after the header-width checks. Read them through an openpgp BinaryReader. This was the last counted raw numeric read, so the raw-buffer-read baseline is removed and the guard now refuses any new copy outright. The CI change-scope test names another baseline file as its static-only path. Refs #11865 Co-Authored-By: gensokyo-dev <342580529+gensokyo-dev@users.noreply.github.com> --- scripts/verify/baselines/raw-buffer-read.json | 3 --- src/domain/desktop/openPgpKeys.ts | 15 +++++++++++++-- tests/boundary/filesystem/ciChangeScope.test.ts | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) delete mode 100644 scripts/verify/baselines/raw-buffer-read.json diff --git a/scripts/verify/baselines/raw-buffer-read.json b/scripts/verify/baselines/raw-buffer-read.json deleted file mode 100644 index c8e9b45f0b..0000000000 --- a/scripts/verify/baselines/raw-buffer-read.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "src/domain/desktop/openPgpKeys.ts": 2 -} diff --git a/src/domain/desktop/openPgpKeys.ts b/src/domain/desktop/openPgpKeys.ts index 549b544caf..b020ef2c70 100644 --- a/src/domain/desktop/openPgpKeys.ts +++ b/src/domain/desktop/openPgpKeys.ts @@ -1,5 +1,6 @@ import { createHash } from "node:crypto"; +import { BinaryReader } from "../binaryContainer.js"; import { err, ok, type Result } from "../result.js"; import { dearmorPublicKeys, isArmoredKey } from "./aptRepositories.js"; @@ -22,10 +23,16 @@ const packetHeader = ( if ((first & 0x40) === 0) { const width = [1, 2, 4][first & 0x03]; if (width === undefined || at + 1 + width > bytes.length) return undefined; + const reader = new BinaryReader(bytes, false, "openpgp"); return { tag: (first >> 2) & 0x0f, header: 1 + width, - body: bytes.readUIntBE(at + 1, width), + body: + width === 1 + ? reader.u8(at + 1) + : width === 2 + ? reader.u16(at + 1) + : reader.u32(at + 1), }; } const tag = first & 0x3f; @@ -39,7 +46,11 @@ const packetHeader = ( : { tag, header: 3, body: ((length - 192) << 8) + next + 192 }; } if (length !== 255 || at + 6 > bytes.length) return undefined; - return { tag, header: 6, body: bytes.readUInt32BE(at + 2) }; + return { + tag, + header: 6, + body: new BinaryReader(bytes, false, "openpgp").u32(at + 2), + }; }; /** A primary key's fingerprint from its packet body: SHA-1 for version 4, SHA-256 for versions 5 and 6. */ diff --git a/tests/boundary/filesystem/ciChangeScope.test.ts b/tests/boundary/filesystem/ciChangeScope.test.ts index 31a960876c..dc35874567 100644 --- a/tests/boundary/filesystem/ciChangeScope.test.ts +++ b/tests/boundary/filesystem/ciChangeScope.test.ts @@ -581,7 +581,7 @@ it("routes license inventories to docs checks and keeps blame-ignore edits forma for (const staticOnly of [ "scripts/lib/module-layers.baseline.json", "scripts/verify/architecture-guards.mjs", - "scripts/verify/baselines/raw-buffer-read.json", + "scripts/verify/baselines/cleanup-dependency-binding.json", "tsconfig.scripts.json", ]) { expect(await classifyPaths([staticOnly]), staticOnly).toMatchObject({