@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
|
@@ -49,8 +49,18 @@ function copyMemory(targets, src) {
|
|
|
49
49
|
const _memory = new WeakMap();
|
|
50
50
|
const _wasi = new WeakMap();
|
|
51
51
|
const _fs = new WeakMap();
|
|
52
|
-
function
|
|
53
|
-
|
|
52
|
+
export function ensureMemoryFor(memory, end) {
|
|
53
|
+
let buffer = memory.buffer;
|
|
54
|
+
if (end > buffer.byteLength) {
|
|
55
|
+
memory.grow(0);
|
|
56
|
+
buffer = memory.buffer;
|
|
57
|
+
}
|
|
58
|
+
return buffer;
|
|
59
|
+
}
|
|
60
|
+
function getMemory(wasi, end = 0) {
|
|
61
|
+
const memory = _memory.get(wasi);
|
|
62
|
+
ensureMemoryFor(memory, end);
|
|
63
|
+
return memory;
|
|
54
64
|
}
|
|
55
65
|
function getFs(wasi) {
|
|
56
66
|
const fs = _fs.get(wasi);
|
|
@@ -179,9 +189,10 @@ export class WASI {
|
|
|
179
189
|
if (argv === 0 || argv_buf === 0) {
|
|
180
190
|
return WasiErrno.EINVAL;
|
|
181
191
|
}
|
|
182
|
-
const { HEAPU8, view } = getMemory(this);
|
|
183
192
|
const wasi = _wasi.get(this);
|
|
184
193
|
const args = wasi.args;
|
|
194
|
+
const argsSize = encoder.encode(args.join('\0') + '\0').length;
|
|
195
|
+
const { HEAPU8, view } = getMemory(this, Math.max(argv + args.length * 4, argv_buf + argsSize));
|
|
185
196
|
for (let i = 0; i < args.length; ++i) {
|
|
186
197
|
const arg = args[i];
|
|
187
198
|
view.setInt32(argv, argv_buf, true);
|
|
@@ -198,7 +209,7 @@ export class WASI {
|
|
|
198
209
|
if (argc === 0 || argv_buf_size === 0) {
|
|
199
210
|
return WasiErrno.EINVAL;
|
|
200
211
|
}
|
|
201
|
-
const { view } = getMemory(this);
|
|
212
|
+
const { view } = getMemory(this, Math.max(argc + 4, argv_buf_size + 4));
|
|
202
213
|
const wasi = _wasi.get(this);
|
|
203
214
|
const args = wasi.args;
|
|
204
215
|
view.setUint32(argc, args.length, true);
|
|
@@ -211,9 +222,10 @@ export class WASI {
|
|
|
211
222
|
if (environ === 0 || environ_buf === 0) {
|
|
212
223
|
return WasiErrno.EINVAL;
|
|
213
224
|
}
|
|
214
|
-
const { HEAPU8, view } = getMemory(this);
|
|
215
225
|
const wasi = _wasi.get(this);
|
|
216
226
|
const env = wasi.env;
|
|
227
|
+
const envSize = encoder.encode(env.join('\0') + '\0').length;
|
|
228
|
+
const { HEAPU8, view } = getMemory(this, Math.max(environ + env.length * 4, environ_buf + envSize));
|
|
217
229
|
for (let i = 0; i < env.length; ++i) {
|
|
218
230
|
const pair = env[i];
|
|
219
231
|
view.setInt32(environ, environ_buf, true);
|
|
@@ -230,7 +242,7 @@ export class WASI {
|
|
|
230
242
|
if (len === 0 || buflen === 0) {
|
|
231
243
|
return WasiErrno.EINVAL;
|
|
232
244
|
}
|
|
233
|
-
const { view } = getMemory(this);
|
|
245
|
+
const { view } = getMemory(this, Math.max(len + 4, buflen + 4));
|
|
234
246
|
const wasi = _wasi.get(this);
|
|
235
247
|
view.setUint32(len, wasi.env.length, true);
|
|
236
248
|
view.setUint32(buflen, encoder.encode(wasi.env.join('\0') + '\0').length, true);
|
|
@@ -241,7 +253,7 @@ export class WASI {
|
|
|
241
253
|
if (resolution === 0) {
|
|
242
254
|
return WasiErrno.EINVAL;
|
|
243
255
|
}
|
|
244
|
-
const { view } = getMemory(this);
|
|
256
|
+
const { view } = getMemory(this, resolution + 8);
|
|
245
257
|
switch (id) {
|
|
246
258
|
case WasiClockid.REALTIME:
|
|
247
259
|
view.setBigUint64(resolution, BigInt(1000000), true);
|
|
@@ -259,7 +271,7 @@ export class WASI {
|
|
|
259
271
|
if (time === 0) {
|
|
260
272
|
return WasiErrno.EINVAL;
|
|
261
273
|
}
|
|
262
|
-
const { view } = getMemory(this);
|
|
274
|
+
const { view } = getMemory(this, time + 8);
|
|
263
275
|
switch (id) {
|
|
264
276
|
case WasiClockid.REALTIME:
|
|
265
277
|
view.setBigUint64(time, BigInt(Date.now()) * BigInt(1000000), true);
|
|
@@ -287,7 +299,7 @@ export class WASI {
|
|
|
287
299
|
}
|
|
288
300
|
const wasi = _wasi.get(this);
|
|
289
301
|
const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
|
|
290
|
-
const { view } = getMemory(this);
|
|
302
|
+
const { view } = getMemory(this, fdstat + 24);
|
|
291
303
|
view.setUint16(fdstat, fileDescriptor.type, true);
|
|
292
304
|
view.setUint16(fdstat + 2, 0, true);
|
|
293
305
|
view.setBigUint64(fdstat + 8, fileDescriptor.rightsBase, true);
|
|
@@ -328,7 +340,7 @@ export class WASI {
|
|
|
328
340
|
}
|
|
329
341
|
if (fileDescriptor.preopen !== 1)
|
|
330
342
|
return WasiErrno.EINVAL;
|
|
331
|
-
const { view } = getMemory(this);
|
|
343
|
+
const { view } = getMemory(this, prestat + 8);
|
|
332
344
|
// preopen type is dir(0)
|
|
333
345
|
view.setUint32(prestat, 0, true);
|
|
334
346
|
view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length, true);
|
|
@@ -348,7 +360,7 @@ export class WASI {
|
|
|
348
360
|
const size = buffer.length;
|
|
349
361
|
if (size > path_len)
|
|
350
362
|
return WasiErrno.ENOBUFS;
|
|
351
|
-
const { HEAPU8 } = getMemory(this);
|
|
363
|
+
const { HEAPU8 } = getMemory(this, path + size);
|
|
352
364
|
HEAPU8.set(buffer, path);
|
|
353
365
|
return WasiErrno.ESUCCESS;
|
|
354
366
|
});
|
|
@@ -362,7 +374,7 @@ export class WASI {
|
|
|
362
374
|
const wasi = _wasi.get(this);
|
|
363
375
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_SEEK, BigInt(0));
|
|
364
376
|
const r = fileDescriptor.seek(offset, whence);
|
|
365
|
-
const { view } = getMemory(this);
|
|
377
|
+
const { view } = getMemory(this, newOffset + 8);
|
|
366
378
|
view.setBigUint64(newOffset, r, true);
|
|
367
379
|
return WasiErrno.ESUCCESS;
|
|
368
380
|
});
|
|
@@ -370,7 +382,7 @@ export class WASI {
|
|
|
370
382
|
const wasi = _wasi.get(this);
|
|
371
383
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_TELL, BigInt(0));
|
|
372
384
|
const pos = BigInt(fileDescriptor.pos);
|
|
373
|
-
const { view } = getMemory(this);
|
|
385
|
+
const { view } = getMemory(this, Number(offset) + 8);
|
|
374
386
|
view.setBigUint64(Number(offset), pos, true);
|
|
375
387
|
return WasiErrno.ESUCCESS;
|
|
376
388
|
});
|
|
@@ -383,7 +395,7 @@ export class WASI {
|
|
|
383
395
|
if (in_ptr === 0 || out_ptr === 0 || nsubscriptions === 0 || nevents === 0) {
|
|
384
396
|
return WasiErrno.EINVAL;
|
|
385
397
|
}
|
|
386
|
-
const { view } = getMemory(this);
|
|
398
|
+
const { view } = getMemory(this, Math.max(in_ptr + nsubscriptions * 48, out_ptr + nsubscriptions * 32, nevents + 4));
|
|
387
399
|
view.setUint32(nevents, 0, true);
|
|
388
400
|
let i = 0;
|
|
389
401
|
let timer_userdata = BigInt(0);
|
|
@@ -502,7 +514,7 @@ export class WASI {
|
|
|
502
514
|
return WasiErrno.EINVAL;
|
|
503
515
|
}
|
|
504
516
|
buf_len = Number(buf_len);
|
|
505
|
-
const { HEAPU8, view } = getMemory(this);
|
|
517
|
+
const { HEAPU8, view } = getMemory(this, buf + buf_len);
|
|
506
518
|
if ((typeof SharedArrayBuffer === 'function' && HEAPU8.buffer instanceof SharedArrayBuffer) ||
|
|
507
519
|
(Object.prototype.toString.call(HEAPU8.buffer) === '[object SharedArrayBuffer]')) {
|
|
508
520
|
for (let i = buf; i < buf + buf_len; ++i) {
|
|
@@ -524,7 +536,7 @@ export class WASI {
|
|
|
524
536
|
return WasiErrno.EINVAL;
|
|
525
537
|
}
|
|
526
538
|
buf_len = Number(buf_len);
|
|
527
|
-
const { view } = getMemory(this);
|
|
539
|
+
const { view } = getMemory(this, buf + buf_len);
|
|
528
540
|
for (let i = buf; i < buf + buf_len; ++i) {
|
|
529
541
|
view.setUint8(i, Math.floor(Math.random() * 256));
|
|
530
542
|
}
|
|
@@ -617,7 +629,7 @@ export class WASI {
|
|
|
617
629
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_GET, BigInt(0));
|
|
618
630
|
const fs = getFs(this);
|
|
619
631
|
const stat = fs.fstatSync(fileDescriptor.fd, { bigint: true });
|
|
620
|
-
const { view } = getMemory(this);
|
|
632
|
+
const { view } = getMemory(this, buf + 64);
|
|
621
633
|
toFileStat(view, buf, stat);
|
|
622
634
|
return WasiErrno.ESUCCESS;
|
|
623
635
|
}, async function fd_filestat_get(fd, buf) {
|
|
@@ -628,7 +640,7 @@ export class WASI {
|
|
|
628
640
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_FILESTAT_GET, BigInt(0));
|
|
629
641
|
const h = fileDescriptor.fd;
|
|
630
642
|
const stat = await h.stat({ bigint: true });
|
|
631
|
-
const { view } = getMemory(this);
|
|
643
|
+
const { view } = getMemory(this, buf + 64);
|
|
632
644
|
toFileStat(view, buf, stat);
|
|
633
645
|
return WasiErrno.ESUCCESS;
|
|
634
646
|
}, ['i32', 'i32'], ['i32']);
|
|
@@ -679,7 +691,7 @@ export class WASI {
|
|
|
679
691
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
680
692
|
return WasiErrno.EINVAL;
|
|
681
693
|
}
|
|
682
|
-
const { HEAPU8, view } = getMemory(this);
|
|
694
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
683
695
|
const wasi = _wasi.get(this);
|
|
684
696
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
685
697
|
if (!iovslen) {
|
|
@@ -715,7 +727,7 @@ export class WASI {
|
|
|
715
727
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
716
728
|
return WasiErrno.EINVAL;
|
|
717
729
|
}
|
|
718
|
-
const { HEAPU8, view } = getMemory(this);
|
|
730
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
719
731
|
const wasi = _wasi.get(this);
|
|
720
732
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ | WasiRights.FD_SEEK, BigInt(0));
|
|
721
733
|
if (!iovslen) {
|
|
@@ -744,7 +756,7 @@ export class WASI {
|
|
|
744
756
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
745
757
|
return WasiErrno.EINVAL;
|
|
746
758
|
}
|
|
747
|
-
const { HEAPU8, view } = getMemory(this);
|
|
759
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
748
760
|
const wasi = _wasi.get(this);
|
|
749
761
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
750
762
|
if (!iovslen) {
|
|
@@ -767,7 +779,7 @@ export class WASI {
|
|
|
767
779
|
if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
|
|
768
780
|
return WasiErrno.EINVAL;
|
|
769
781
|
}
|
|
770
|
-
const { HEAPU8, view } = getMemory(this);
|
|
782
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
771
783
|
const wasi = _wasi.get(this);
|
|
772
784
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE | WasiRights.FD_SEEK, BigInt(0));
|
|
773
785
|
if (!iovslen) {
|
|
@@ -790,7 +802,7 @@ export class WASI {
|
|
|
790
802
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
791
803
|
return WasiErrno.EINVAL;
|
|
792
804
|
}
|
|
793
|
-
const { HEAPU8, view } = getMemory(this);
|
|
805
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
794
806
|
const wasi = _wasi.get(this);
|
|
795
807
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
796
808
|
if (!iovslen) {
|
|
@@ -837,7 +849,7 @@ export class WASI {
|
|
|
837
849
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
838
850
|
return WasiErrno.EINVAL;
|
|
839
851
|
}
|
|
840
|
-
const { HEAPU8, view } = getMemory(this);
|
|
852
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
841
853
|
const wasi = _wasi.get(this);
|
|
842
854
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READ, BigInt(0));
|
|
843
855
|
if (!iovslen) {
|
|
@@ -881,7 +893,7 @@ export class WASI {
|
|
|
881
893
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READDIR, BigInt(0));
|
|
882
894
|
const fs = getFs(this);
|
|
883
895
|
const entries = fs.readdirSync(fileDescriptor.realPath, { withFileTypes: true });
|
|
884
|
-
const { HEAPU8, view } = getMemory(this);
|
|
896
|
+
const { HEAPU8, view } = getMemory(this, Math.max(buf + buf_len, bufused + 4));
|
|
885
897
|
let bufferUsed = 0;
|
|
886
898
|
for (let i = Number(cookie); i < entries.length; i++) {
|
|
887
899
|
const nameData = encoder.encode(entries[i].name);
|
|
@@ -931,7 +943,7 @@ export class WASI {
|
|
|
931
943
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_READDIR, BigInt(0));
|
|
932
944
|
const fs = getFs(this);
|
|
933
945
|
const entries = await fs.promises.readdir(fileDescriptor.realPath, { withFileTypes: true });
|
|
934
|
-
const { HEAPU8, view } = getMemory(this);
|
|
946
|
+
const { HEAPU8, view } = getMemory(this, Math.max(buf + buf_len, bufused + 4));
|
|
935
947
|
let bufferUsed = 0;
|
|
936
948
|
for (let i = Number(cookie); i < entries.length; i++) {
|
|
937
949
|
const nameData = encoder.encode(entries[i].name);
|
|
@@ -999,7 +1011,7 @@ export class WASI {
|
|
|
999
1011
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1000
1012
|
return WasiErrno.EINVAL;
|
|
1001
1013
|
}
|
|
1002
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1014
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1003
1015
|
const wasi = _wasi.get(this);
|
|
1004
1016
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
1005
1017
|
if (!iovslen) {
|
|
@@ -1029,7 +1041,7 @@ export class WASI {
|
|
|
1029
1041
|
if ((iovs === 0 && iovslen) || size === 0) {
|
|
1030
1042
|
return WasiErrno.EINVAL;
|
|
1031
1043
|
}
|
|
1032
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1044
|
+
const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
|
|
1033
1045
|
const wasi = _wasi.get(this);
|
|
1034
1046
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.FD_WRITE, BigInt(0));
|
|
1035
1047
|
if (!iovslen) {
|
|
@@ -1059,7 +1071,7 @@ export class WASI {
|
|
|
1059
1071
|
if (path === 0) {
|
|
1060
1072
|
return WasiErrno.EINVAL;
|
|
1061
1073
|
}
|
|
1062
|
-
const { HEAPU8 } = getMemory(this);
|
|
1074
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1063
1075
|
const wasi = _wasi.get(this);
|
|
1064
1076
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
|
|
1065
1077
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1073,7 +1085,7 @@ export class WASI {
|
|
|
1073
1085
|
if (path === 0) {
|
|
1074
1086
|
return WasiErrno.EINVAL;
|
|
1075
1087
|
}
|
|
1076
|
-
const { HEAPU8 } = getMemory(this);
|
|
1088
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1077
1089
|
const wasi = _wasi.get(this);
|
|
1078
1090
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
|
|
1079
1091
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1089,7 +1101,7 @@ export class WASI {
|
|
|
1089
1101
|
if (path === 0 || filestat === 0) {
|
|
1090
1102
|
return WasiErrno.EINVAL;
|
|
1091
1103
|
}
|
|
1092
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1104
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, filestat + 64));
|
|
1093
1105
|
const wasi = _wasi.get(this);
|
|
1094
1106
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
|
|
1095
1107
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1111,7 +1123,7 @@ export class WASI {
|
|
|
1111
1123
|
if (path === 0 || filestat === 0) {
|
|
1112
1124
|
return WasiErrno.EINVAL;
|
|
1113
1125
|
}
|
|
1114
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1126
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, filestat + 64));
|
|
1115
1127
|
const wasi = _wasi.get(this);
|
|
1116
1128
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_GET, BigInt(0));
|
|
1117
1129
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1132,7 +1144,7 @@ export class WASI {
|
|
|
1132
1144
|
path_len = Number(path_len);
|
|
1133
1145
|
if (path === 0)
|
|
1134
1146
|
return WasiErrno.EINVAL;
|
|
1135
|
-
const { HEAPU8 } = getMemory(this);
|
|
1147
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1136
1148
|
const wasi = _wasi.get(this);
|
|
1137
1149
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
1138
1150
|
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
@@ -1153,7 +1165,7 @@ export class WASI {
|
|
|
1153
1165
|
path_len = Number(path_len);
|
|
1154
1166
|
if (path === 0)
|
|
1155
1167
|
return WasiErrno.EINVAL;
|
|
1156
|
-
const { HEAPU8 } = getMemory(this);
|
|
1168
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1157
1169
|
const wasi = _wasi.get(this);
|
|
1158
1170
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
|
|
1159
1171
|
if (validateFstFlagsOrReturn(fst_flags)) {
|
|
@@ -1188,7 +1200,7 @@ export class WASI {
|
|
|
1188
1200
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE, BigInt(0));
|
|
1189
1201
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
1190
1202
|
}
|
|
1191
|
-
const { HEAPU8 } = getMemory(this);
|
|
1203
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
1192
1204
|
const fs = getFs(this);
|
|
1193
1205
|
const resolvedOldPath = resolvePathSync(fs, oldWrap, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)), old_flags);
|
|
1194
1206
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
@@ -1212,7 +1224,7 @@ export class WASI {
|
|
|
1212
1224
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_LINK_SOURCE, BigInt(0));
|
|
1213
1225
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_LINK_TARGET, BigInt(0));
|
|
1214
1226
|
}
|
|
1215
|
-
const { HEAPU8 } = getMemory(this);
|
|
1227
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
1216
1228
|
const fs = getFs(this);
|
|
1217
1229
|
const resolvedOldPath = await resolvePathAsync(fs, oldWrap, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)), old_flags);
|
|
1218
1230
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
@@ -1278,7 +1290,7 @@ export class WASI {
|
|
|
1278
1290
|
const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
|
|
1279
1291
|
const wasi = _wasi.get(this);
|
|
1280
1292
|
const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
|
|
1281
|
-
const memory = getMemory(this);
|
|
1293
|
+
const memory = getMemory(this, Math.max(path + path_len, fd + 4));
|
|
1282
1294
|
const HEAPU8 = memory.HEAPU8;
|
|
1283
1295
|
const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
1284
1296
|
const fs = getFs(this);
|
|
@@ -1314,7 +1326,7 @@ export class WASI {
|
|
|
1314
1326
|
const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
|
|
1315
1327
|
const wasi = _wasi.get(this);
|
|
1316
1328
|
const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
|
|
1317
|
-
const memory = getMemory(this);
|
|
1329
|
+
const memory = getMemory(this, Math.max(path + path_len, fd + 4));
|
|
1318
1330
|
const HEAPU8 = memory.HEAPU8;
|
|
1319
1331
|
const pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
1320
1332
|
const fs = getFs(this);
|
|
@@ -1346,7 +1358,7 @@ export class WASI {
|
|
|
1346
1358
|
if (path === 0 || buf === 0 || bufused === 0) {
|
|
1347
1359
|
return WasiErrno.EINVAL;
|
|
1348
1360
|
}
|
|
1349
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1361
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, buf + buf_len, bufused + 4));
|
|
1350
1362
|
const wasi = _wasi.get(this);
|
|
1351
1363
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
|
|
1352
1364
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1370,7 +1382,7 @@ export class WASI {
|
|
|
1370
1382
|
if (path === 0 || buf === 0 || bufused === 0) {
|
|
1371
1383
|
return WasiErrno.EINVAL;
|
|
1372
1384
|
}
|
|
1373
|
-
const { HEAPU8, view } = getMemory(this);
|
|
1385
|
+
const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, buf + buf_len, bufused + 4));
|
|
1374
1386
|
const wasi = _wasi.get(this);
|
|
1375
1387
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_READLINK, BigInt(0));
|
|
1376
1388
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1392,7 +1404,7 @@ export class WASI {
|
|
|
1392
1404
|
if (path === 0) {
|
|
1393
1405
|
return WasiErrno.EINVAL;
|
|
1394
1406
|
}
|
|
1395
|
-
const { HEAPU8 } = getMemory(this);
|
|
1407
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1396
1408
|
const wasi = _wasi.get(this);
|
|
1397
1409
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
|
|
1398
1410
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1406,7 +1418,7 @@ export class WASI {
|
|
|
1406
1418
|
if (path === 0) {
|
|
1407
1419
|
return WasiErrno.EINVAL;
|
|
1408
1420
|
}
|
|
1409
|
-
const { HEAPU8 } = getMemory(this);
|
|
1421
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1410
1422
|
const wasi = _wasi.get(this);
|
|
1411
1423
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
|
|
1412
1424
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1433,7 +1445,7 @@ export class WASI {
|
|
|
1433
1445
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE, BigInt(0));
|
|
1434
1446
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
1435
1447
|
}
|
|
1436
|
-
const { HEAPU8 } = getMemory(this);
|
|
1448
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
1437
1449
|
const resolvedOldPath = resolve(oldWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)));
|
|
1438
1450
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
1439
1451
|
const fs = getFs(this);
|
|
@@ -1457,7 +1469,7 @@ export class WASI {
|
|
|
1457
1469
|
oldWrap = wasi.fds.get(old_fd, WasiRights.PATH_RENAME_SOURCE, BigInt(0));
|
|
1458
1470
|
newWrap = wasi.fds.get(new_fd, WasiRights.PATH_RENAME_TARGET, BigInt(0));
|
|
1459
1471
|
}
|
|
1460
|
-
const { HEAPU8 } = getMemory(this);
|
|
1472
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
1461
1473
|
const resolvedOldPath = resolve(oldWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len)));
|
|
1462
1474
|
const resolvedNewPath = resolve(newWrap.realPath, decoder.decode(unsharedSlice(HEAPU8, new_path, new_path + new_path_len)));
|
|
1463
1475
|
const fs = getFs(this);
|
|
@@ -1472,7 +1484,7 @@ export class WASI {
|
|
|
1472
1484
|
if (old_path === 0 || new_path === 0) {
|
|
1473
1485
|
return WasiErrno.EINVAL;
|
|
1474
1486
|
}
|
|
1475
|
-
const { HEAPU8 } = getMemory(this);
|
|
1487
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
1476
1488
|
const wasi = _wasi.get(this);
|
|
1477
1489
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
|
|
1478
1490
|
const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
|
|
@@ -1492,7 +1504,7 @@ export class WASI {
|
|
|
1492
1504
|
if (old_path === 0 || new_path === 0) {
|
|
1493
1505
|
return WasiErrno.EINVAL;
|
|
1494
1506
|
}
|
|
1495
|
-
const { HEAPU8 } = getMemory(this);
|
|
1507
|
+
const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
|
|
1496
1508
|
const wasi = _wasi.get(this);
|
|
1497
1509
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_SYMLINK, BigInt(0));
|
|
1498
1510
|
const oldPath = decoder.decode(unsharedSlice(HEAPU8, old_path, old_path + old_path_len));
|
|
@@ -1508,7 +1520,7 @@ export class WASI {
|
|
|
1508
1520
|
if (path === 0) {
|
|
1509
1521
|
return WasiErrno.EINVAL;
|
|
1510
1522
|
}
|
|
1511
|
-
const { HEAPU8 } = getMemory(this);
|
|
1523
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1512
1524
|
const wasi = _wasi.get(this);
|
|
1513
1525
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
|
|
1514
1526
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|
|
@@ -1522,7 +1534,7 @@ export class WASI {
|
|
|
1522
1534
|
if (path === 0) {
|
|
1523
1535
|
return WasiErrno.EINVAL;
|
|
1524
1536
|
}
|
|
1525
|
-
const { HEAPU8 } = getMemory(this);
|
|
1537
|
+
const { HEAPU8 } = getMemory(this, path + path_len);
|
|
1526
1538
|
const wasi = _wasi.get(this);
|
|
1527
1539
|
const fileDescriptor = wasi.fds.get(fd, WasiRights.PATH_UNLINK_FILE, BigInt(0));
|
|
1528
1540
|
let pathString = decoder.decode(unsharedSlice(HEAPU8, path, path + path_len));
|