Skip to content

Commit 35f9e16

Browse files
committed
🤖 fix: stat local audio files before reading import payloads
--- _Generated with `mux` • Model: `openai:gpt-5.3-codex` • Thinking: `xhigh` • Cost: `3.03`_ <!-- mux-attribution: model=openai:gpt-5.3-codex thinking=xhigh costs=53.03 -->
1 parent fd9b713 commit 35f9e16

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎src/node/services/eventSoundAssetService.test.ts‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterEach, beforeEach, describe, expect, it } from "bun:test";
1+
import { afterEach, beforeEach, describe, expect, it, spyOn } from "bun:test";
22
import * as fsPromises from "node:fs/promises";
33
import * as os from "node:os";
44
import * as path from "node:path";
@@ -69,6 +69,23 @@ describe("EventSoundAssetService", () => {
6969
);
7070
});
7171

72+
it("checks file size metadata before reading oversized local imports", async () => {
73+
const sourcePath = path.join(tempMuxHome, "oversize-by-metadata.wav");
74+
await fsPromises.writeFile(sourcePath, "");
75+
await fsPromises.truncate(sourcePath, MAX_AUDIO_FILE_SIZE_BYTES + 1);
76+
77+
const readFileSpy = spyOn(fsPromises, "readFile");
78+
try {
79+
await expectRejects(
80+
service.importFromLocalPath(sourcePath),
81+
"Audio file exceeds maximum allowed size"
82+
);
83+
expect(readFileSpy).not.toHaveBeenCalled();
84+
} finally {
85+
readFileSpy.mockRestore();
86+
}
87+
});
88+
7289
it("rejects local imports with unsupported extensions", async () => {
7390
const sourcePath = path.join(tempMuxHome, "not-audio.txt");
7491
await fsPromises.writeFile(sourcePath, "not audio");

‎src/node/services/eventSoundAssetService.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ export class EventSoundAssetService {
321321
throw new Error("Unsupported audio file extension");
322322
}
323323

324+
const stat = await fsPromises.stat(localPath);
325+
this.validateSize(stat.size);
326+
324327
const bytes = await fsPromises.readFile(localPath);
328+
// Re-validate after reading in case the file grew between stat + read.
325329
this.validateSize(bytes.byteLength);
326330

327331
return this.storeAsset({

0 commit comments

Comments
 (0)