Skip to content

Commit 8db66b4

Browse files
committed
fix(release): reject unsafe Sparkle build floors
1 parent 2b92fbc commit 8db66b4

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

‎scripts/sparkle-build.ts‎

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ export function sparkleBuildFloorsFromShortVersion(
5454
return null;
5555
}
5656

57-
const year = Number.parseInt(match[1], 10);
58-
const month = Number.parseInt(match[2], 10);
59-
const patch = Number.parseInt(match[3], 10);
57+
const year = Number(match[1]);
58+
const month = Number(match[2]);
59+
const patch = Number(match[3]);
6060
if (
61-
!Number.isInteger(year) ||
62-
!Number.isInteger(month) ||
63-
!Number.isInteger(patch) ||
61+
!Number.isSafeInteger(year) ||
62+
!Number.isSafeInteger(month) ||
63+
!Number.isSafeInteger(patch) ||
6464
month < 1 ||
6565
month > 12 ||
6666
patch < 1
@@ -87,24 +87,39 @@ export function sparkleBuildFloorsFromShortVersion(
8787
// Keep old appcast entries byte-stable, then switch to YYMMPPPPLL so
8888
// monthly patches beyond 31 stay monotonic without pretending to be dates.
8989
const releaseKey = monthlyPatchReleaseKey(year, month, patch);
90+
const laneFloor = releaseKey + lane;
91+
if (!isSafeSparkleFloor(releaseKey) || !isSafeSparkleFloor(laneFloor)) {
92+
return null;
93+
}
9094
return {
9195
releaseKey,
9296
legacyFloor: releaseKey,
93-
laneFloor: releaseKey + lane,
97+
laneFloor,
9498
lane,
9599
};
96100
}
97101

98102
const releaseKey = legacyDateReleaseKey(year, month, patch);
99103
const legacyFloor = Number(`${releaseKey}0`);
100104
const laneFloor = Number(`${releaseKey}${String(lane).padStart(2, "0")}`);
105+
if (
106+
!isSafeSparkleFloor(releaseKey) ||
107+
!isSafeSparkleFloor(legacyFloor) ||
108+
!isSafeSparkleFloor(laneFloor)
109+
) {
110+
return null;
111+
}
101112
return { releaseKey, legacyFloor, laneFloor, lane };
102113
}
103114

104115
export function canonicalSparkleBuildFromVersion(shortVersion: string): number | null {
105116
return sparkleBuildFloorsFromShortVersion(shortVersion)?.laneFloor ?? null;
106117
}
107118

119+
function isSafeSparkleFloor(value: number): boolean {
120+
return Number.isSafeInteger(value) && value > 0;
121+
}
122+
108123
function runCli(args: string[]): number {
109124
const [command, version] = args;
110125
if (command !== "canonical-build" || !version) {

‎test/appcast.test.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ describe("canonicalSparkleBuildFromVersion", () => {
2626
expect(canonicalSparkleBuildFromVersion("2026.6.5-beta.0")).toBeNull();
2727
expect(canonicalSparkleBuildFromVersion("2026.6.5-beta.9007199254740993")).toBeNull();
2828
});
29+
30+
it("rejects unsafe numeric release parts and build floors", () => {
31+
expect(canonicalSparkleBuildFromVersion("2026.6.9007199254740993")).toBeNull();
32+
expect(canonicalSparkleBuildFromVersion("2026.6.90071992547410")).toBeNull();
33+
});
2934
});
3035

3136
function parseItems(appcast: string): AppcastItem[] {

0 commit comments

Comments
 (0)