Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

fix(media-server): cap a single timing metadata read at 256 MB

Richie McIlroy2afdb50fd3b1
diff --git a/apps/media-server/src/lib/recording-timing.ts b/apps/media-server/src/lib/recording-timing.ts
index ac1934f17..cec679497 100644
--- a/apps/media-server/src/lib/recording-timing.ts
+++ b/apps/media-server/src/lib/recording-timing.ts
@@ -14,6 +14,8 @@ import {
const MAX_METADATA_BYTES = 64 * 1024 * 1024;
const MAX_LONG_RECORDING_METADATA_BYTES = 1024 * 1024 * 1024;
+// A long budget covers many reads; one allocation for a single header box stays bounded.
+const MAX_SINGLE_METADATA_READ_BYTES = 256 * 1024 * 1024;
// Sample tables grow with a recording's length; reads stream through a fixed cache.
const METADATA_BYTES_PER_FILE_BYTE = 1 / 64;
const MAX_RANGE_BYTES = 1024 * 1024;
@@ -524,6 +526,12 @@ export async function readRecordingVideoTiming(
false,
);
}
+ if (end - start > MAX_SINGLE_METADATA_READ_BYTES) {
+ throw new RecordingTimingError(
+ `Recording timing metadata exceeds its read budget (one ${megabytes(end - start)} MB read)`,
+ false,
+ );
+ }
reserve(end - start);
const result = new Uint8Array(end - start);
for (let position = start; position < end; ) {