@componentor/fs 3.0.14 → 3.0.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1950,11 +1950,18 @@ var SIGNAL = {
1950
1950
  var encoder3 = new TextEncoder();
1951
1951
  var decoder2 = new TextDecoder();
1952
1952
  function decodeRequest(buf) {
1953
+ if (buf.byteLength < 16) {
1954
+ throw new Error(`Request buffer too small: ${buf.byteLength} < 16 bytes (possible SAB race)`);
1955
+ }
1953
1956
  const view = new DataView(buf);
1954
1957
  const op = view.getUint32(0, true);
1955
1958
  const flags = view.getUint32(4, true);
1956
1959
  const pathLen = view.getUint32(8, true);
1957
1960
  const dataLen = view.getUint32(12, true);
1961
+ const expectedMin = 16 + pathLen + dataLen;
1962
+ if (buf.byteLength < expectedMin) {
1963
+ throw new Error(`Request buffer truncated: ${buf.byteLength} < ${expectedMin} bytes (op=${op}, pathLen=${pathLen}, dataLen=${dataLen})`);
1964
+ }
1958
1965
  const bytes = new Uint8Array(buf);
1959
1966
  const path = decoder2.decode(bytes.subarray(16, 16 + pathLen));
1960
1967
  const data = dataLen > 0 ? bytes.subarray(16 + pathLen, 16 + pathLen + dataLen) : null;
@@ -2115,7 +2122,13 @@ var OP_NAMES = {
2115
2122
  };
2116
2123
  function handleRequest(reqTabId, buffer) {
2117
2124
  const t0 = debug ? performance.now() : 0;
2118
- const { op, flags, path, data } = decodeRequest(buffer);
2125
+ let op, flags, path, data;
2126
+ try {
2127
+ ({ op, flags, path, data } = decodeRequest(buffer));
2128
+ } catch (err) {
2129
+ console.error(`[sync-relay] decodeRequest failed (bufLen=${buffer.byteLength}): ${err.message}`);
2130
+ return { status: -1 };
2131
+ }
2119
2132
  const t1 = debug ? performance.now() : 0;
2120
2133
  let result;
2121
2134
  let syncOp;
@@ -2356,7 +2369,13 @@ function handleRequest(reqTabId, buffer) {
2356
2369
  }
2357
2370
  async function handleRequestOPFS(reqTabId, buffer) {
2358
2371
  const oe = opfsEngine;
2359
- const { op, flags, path, data } = decodeRequest(buffer);
2372
+ let op, flags, path, data;
2373
+ try {
2374
+ ({ op, flags, path, data } = decodeRequest(buffer));
2375
+ } catch (err) {
2376
+ console.error(`[sync-relay] decodeRequest failed in OPFS handler (bufLen=${buffer.byteLength}): ${err.message}`);
2377
+ return { status: -1 };
2378
+ }
2360
2379
  let result;
2361
2380
  let syncPath;
2362
2381
  let syncNewPath;
@@ -2531,6 +2550,10 @@ function readPayload(targetSab, targetCtrl) {
2531
2550
  const maxChunk = targetSab.byteLength - HEADER_SIZE;
2532
2551
  const chunkLen = Atomics.load(targetCtrl, 3);
2533
2552
  const totalLen = Number(Atomics.load(totalLenView, 0));
2553
+ if (chunkLen <= 0 || chunkLen > maxChunk) {
2554
+ console.error(`[sync-relay] readPayload: invalid chunkLen=${chunkLen} (maxChunk=${maxChunk}, totalLen=${totalLen})`);
2555
+ return new Uint8Array(0);
2556
+ }
2534
2557
  if (totalLen <= maxChunk) {
2535
2558
  return new Uint8Array(targetSab, HEADER_SIZE, chunkLen).slice();
2536
2559
  }