gm-plugkit 2.0.1636 → 2.0.1637

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gm-plugkit",
3
- "version": "2.0.1636",
3
+ "version": "2.0.1637",
4
4
  "description": "Bootstrap and daemon-spawn tool for gm plugkit binary. Downloads the correct platform binary, verifies SHA256, and starts the spool watcher daemon. Includes plugkit-wasm-wrapper for WASM-based spool watching.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -1457,8 +1457,9 @@ function createWasiShim(instanceRef) {
1457
1457
  const dv = new DataView(buf);
1458
1458
  const chunks = [];
1459
1459
  let total = 0;
1460
+ const iovsBase = iovs_ptr >>> 0; // >>>0: high-bit iovs pointer is negative in JS -> getUint32 would throw
1460
1461
  for (let i = 0; i < iovs_len; i++) {
1461
- const base = iovs_ptr + i * 8;
1462
+ const base = iovsBase + i * 8;
1462
1463
  const ptr = dv.getUint32(base, true);
1463
1464
  const len = dv.getUint32(base + 4, true);
1464
1465
  if (len > 0 && ptr + len <= buf.byteLength) {
@@ -1480,7 +1481,7 @@ function createWasiShim(instanceRef) {
1480
1481
  },
1481
1482
  random_get: (buf_ptr, buf_len) => {
1482
1483
  try {
1483
- crypto.randomFillSync(new Uint8Array(getMemory(), buf_ptr, buf_len));
1484
+ crypto.randomFillSync(new Uint8Array(getMemory(), buf_ptr >>> 0, buf_len >>> 0)); // >>>0: high-bit ptr is negative in JS
1484
1485
  return 0;
1485
1486
  } catch (e) {
1486
1487
  return 28;
@@ -1489,7 +1490,7 @@ function createWasiShim(instanceRef) {
1489
1490
  clock_time_get: (clock_id, precision, time_ptr) => {
1490
1491
  try {
1491
1492
  const ns = BigInt(Date.now()) * 1000000n;
1492
- new DataView(getMemory()).setBigUint64(time_ptr, ns, true);
1493
+ new DataView(getMemory()).setBigUint64(time_ptr >>> 0, ns, true); // >>>0: high-bit ptr is negative in JS
1493
1494
  return 0;
1494
1495
  } catch (e) {
1495
1496
  return 28;
@@ -1548,8 +1549,15 @@ function decodeWasmResult(instance, result, where) {
1548
1549
 
1549
1550
  function writeWasmInput(instance, bytes, where) {
1550
1551
  if (bytes.length === 0) return 0;
1551
- const ptr = instance.exports.plugkit_alloc(bytes.length);
1552
+ // COERCE the alloc pointer to UNSIGNED 32-bit: a wasm i32 return with the high bit set (a pointer
1553
+ // > 0x7fffffff, which occurs once the linear memory grows past ~2GB in a long session) arrives in JS
1554
+ // as a NEGATIVE number, and new Uint8Array(buffer, negativePtr, len) throws the raw V8 "Start offset
1555
+ // <neg> is outside the bounds of the buffer" -- the deterministic long-session corruption that blocked
1556
+ // dispatches. >>>0 reinterprets the i32 as the true unsigned offset. Guard the range too so a genuinely
1557
+ // bad (ptr,len) raises the clean wasm-memory-read-out-of-bounds error instead of a raw typed-array throw.
1558
+ const ptr = instance.exports.plugkit_alloc(bytes.length) >>> 0;
1552
1559
  if (ptr === 0) throw new Error(`wasm-alloc-failed at ${where}: plugkit_alloc returned 0 (wasm OOM)`);
1560
+ guardWasmRange(instance.exports.memory.buffer, ptr, bytes.length, `${where}:writeWasmInput`);
1553
1561
  new Uint8Array(instance.exports.memory.buffer, ptr, bytes.length).set(bytes); // fresh buffer post-alloc
1554
1562
  return ptr;
1555
1563
  }
@@ -1571,8 +1579,11 @@ function readWasmStr(instance, ptr, len) {
1571
1579
 
1572
1580
  function writeWasmBytes(instance, bytes) {
1573
1581
  if (bytes.length === 0) return 0n;
1574
- const ptr = instance.exports.plugkit_alloc(bytes.length);
1582
+ // >>>0: same signed-pointer fix as writeWasmInput -- a high-bit alloc pointer is negative in JS and
1583
+ // throws "Start offset <neg> is outside the bounds" on the Uint8Array write below.
1584
+ const ptr = instance.exports.plugkit_alloc(bytes.length) >>> 0;
1575
1585
  if (ptr === 0) return 0n;
1586
+ guardWasmRange(instance.exports.memory.buffer, ptr, bytes.length, 'writeWasmBytes');
1576
1587
  new Uint8Array(instance.exports.memory.buffer, ptr, bytes.length).set(bytes);
1577
1588
  return (BigInt(ptr) & 0xffffffffn) | (BigInt(bytes.length) << 32n);
1578
1589
  }
@@ -2256,7 +2267,7 @@ function makeHostFunctions(instanceRef) {
2256
2267
  host_random_fill: (ptr, len) => {
2257
2268
  try {
2258
2269
  const buf = instanceRef.value.exports.memory.buffer;
2259
- crypto.randomFillSync(new Uint8Array(buf, ptr, len));
2270
+ crypto.randomFillSync(new Uint8Array(buf, ptr >>> 0, len >>> 0)); // >>>0: high-bit ptr is negative in JS
2260
2271
  return 1;
2261
2272
  } catch (_) {
2262
2273
  return 0;