@tybys/wasm-util 0.10.2 → 0.10.3
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/dist/wasm-util.esm-bundler.js +60 -48
- package/dist/wasm-util.esm.js +60 -48
- package/dist/wasm-util.esm.min.js +1 -1
- package/dist/wasm-util.js +60 -48
- package/dist/wasm-util.min.js +1 -1
- package/lib/cjs/wasi/preview1.js +62 -49
- package/lib/mjs/wasi/preview1.mjs +60 -48
- package/package.json +1 -1
package/dist/wasm-util.esm.js
CHANGED
|
@@ -1201,8 +1201,18 @@ function copyMemory(targets, src) {
|
|
|
1201
1201
|
const _memory = new WeakMap();
|
|
1202
1202
|
const _wasi = new WeakMap();
|
|
1203
1203
|
const _fs = new WeakMap();
|
|
1204
|
-
function
|
|
1205
|
-
|
|
1204
|
+
function ensureMemoryFor(memory, end) {
|
|
1205
|
+
let buffer = memory.buffer;
|
|
1206
|
+
if (end > buffer.byteLength) {
|
|
1207
|
+
memory.grow(0);
|
|
1208
|
+
buffer = memory.buffer;
|
|
1209
|
+
}
|
|
1210
|
+
return buffer;
|
|
1211
|
+
}
|
|
1212
|
+
function getMemory(wasi, end = 0) {
|
|
1213
|
+
const memory = _memory.get(wasi);
|
|
1214
|
+
ensureMemoryFor(memory, end);
|
|
1215
|
+
return memory;
|
|
1206
1216
|
}
|
|
1207
1217
|
function getFs(wasi) {
|
|
1208
1218
|
const fs = _fs.get(wasi);
|
|
@@ -1331,9 +1341,10 @@ class WASI$1 {
|
|
|
1331
1341
|
if (argv === 0 || argv_buf === 0) {
|
|
1332
1342
|
return 28 /* WasiErrno.EINVAL */;
|
|
1333
1343
|
}
|
|
1334
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1335
1344
|
const wasi = _wasi.get(this);
|
|
1336
1345
|
const args = wasi.args;
|
|
1346
|
+
const argsSize = encoder.encode(args.join('\0') + '\0').length;
|
|
1347
|
+
const { HEAPU8, view } = getMemory(this, Math.max(argv + args.length * 4, argv_buf + argsSize));
|
|
1337
1348
|
for (let i = 0; i < args.length; ++i) {
|
|
1338
1349
|
const arg = args[i];
|
|
1339
1350
|
view.setInt32(argv, argv_buf, true);
|
|
@@ -1350,7 +1361,7 @@ class WASI$1 {
|
|
|
1350
1361
|
if (argc === 0 || argv_buf_size === 0) {
|
|
1351
1362
|
return 28 /* WasiErrno.EINVAL */;
|
|
1352
1363
|
}
|
|
1353
|
-
const { view } = getMemory(this);
|
|
1364
|
+
const { view } = getMemory(this, Math.max(argc + 4, argv_buf_size + 4));
|
|
1354
1365
|
const wasi = _wasi.get(this);
|
|
1355
1366
|
const args = wasi.args;
|
|
1356
1367
|
view.setUint32(argc, args.length, true);
|
|
@@ -1363,9 +1374,10 @@ class WASI$1 {
|
|
|
1363
1374
|
if (environ === 0 || environ_buf === 0) {
|
|
1364
1375
|
return 28 /* WasiErrno.EINVAL */;
|
|
1365
1376
|
}
|
|
1366
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1367
1377
|
const wasi = _wasi.get(this);
|
|
1368
1378
|
const env = wasi.env;
|
|
1379
|
+
const envSize = encoder.encode(env.join('\0') + '\0').length;
|
|
1380
|
+
const { HEAPU8, view } = getMemory(this, Math.max(environ + env.length * 4, environ_buf + envSize));
|
|
1369
1381
|
for (let i = 0; i < env.length; ++i) {
|
|
1370
1382
|
const pair = env[i];
|
|
1371
1383
|
view.setInt32(environ, environ_buf, true);
|
|
@@ -1382,7 +1394,7 @@ class WASI$1 {
|
|
|
1382
1394
|
if (len === 0 || buflen === 0) {
|
|
1383
1395
|
return 28 /* WasiErrno.EINVAL */;
|
|
1384
1396
|
}
|
|
1385
|
-
const { view } = getMemory(this);
|
|
1397
|
+
const { view } = getMemory(this, Math.max(len + 4, buflen + 4));
|
|
1386
1398
|
const wasi = _wasi.get(this);
|
|
1387
1399
|
view.setUint32(len, wasi.env.length, true);
|
|
1388
1400
|
view.setUint32(buflen, encoder.encode(wasi.env.join('\0') + '\0').length, true);
|
|
@@ -1393,7 +1405,7 @@ class WASI$1 {
|
|
|
1393
1405
|
if (resolution === 0) {
|
|
1394
1406
|
return 28 /* WasiErrno.EINVAL */;
|
|
1395
1407
|
}
|
|
1396
|
-
const { view } = getMemory(this);
|
|
1408
|
+
const { view } = getMemory(this, resolution + 8);
|
|
1397
1409
|
switch (id) {
|
|
1398
1410
|
case 0 /* WasiClockid.REALTIME */:
|
|
1399
1411
|
view.setBigUint64(resolution, BigInt(1000000), true);
|
|
@@ -1411,7 +1423,7 @@ class WASI$1 {
|
|
|
1411
1423
|
if (time === 0) {
|
|
1412
1424
|
return 28 /* WasiErrno.EINVAL */;
|
|
1413
1425
|
}
|
|
1414
|
-
const { view } = getMemory(this);
|
|
1426
|
+
const { view } = getMemory(this, time + 8);
|
|
1415
1427
|
switch (id) {
|
|
1416
1428
|
case 0 /* WasiClockid.REALTIME */:
|
|
1417
1429
|
view.setBigUint64(time, BigInt(Date.now()) * BigInt(1000000), true);
|
|
@@ -1439,7 +1451,7 @@ class WASI$1 {
|
|
|
1439
1451
|
}
|
|
1440
1452
|
const wasi = _wasi.get(this);
|
|
1441
1453
|
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
1442
|
-
const { view } = getMemory(this);
|
|
1454
|
+
const { view } = getMemory(this, fdstat + 24);
|
|
1443
1455
|
view.setUint16(fdstat, fileDescriptor.type, true);
|
|
1444
1456
|
view.setUint16(fdstat + 2, 0, true);
|
|
1445
1457
|
view.setBigUint64(fdstat + 8, fileDescriptor.rightsBase, true);
|
|
@@ -1480,7 +1492,7 @@ class WASI$1 {
|
|
|
1480
1492
|
}
|
|
1481
1493
|
if (fileDescriptor.preopen !== 1)
|
|
1482
1494
|
return 28 /* WasiErrno.EINVAL */;
|
|
1483
|
-
const { view } = getMemory(this);
|
|
1495
|
+
const { view } = getMemory(this, prestat + 8);
|
|
1484
1496
|
// preopen type is dir(0)
|
|
1485
1497
|
view.setUint32(prestat, 0, true);
|
|
1486
1498
|
view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length, true);
|
|
@@ -1500,7 +1512,7 @@ class WASI$1 {
|
|
|
1500
1512
|
const size = buffer.length;
|
|
1501
1513
|
if (size > path_len)
|
|
1502
1514
|
return 42 /* WasiErrno.ENOBUFS */;
|
|
1503
|
-
const { HEAPU8 } = getMemory(this);
|
|
1515
|
+
const { HEAPU8 } = getMemory(this, path + size);
|
|
1504
1516
|
HEAPU8.set(buffer, path);
|
|
1505
1517
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1506
1518
|
});
|
|
@@ -1514,7 +1526,7 @@ class WASI$1 {
|
|
|
1514
1526
|
const wasi = _wasi.get(this);
|
|
1515
1527
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_SEEK, BigInt(0));
|
|
1516
1528
|
const r = fileDescriptor.seek(offset, whence);
|
|
1517
|
-
const { view } = getMemory(this);
|
|
1529
|
+
const { view } = getMemory(this, newOffset + 8);
|
|
1518
1530
|
view.setBigUint64(newOffset, r, true);
|
|
1519
1531
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1520
1532
|
});
|
|
@@ -1522,7 +1534,7 @@ class WASI$1 {
|
|
|
1522
1534
|
const wasi = _wasi.get(this);
|
|
1523
1535
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_TELL, BigInt(0));
|
|
1524
1536
|
const pos = BigInt(fileDescriptor.pos);
|
|
1525
|
-
const { view } = getMemory(this);
|
|
1537
|
+
const { view } = getMemory(this, Number(offset) + 8);
|
|
1526
1538
|
view.setBigUint64(Number(offset), pos, true);
|
|
1527
1539
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1528
1540
|
});
|
|
@@ -1535,7 +1547,7 @@ class WASI$1 {
|
|
|
1535
1547
|
if (in_ptr === 0 || out_ptr === 0 || nsubscriptions === 0 || nevents === 0) {
|
|
1536
1548
|
return 28 /* WasiErrno.EINVAL */;
|
|
1537
1549
|
}
|
|
1538
|
-
const { view } = getMemory(this);
|
|
1550
|
+
const { view } = getMemory(this, Math.max(in_ptr + nsubscriptions * 48, out_ptr + nsubscriptions * 32, nevents + 4));
|
|
1539
1551
|
view.setUint32(nevents, 0, true);
|
|
1540
1552
|
let i = 0;
|
|
1541
1553
|
let timer_userdata = BigInt(0);
|
|
@@ -1654,7 +1666,7 @@ class WASI$1 {
|
|
|
1654
1666
|
return 28 /* WasiErrno.EINVAL */;
|
|
1655
1667
|
}
|
|
1656
1668
|
buf_len = Number(buf_len);
|
|
1657
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1669
|
+
const { HEAPU8, view } = getMemory(this, buf + buf_len);
|
|
1658
1670
|
if ((typeof SharedArrayBuffer === 'function' && HEAPU8.buffer instanceof SharedArrayBuffer) ||
|
|
1659
1671
|
(Object.prototype.toString.call(HEAPU8.buffer) === '[object SharedArrayBuffer]')) {
|
|
1660
1672
|
for (let i = buf; i < buf + buf_len; ++i) {
|
|
@@ -1676,7 +1688,7 @@ class WASI$1 {
|
|
|
1676
1688
|
return 28 /* WasiErrno.EINVAL */;
|
|
1677
1689
|
}
|
|
1678
1690
|
buf_len = Number(buf_len);
|
|
1679
|
-
const { view } = getMemory(this);
|
|
1691
|
+
const { view } = getMemory(this, buf + buf_len);
|
|
1680
1692
|
for (let i = buf; i < buf + buf_len; ++i) {
|
|
1681
1693
|
view.setUint8(i, Math.floor(Math.random() * 256));
|
|
1682
1694
|
}
|
|
@@ -1769,7 +1781,7 @@ class WASI$1 {
|
|
|
1769
1781
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_GET, BigInt(0));
|
|
1770
1782
|
const fs = getFs(this);
|
|
1771
1783
|
const stat = fs.fstatSync(fileDescriptor.fd, { bigint: true });
|
|
1772
|
-
const { view } = getMemory(this);
|
|
1784
|
+
const { view } = getMemory(this, buf + 64);
|
|
1773
1785
|
toFileStat(view, buf, stat);
|
|
1774
1786
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1775
1787
|
}, async function fd_filestat_get(fd, buf) {
|
|
@@ -1780,7 +1792,7 @@ class WASI$1 {
|
|
|
1780
1792
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_GET, BigInt(0));
|
|
1781
1793
|
const h = fileDescriptor.fd;
|
|
1782
1794
|
const stat = await h.stat({ bigint: true });
|
|
1783
|
-
const { view } = getMemory(this);
|
|
1795
|
+
const { view } = getMemory(this, buf + 64);
|
|
1784
1796
|
toFileStat(view, buf, stat);
|
|
1785
1797
|
return 0 /* WasiErrno.ESUCCESS */;
|
|
1786
1798
|
}, ['i32', 'i32'], ['i32']);
|
|
@@ -1831,7 +1843,7 @@ class WASI$1 {
|
|
|
1831
1843
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1832
1844
|
return 28 /* WasiErrno.EINVAL */;
|
|
1833
1845
|
}
|
|
1834
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1846
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1835
1847
|
const wasi = _wasi.get(this);
|
|
1836
1848
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1837
1849
|
if (!iovslen) {
|
|
@@ -1867,7 +1879,7 @@ class WASI$1 {
|
|
|
1867
1879
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1868
1880
|
return 28 /* WasiErrno.EINVAL */;
|
|
1869
1881
|
}
|
|
1870
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1882
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1871
1883
|
const wasi = _wasi.get(this);
|
|
1872
1884
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
1873
1885
|
if (!iovslen) {
|
|
@@ -1896,7 +1908,7 @@ class WASI$1 {
|
|
|
1896
1908
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1897
1909
|
return 28 /* WasiErrno.EINVAL */;
|
|
1898
1910
|
}
|
|
1899
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1911
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1900
1912
|
const wasi = _wasi.get(this);
|
|
1901
1913
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1902
1914
|
if (!iovslen) {
|
|
@@ -1919,7 +1931,7 @@ class WASI$1 {
|
|
|
1919
1931
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
1920
1932
|
return 28 /* WasiErrno.EINVAL */;
|
|
1921
1933
|
}
|
|
1922
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1934
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1923
1935
|
const wasi = _wasi.get(this);
|
|
1924
1936
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
1925
1937
|
if (!iovslen) {
|
|
@@ -1942,7 +1954,7 @@ class WASI$1 {
|
|
|
1942
1954
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1943
1955
|
return 28 /* WasiErrno.EINVAL */;
|
|
1944
1956
|
}
|
|
1945
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1957
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1946
1958
|
const wasi = _wasi.get(this);
|
|
1947
1959
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1948
1960
|
if (!iovslen) {
|
|
@@ -1989,7 +2001,7 @@ class WASI$1 {
|
|
|
1989
2001
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1990
2002
|
return 28 /* WasiErrno.EINVAL */;
|
|
1991
2003
|
}
|
|
1992
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2004
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1993
2005
|
const wasi = _wasi.get(this);
|
|
1994
2006
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
1995
2007
|
if (!iovslen) {
|
|
@@ -2033,7 +2045,7 @@ class WASI$1 {
|
|
|
2033
2045
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READDIR, BigInt(0));
|
|
2034
2046
|
const fs = getFs(this);
|
|
2035
2047
|
const entries = fs.readdirSync(fileDescriptor.realPath, { withFileTypes: true });
|
|
2036
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2048
|
+
const { HEAPU8, view } = getMemory(this, Math.max(buf + buf_len, bufused + 4));
|
|
2037
2049
|
let bufferUsed = 0;
|
|
2038
2050
|
for (let i = Number(cookie); i < entries.length; i++) {
|
|
2039
2051
|
const nameData = encoder.encode(entries[i].name);
|
|
@@ -2083,7 +2095,7 @@ class WASI$1 {
|
|
|
2083
2095
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READDIR, BigInt(0));
|
|
2084
2096
|
const fs = getFs(this);
|
|
2085
2097
|
const entries = await fs.promises.readdir(fileDescriptor.realPath, { withFileTypes: true });
|
|
2086
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2098
|
+
const { HEAPU8, view } = getMemory(this, Math.max(buf + buf_len, bufused + 4));
|
|
2087
2099
|
let bufferUsed = 0;
|
|
2088
2100
|
for (let i = Number(cookie); i < entries.length; i++) {
|
|
2089
2101
|
const nameData = encoder.encode(entries[i].name);
|
|
@@ -2151,7 +2163,7 @@ class WASI$1 {
|
|
|
2151
2163
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
2152
2164
|
return 28 /* WasiErrno.EINVAL */;
|
|
2153
2165
|
}
|
|
2154
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2166
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
2155
2167
|
const wasi = _wasi.get(this);
|
|
2156
2168
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
2157
2169
|
if (!iovslen) {
|
|
@@ -2181,7 +2193,7 @@ class WASI$1 {
|
|
|
2181
2193
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
2182
2194
|
return 28 /* WasiErrno.EINVAL */;
|
|
2183
2195
|
}
|
|
2184
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2196
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
2185
2197
|
const wasi = _wasi.get(this);
|
|
2186
2198
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
2187
2199
|
if (!iovslen) {
|
|
@@ -2211,7 +2223,7 @@ class WASI$1 {
|
|
|
2211
2223
|
if (path === 0) {
|
|
2212
2224
|
return 28 /* WasiErrno.EINVAL */;
|
|
2213
2225
|
}
|
|
2214
|
-
const { HEAPU8 } = getMemory(this);
|
|
2226
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2215
2227
|
const wasi = _wasi.get(this);
|
|
2216
2228
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
|
|
2217
2229
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2225,7 +2237,7 @@ class WASI$1 {
|
|
|
2225
2237
|
if (path === 0) {
|
|
2226
2238
|
return 28 /* WasiErrno.EINVAL */;
|
|
2227
2239
|
}
|
|
2228
|
-
const { HEAPU8 } = getMemory(this);
|
|
2240
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2229
2241
|
const wasi = _wasi.get(this);
|
|
2230
2242
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
|
|
2231
2243
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2241,7 +2253,7 @@ class WASI$1 {
|
|
|
2241
2253
|
if (path === 0 || filestat === 0) {
|
|
2242
2254
|
return 28 /* WasiErrno.EINVAL */;
|
|
2243
2255
|
}
|
|
2244
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2256
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, filestat + 64));
|
|
2245
2257
|
const wasi = _wasi.get(this);
|
|
2246
2258
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
|
|
2247
2259
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2263,7 +2275,7 @@ class WASI$1 {
|
|
|
2263
2275
|
if (path === 0 || filestat === 0) {
|
|
2264
2276
|
return 28 /* WasiErrno.EINVAL */;
|
|
2265
2277
|
}
|
|
2266
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2278
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, filestat + 64));
|
|
2267
2279
|
const wasi = _wasi.get(this);
|
|
2268
2280
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
|
|
2269
2281
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2284,7 +2296,7 @@ class WASI$1 {
|
|
|
2284
2296
|
path_len = Number(path_len);
|
|
2285
2297
|
if (path === 0)
|
|
2286
2298
|
return 28 /* WasiErrno.EINVAL */;
|
|
2287
|
-
const { HEAPU8 } = getMemory(this);
|
|
2299
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2288
2300
|
const wasi = _wasi.get(this);
|
|
2289
2301
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2290
2302
|
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
@@ -2305,7 +2317,7 @@ class WASI$1 {
|
|
|
2305
2317
|
path_len = Number(path_len);
|
|
2306
2318
|
if (path === 0)
|
|
2307
2319
|
return 28 /* WasiErrno.EINVAL */;
|
|
2308
|
-
const { HEAPU8 } = getMemory(this);
|
|
2320
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2309
2321
|
const wasi = _wasi.get(this);
|
|
2310
2322
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
2311
2323
|
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
@@ -2340,7 +2352,7 @@ class WASI$1 {
|
|
|
2340
2352
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE, BigInt(0));
|
|
2341
2353
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
2342
2354
|
}
|
|
2343
|
-
const { HEAPU8 } = getMemory(this);
|
|
2355
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
2344
2356
|
const fs = getFs(this);
|
|
2345
2357
|
const resolvedOldPath = resolvePathSync(fs, oldWrap, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)), old_flags);
|
|
2346
2358
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
@@ -2364,7 +2376,7 @@ class WASI$1 {
|
|
|
2364
2376
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE, BigInt(0));
|
|
2365
2377
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
2366
2378
|
}
|
|
2367
|
-
const { HEAPU8 } = getMemory(this);
|
|
2379
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
2368
2380
|
const fs = getFs(this);
|
|
2369
2381
|
const resolvedOldPath = await resolvePathAsync(fs, oldWrap, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)), old_flags);
|
|
2370
2382
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
@@ -2430,7 +2442,7 @@ class WASI$1 {
|
|
|
2430
2442
|
const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
|
|
2431
2443
|
const wasi = _wasi.get(this);
|
|
2432
2444
|
const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
|
|
2433
|
-
const memory = getMemory(this);
|
|
2445
|
+
const memory = getMemory(this, Math.max(path + path_len, fd + 4));
|
|
2434
2446
|
const HEAPU8 = memory.HEAPU8;
|
|
2435
2447
|
const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2436
2448
|
const fs = getFs(this);
|
|
@@ -2466,7 +2478,7 @@ class WASI$1 {
|
|
|
2466
2478
|
const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
|
|
2467
2479
|
const wasi = _wasi.get(this);
|
|
2468
2480
|
const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
|
|
2469
|
-
const memory = getMemory(this);
|
|
2481
|
+
const memory = getMemory(this, Math.max(path + path_len, fd + 4));
|
|
2470
2482
|
const HEAPU8 = memory.HEAPU8;
|
|
2471
2483
|
const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
2472
2484
|
const fs = getFs(this);
|
|
@@ -2498,7 +2510,7 @@ class WASI$1 {
|
|
|
2498
2510
|
if (path === 0 || buf === 0 || bufused === 0) {
|
|
2499
2511
|
return 28 /* WasiErrno.EINVAL */;
|
|
2500
2512
|
}
|
|
2501
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2513
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, buf + buf_len, bufused + 4));
|
|
2502
2514
|
const wasi = _wasi.get(this);
|
|
2503
2515
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
|
|
2504
2516
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2522,7 +2534,7 @@ class WASI$1 {
|
|
|
2522
2534
|
if (path === 0 || buf === 0 || bufused === 0) {
|
|
2523
2535
|
return 28 /* WasiErrno.EINVAL */;
|
|
2524
2536
|
}
|
|
2525
|
-
const { HEAPU8, view } = getMemory(this);
|
|
2537
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, buf + buf_len, bufused + 4));
|
|
2526
2538
|
const wasi = _wasi.get(this);
|
|
2527
2539
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
|
|
2528
2540
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2544,7 +2556,7 @@ class WASI$1 {
|
|
|
2544
2556
|
if (path === 0) {
|
|
2545
2557
|
return 28 /* WasiErrno.EINVAL */;
|
|
2546
2558
|
}
|
|
2547
|
-
const { HEAPU8 } = getMemory(this);
|
|
2559
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2548
2560
|
const wasi = _wasi.get(this);
|
|
2549
2561
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
|
|
2550
2562
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2558,7 +2570,7 @@ class WASI$1 {
|
|
|
2558
2570
|
if (path === 0) {
|
|
2559
2571
|
return 28 /* WasiErrno.EINVAL */;
|
|
2560
2572
|
}
|
|
2561
|
-
const { HEAPU8 } = getMemory(this);
|
|
2573
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2562
2574
|
const wasi = _wasi.get(this);
|
|
2563
2575
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
|
|
2564
2576
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2585,7 +2597,7 @@ class WASI$1 {
|
|
|
2585
2597
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE, BigInt(0));
|
|
2586
2598
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
2587
2599
|
}
|
|
2588
|
-
const { HEAPU8 } = getMemory(this);
|
|
2600
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
2589
2601
|
const resolvedOldPath = resolve(oldWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)));
|
|
2590
2602
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
2591
2603
|
const fs = getFs(this);
|
|
@@ -2609,7 +2621,7 @@ class WASI$1 {
|
|
|
2609
2621
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE, BigInt(0));
|
|
2610
2622
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
2611
2623
|
}
|
|
2612
|
-
const { HEAPU8 } = getMemory(this);
|
|
2624
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
2613
2625
|
const resolvedOldPath = resolve(oldWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)));
|
|
2614
2626
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
2615
2627
|
const fs = getFs(this);
|
|
@@ -2624,7 +2636,7 @@ class WASI$1 {
|
|
|
2624
2636
|
if (old_path === 0 || new_path === 0) {
|
|
2625
2637
|
return 28 /* WasiErrno.EINVAL */;
|
|
2626
2638
|
}
|
|
2627
|
-
const { HEAPU8 } = getMemory(this);
|
|
2639
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
2628
2640
|
const wasi = _wasi.get(this);
|
|
2629
2641
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
|
|
2630
2642
|
const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
|
|
@@ -2644,7 +2656,7 @@ class WASI$1 {
|
|
|
2644
2656
|
if (old_path === 0 || new_path === 0) {
|
|
2645
2657
|
return 28 /* WasiErrno.EINVAL */;
|
|
2646
2658
|
}
|
|
2647
|
-
const { HEAPU8 } = getMemory(this);
|
|
2659
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
2648
2660
|
const wasi = _wasi.get(this);
|
|
2649
2661
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
|
|
2650
2662
|
const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
|
|
@@ -2660,7 +2672,7 @@ class WASI$1 {
|
|
|
2660
2672
|
if (path === 0) {
|
|
2661
2673
|
return 28 /* WasiErrno.EINVAL */;
|
|
2662
2674
|
}
|
|
2663
|
-
const { HEAPU8 } = getMemory(this);
|
|
2675
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2664
2676
|
const wasi = _wasi.get(this);
|
|
2665
2677
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
|
|
2666
2678
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -2674,7 +2686,7 @@ class WASI$1 {
|
|
|
2674
2686
|
if (path === 0) {
|
|
2675
2687
|
return 28 /* WasiErrno.EINVAL */;
|
|
2676
2688
|
}
|
|
2677
|
-
const { HEAPU8 } = getMemory(this);
|
|
2689
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
2678
2690
|
const wasi = _wasi.get(this);
|
|
2679
2691
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
|
|
2680
2692
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|