Skip to content

Commit 64e9df6

Browse files
committed
fix(cactus): mirror tightened filename length cap in browser variant
Apply the same `MAX_FILENAME_LEN = 251` cap as Cactus_Runtime.ts so a filename that validates in the browser also validates on Node — the Node atomic-write path appends `.tmp` (4 chars) and would otherwise exceed the 255-byte per-component limit on common filesystems.
1 parent 37e1544 commit 64e9df6

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

‎providers/cactus/src/ai/common/Cactus_Runtime.browser.ts‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export interface CactusModelCacheInfo {
4545

4646
const MODEL_ID_RE = /^[A-Za-z0-9_-]{1,64}$/;
4747
const FILENAME_RE = /^[A-Za-z0-9_.-]+$/;
48+
// Match the Node variant's limit so an asset that validates here also
49+
// validates there. The Node atomic-write path writes to `${filename}.tmp`
50+
// before renaming, so the source filename must leave room for that suffix
51+
// (most filesystems cap a path component at 255 bytes).
52+
const MAX_FILENAME_LEN = 251;
4853

4954
function assertSafeModelId(model_id: string): void {
5055
if (typeof model_id !== "string" || !MODEL_ID_RE.test(model_id)) {
@@ -59,14 +64,14 @@ function assertSafeFilename(filename: string): void {
5964
if (
6065
typeof filename !== "string" ||
6166
filename.length === 0 ||
62-
filename.length > 255 ||
67+
filename.length > MAX_FILENAME_LEN ||
6368
filename === "." ||
6469
filename === ".." ||
6570
!FILENAME_RE.test(filename)
6671
) {
6772
throw new Error(
6873
`Invalid Cactus asset filename ${JSON.stringify(filename)}: ` +
69-
`must match ${FILENAME_RE} (no path separators, no '..').`
74+
`must match ${FILENAME_RE} (no path separators, no '..'), 1-${MAX_FILENAME_LEN} chars.`
7075
);
7176
}
7277
}

0 commit comments

Comments
 (0)