Open source Loom alternative. Beautiful, shareable screen recordings.
Rust appcapcossloommacnextjsnextjs15open-sourceossreactrecordrustscreen-capturescreen-recorderscreenshotsolidjstauritauri-apptypescriptvite
fix: validate nv12 frame metadata
Richie McIlroy02a6aa942575
diff --git a/apps/desktop/src/utils/frame-worker.ts b/apps/desktop/src/utils/frame-worker.tsindex 3e3cd042d..89b773006 100644--- a/apps/desktop/src/utils/frame-worker.ts+++ b/apps/desktop/src/utils/frame-worker.ts@@ -236,10 +236,10 @@ function parseFrameMetadata(bytes: Uint8Array): FrameMetadata | null {const frameNumber = meta.getUint32(12, true);const targetTimeNs = meta.getBigUint64(16, true);- if (!width || !height) return null;+ if (!width || !height || !yStride) return null;const ySize = yStride * height;- const uvSize = yStride * (height / 2);+ const uvSize = yStride * Math.floor(height / 2);const totalSize = ySize + uvSize;if (bytes.byteLength - 28 < totalSize) {diff --git a/apps/desktop/src/utils/socket.ts b/apps/desktop/src/utils/socket.tsindex 11448ad13..0b1915129 100644--- a/apps/desktop/src/utils/socket.ts+++ b/apps/desktop/src/utils/socket.ts@@ -50,10 +50,26 @@ function readNv12Metadata(buffer: ArrayBuffer): Nv12Metadata | null {const metadataOffset = buffer.byteLength - NV12_METADATA_SIZE;const meta = new DataView(buffer, metadataOffset, NV12_METADATA_SIZE);+ const yStride = meta.getUint32(0, true);+ const height = meta.getUint32(4, true);+ const width = meta.getUint32(8, true);++ const ySize = yStride * height;+ const uvSize = yStride * Math.floor(height / 2);+ const totalSize = ySize + uvSize;+ if (+ yStride === 0 ||+ height === 0 ||+ width === 0 ||+ buffer.byteLength - NV12_METADATA_SIZE < totalSize+ ) {+ return null;+ }+return {- yStride: meta.getUint32(0, true),- height: meta.getUint32(4, true),- width: meta.getUint32(8, true),+ yStride,+ height,+ width,fullRange: magic === NV12_FULL_MAGIC,};}