Skip to content

Commit 3a54428

Browse files
committed
fix(release): carry Windows checksum record support to main
1 parent b1ae178 commit 3a54428

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

‎desktop/scripts/verify-release-assets.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export function releaseMatrixTargets(workflowText: string): {
9595

9696
/**
9797
* Every recorded checksum against the bytes on disk, in exactly the producers'
98-
* format (64 hex, two spaces, bare name, one trailing newline). The recorded name
98+
* format (64 hex, a space, text/binary marker, bare name, newline). The recorded name
9999
* must equal the checksum file's own name minus the suffix: a foo.sha256 naming
100100
* bar would leave foo's bytes unchecked while bar's are checked twice.
101101
*/
@@ -104,7 +104,7 @@ export function verifyChecksums(dir: string): number {
104104
if (checksumFiles.length === 0) throw new Error(`No .sha256 files found in ${dir}`);
105105
for (const checksumFile of checksumFiles) {
106106
const content = readFileSync(join(dir, checksumFile), "utf8");
107-
const match = /^([0-9a-f]{64}) (\S+)\n$/.exec(content);
107+
const match = /^([0-9a-f]{64}) [ *](\S+)\r?\n$/.exec(content);
108108
if (!match) throw new Error(`Malformed checksum record in ${checksumFile}: ${JSON.stringify(content)}`);
109109
const digest = match[1]!;
110110
const recorded = match[2]!;

‎tests/ci-workflows/release-desktop-scripts.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,35 @@ describe("release asset verification", () => {
618618
}
619619
});
620620

621+
test("verifies Windows binary checksum records without weakening payload binding", () => {
622+
const dir = temporaryDirectory();
623+
const name = "ocx-1.0.0-bun-windows-x64.zip";
624+
const asset = join(dir, name);
625+
const checksum = `${asset}.sha256`;
626+
// Standard sha256sum binary marker observed in release run 35728908862.
627+
const digest = "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
628+
try {
629+
writeFileSync(asset, "");
630+
for (const newline of ["\n", "\r\n"]) {
631+
writeFileSync(checksum, `${digest} *${name}${newline}`);
632+
expect(verifyChecksums(dir)).toBe(1);
633+
}
634+
writeFileSync(checksum, `${digest} *different.zip\n`);
635+
expect(() => verifyChecksums(dir)).toThrow(/must record its own payload/);
636+
for (const record of [`${digest} ?${name}\n`, `${digest}*${name}\n`, `${digest} *${name}\nextra\n`]) {
637+
writeFileSync(checksum, record);
638+
expect(() => verifyChecksums(dir)).toThrow(/Malformed checksum record/);
639+
}
640+
writeFileSync(checksum, `${digest} *${name}\n`);
641+
writeFileSync(asset, "changed");
642+
expect(() => verifyChecksums(dir)).toThrow(/Checksum mismatch/);
643+
rmSync(asset);
644+
expect(() => verifyChecksums(dir)).toThrow(/which is missing/);
645+
} finally {
646+
rmSync(dir, { recursive: true, force: true });
647+
}
648+
});
649+
621650
test("rejects a tampered payload and a missing payload", () => {
622651
const dir = temporaryDirectory();
623652
try {

0 commit comments

Comments
 (0)