@tybys/wasm-util 0.10.2 → 0.10.4

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WASI = void 0;
3
+ exports.WASI = exports.ensureMemoryFor = void 0;
4
4
  const webassembly_1 = require("../webassembly");
5
5
  const path_1 = require("./path");
6
6
  // Linux fcntl flag bits ↔ Windows libuv flag bits. `pathOpen()` builds
@@ -52,8 +52,19 @@ function copyMemory(targets, src) {
52
52
  const _memory = new WeakMap();
53
53
  const _wasi = new WeakMap();
54
54
  const _fs = new WeakMap();
55
- function getMemory(wasi) {
56
- return _memory.get(wasi);
55
+ function ensureMemoryFor(memory, end) {
56
+ let buffer = memory.buffer;
57
+ if (end > buffer.byteLength) {
58
+ memory.grow(0);
59
+ buffer = memory.buffer;
60
+ }
61
+ return buffer;
62
+ }
63
+ exports.ensureMemoryFor = ensureMemoryFor;
64
+ function getMemory(wasi, end = 0) {
65
+ const memory = _memory.get(wasi);
66
+ ensureMemoryFor(memory, end);
67
+ return memory;
57
68
  }
58
69
  function getFs(wasi) {
59
70
  const fs = _fs.get(wasi);
@@ -182,9 +193,10 @@ class WASI {
182
193
  if (argv === 0 || argv_buf === 0) {
183
194
  return types_1.WasiErrno.EINVAL;
184
195
  }
185
- const { HEAPU8, view } = getMemory(this);
186
196
  const wasi = _wasi.get(this);
187
197
  const args = wasi.args;
198
+ const argsSize = encoder.encode(args.join('\0') + '\0').length;
199
+ const { HEAPU8, view } = getMemory(this, Math.max(argv + args.length * 4, argv_buf + argsSize));
188
200
  for (let i = 0; i < args.length; ++i) {
189
201
  const arg = args[i];
190
202
  view.setInt32(argv, argv_buf, true);
@@ -201,7 +213,7 @@ class WASI {
201
213
  if (argc === 0 || argv_buf_size === 0) {
202
214
  return types_1.WasiErrno.EINVAL;
203
215
  }
204
- const { view } = getMemory(this);
216
+ const { view } = getMemory(this, Math.max(argc + 4, argv_buf_size + 4));
205
217
  const wasi = _wasi.get(this);
206
218
  const args = wasi.args;
207
219
  view.setUint32(argc, args.length, true);
@@ -214,9 +226,10 @@ class WASI {
214
226
  if (environ === 0 || environ_buf === 0) {
215
227
  return types_1.WasiErrno.EINVAL;
216
228
  }
217
- const { HEAPU8, view } = getMemory(this);
218
229
  const wasi = _wasi.get(this);
219
230
  const env = wasi.env;
231
+ const envSize = encoder.encode(env.join('\0') + '\0').length;
232
+ const { HEAPU8, view } = getMemory(this, Math.max(environ + env.length * 4, environ_buf + envSize));
220
233
  for (let i = 0; i < env.length; ++i) {
221
234
  const pair = env[i];
222
235
  view.setInt32(environ, environ_buf, true);
@@ -233,7 +246,7 @@ class WASI {
233
246
  if (len === 0 || buflen === 0) {
234
247
  return types_1.WasiErrno.EINVAL;
235
248
  }
236
- const { view } = getMemory(this);
249
+ const { view } = getMemory(this, Math.max(len + 4, buflen + 4));
237
250
  const wasi = _wasi.get(this);
238
251
  view.setUint32(len, wasi.env.length, true);
239
252
  view.setUint32(buflen, encoder.encode(wasi.env.join('\0') + '\0').length, true);
@@ -244,7 +257,7 @@ class WASI {
244
257
  if (resolution === 0) {
245
258
  return types_1.WasiErrno.EINVAL;
246
259
  }
247
- const { view } = getMemory(this);
260
+ const { view } = getMemory(this, resolution + 8);
248
261
  switch (id) {
249
262
  case types_1.WasiClockid.REALTIME:
250
263
  view.setBigUint64(resolution, BigInt(1000000), true);
@@ -262,7 +275,7 @@ class WASI {
262
275
  if (time === 0) {
263
276
  return types_1.WasiErrno.EINVAL;
264
277
  }
265
- const { view } = getMemory(this);
278
+ const { view } = getMemory(this, time + 8);
266
279
  switch (id) {
267
280
  case types_1.WasiClockid.REALTIME:
268
281
  view.setBigUint64(time, BigInt(Date.now()) * BigInt(1000000), true);
@@ -290,7 +303,7 @@ class WASI {
290
303
  }
291
304
  const wasi = _wasi.get(this);
292
305
  const fileDescriptor = wasi.fds.get(fd, BigInt(0), BigInt(0));
293
- const { view } = getMemory(this);
306
+ const { view } = getMemory(this, fdstat + 24);
294
307
  view.setUint16(fdstat, fileDescriptor.type, true);
295
308
  view.setUint16(fdstat + 2, 0, true);
296
309
  view.setBigUint64(fdstat + 8, fileDescriptor.rightsBase, true);
@@ -331,7 +344,7 @@ class WASI {
331
344
  }
332
345
  if (fileDescriptor.preopen !== 1)
333
346
  return types_1.WasiErrno.EINVAL;
334
- const { view } = getMemory(this);
347
+ const { view } = getMemory(this, prestat + 8);
335
348
  // preopen type is dir(0)
336
349
  view.setUint32(prestat, 0, true);
337
350
  view.setUint32(prestat + 4, encoder.encode(fileDescriptor.path).length, true);
@@ -351,7 +364,7 @@ class WASI {
351
364
  const size = buffer.length;
352
365
  if (size > path_len)
353
366
  return types_1.WasiErrno.ENOBUFS;
354
- const { HEAPU8 } = getMemory(this);
367
+ const { HEAPU8 } = getMemory(this, path + size);
355
368
  HEAPU8.set(buffer, path);
356
369
  return types_1.WasiErrno.ESUCCESS;
357
370
  });
@@ -365,7 +378,7 @@ class WASI {
365
378
  const wasi = _wasi.get(this);
366
379
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_SEEK, BigInt(0));
367
380
  const r = fileDescriptor.seek(offset, whence);
368
- const { view } = getMemory(this);
381
+ const { view } = getMemory(this, newOffset + 8);
369
382
  view.setBigUint64(newOffset, r, true);
370
383
  return types_1.WasiErrno.ESUCCESS;
371
384
  });
@@ -373,7 +386,7 @@ class WASI {
373
386
  const wasi = _wasi.get(this);
374
387
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_TELL, BigInt(0));
375
388
  const pos = BigInt(fileDescriptor.pos);
376
- const { view } = getMemory(this);
389
+ const { view } = getMemory(this, Number(offset) + 8);
377
390
  view.setBigUint64(Number(offset), pos, true);
378
391
  return types_1.WasiErrno.ESUCCESS;
379
392
  });
@@ -386,7 +399,7 @@ class WASI {
386
399
  if (in_ptr === 0 || out_ptr === 0 || nsubscriptions === 0 || nevents === 0) {
387
400
  return types_1.WasiErrno.EINVAL;
388
401
  }
389
- const { view } = getMemory(this);
402
+ const { view } = getMemory(this, Math.max(in_ptr + nsubscriptions * 48, out_ptr + nsubscriptions * 32, nevents + 4));
390
403
  view.setUint32(nevents, 0, true);
391
404
  let i = 0;
392
405
  let timer_userdata = BigInt(0);
@@ -505,7 +518,7 @@ class WASI {
505
518
  return types_1.WasiErrno.EINVAL;
506
519
  }
507
520
  buf_len = Number(buf_len);
508
- const { HEAPU8, view } = getMemory(this);
521
+ const { HEAPU8, view } = getMemory(this, buf + buf_len);
509
522
  if ((typeof SharedArrayBuffer === 'function' && HEAPU8.buffer instanceof SharedArrayBuffer) ||
510
523
  (Object.prototype.toString.call(HEAPU8.buffer) === '[object SharedArrayBuffer]')) {
511
524
  for (let i = buf; i < buf + buf_len; ++i) {
@@ -527,7 +540,7 @@ class WASI {
527
540
  return types_1.WasiErrno.EINVAL;
528
541
  }
529
542
  buf_len = Number(buf_len);
530
- const { view } = getMemory(this);
543
+ const { view } = getMemory(this, buf + buf_len);
531
544
  for (let i = buf; i < buf + buf_len; ++i) {
532
545
  view.setUint8(i, Math.floor(Math.random() * 256));
533
546
  }
@@ -620,7 +633,7 @@ class WASI {
620
633
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_FILESTAT_GET, BigInt(0));
621
634
  const fs = getFs(this);
622
635
  const stat = fs.fstatSync(fileDescriptor.fd, { bigint: true });
623
- const { view } = getMemory(this);
636
+ const { view } = getMemory(this, buf + 64);
624
637
  (0, fd_1.toFileStat)(view, buf, stat);
625
638
  return types_1.WasiErrno.ESUCCESS;
626
639
  }, async function fd_filestat_get(fd, buf) {
@@ -631,7 +644,7 @@ class WASI {
631
644
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_FILESTAT_GET, BigInt(0));
632
645
  const h = fileDescriptor.fd;
633
646
  const stat = await h.stat({ bigint: true });
634
- const { view } = getMemory(this);
647
+ const { view } = getMemory(this, buf + 64);
635
648
  (0, fd_1.toFileStat)(view, buf, stat);
636
649
  return types_1.WasiErrno.ESUCCESS;
637
650
  }, ['i32', 'i32'], ['i32']);
@@ -682,7 +695,7 @@ class WASI {
682
695
  if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
683
696
  return types_1.WasiErrno.EINVAL;
684
697
  }
685
- const { HEAPU8, view } = getMemory(this);
698
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
686
699
  const wasi = _wasi.get(this);
687
700
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_READ | types_1.WasiRights.FD_SEEK, BigInt(0));
688
701
  if (!iovslen) {
@@ -718,7 +731,7 @@ class WASI {
718
731
  if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
719
732
  return types_1.WasiErrno.EINVAL;
720
733
  }
721
- const { HEAPU8, view } = getMemory(this);
734
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
722
735
  const wasi = _wasi.get(this);
723
736
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_READ | types_1.WasiRights.FD_SEEK, BigInt(0));
724
737
  if (!iovslen) {
@@ -747,7 +760,7 @@ class WASI {
747
760
  if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
748
761
  return types_1.WasiErrno.EINVAL;
749
762
  }
750
- const { HEAPU8, view } = getMemory(this);
763
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
751
764
  const wasi = _wasi.get(this);
752
765
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_WRITE | types_1.WasiRights.FD_SEEK, BigInt(0));
753
766
  if (!iovslen) {
@@ -770,7 +783,7 @@ class WASI {
770
783
  if ((iovs === 0 && iovslen) || size === 0 || offset > INT64_MAX) {
771
784
  return types_1.WasiErrno.EINVAL;
772
785
  }
773
- const { HEAPU8, view } = getMemory(this);
786
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
774
787
  const wasi = _wasi.get(this);
775
788
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_WRITE | types_1.WasiRights.FD_SEEK, BigInt(0));
776
789
  if (!iovslen) {
@@ -793,7 +806,7 @@ class WASI {
793
806
  if ((iovs === 0 && iovslen) || size === 0) {
794
807
  return types_1.WasiErrno.EINVAL;
795
808
  }
796
- const { HEAPU8, view } = getMemory(this);
809
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
797
810
  const wasi = _wasi.get(this);
798
811
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_READ, BigInt(0));
799
812
  if (!iovslen) {
@@ -840,7 +853,7 @@ class WASI {
840
853
  if ((iovs === 0 && iovslen) || size === 0) {
841
854
  return types_1.WasiErrno.EINVAL;
842
855
  }
843
- const { HEAPU8, view } = getMemory(this);
856
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
844
857
  const wasi = _wasi.get(this);
845
858
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_READ, BigInt(0));
846
859
  if (!iovslen) {
@@ -884,7 +897,7 @@ class WASI {
884
897
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_READDIR, BigInt(0));
885
898
  const fs = getFs(this);
886
899
  const entries = fs.readdirSync(fileDescriptor.realPath, { withFileTypes: true });
887
- const { HEAPU8, view } = getMemory(this);
900
+ const { HEAPU8, view } = getMemory(this, Math.max(buf + buf_len, bufused + 4));
888
901
  let bufferUsed = 0;
889
902
  for (let i = Number(cookie); i < entries.length; i++) {
890
903
  const nameData = encoder.encode(entries[i].name);
@@ -934,7 +947,7 @@ class WASI {
934
947
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_READDIR, BigInt(0));
935
948
  const fs = getFs(this);
936
949
  const entries = await fs.promises.readdir(fileDescriptor.realPath, { withFileTypes: true });
937
- const { HEAPU8, view } = getMemory(this);
950
+ const { HEAPU8, view } = getMemory(this, Math.max(buf + buf_len, bufused + 4));
938
951
  let bufferUsed = 0;
939
952
  for (let i = Number(cookie); i < entries.length; i++) {
940
953
  const nameData = encoder.encode(entries[i].name);
@@ -1002,7 +1015,7 @@ class WASI {
1002
1015
  if ((iovs === 0 && iovslen) || size === 0) {
1003
1016
  return types_1.WasiErrno.EINVAL;
1004
1017
  }
1005
- const { HEAPU8, view } = getMemory(this);
1018
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
1006
1019
  const wasi = _wasi.get(this);
1007
1020
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_WRITE, BigInt(0));
1008
1021
  if (!iovslen) {
@@ -1032,7 +1045,7 @@ class WASI {
1032
1045
  if ((iovs === 0 && iovslen) || size === 0) {
1033
1046
  return types_1.WasiErrno.EINVAL;
1034
1047
  }
1035
- const { HEAPU8, view } = getMemory(this);
1048
+ const { HEAPU8, view } = getMemory(this, Math.max(iovs + Number(iovslen) * 8, size + 4));
1036
1049
  const wasi = _wasi.get(this);
1037
1050
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.FD_WRITE, BigInt(0));
1038
1051
  if (!iovslen) {
@@ -1062,7 +1075,7 @@ class WASI {
1062
1075
  if (path === 0) {
1063
1076
  return types_1.WasiErrno.EINVAL;
1064
1077
  }
1065
- const { HEAPU8 } = getMemory(this);
1078
+ const { HEAPU8 } = getMemory(this, path + path_len);
1066
1079
  const wasi = _wasi.get(this);
1067
1080
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
1068
1081
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1076,7 +1089,7 @@ class WASI {
1076
1089
  if (path === 0) {
1077
1090
  return types_1.WasiErrno.EINVAL;
1078
1091
  }
1079
- const { HEAPU8 } = getMemory(this);
1092
+ const { HEAPU8 } = getMemory(this, path + path_len);
1080
1093
  const wasi = _wasi.get(this);
1081
1094
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_CREATE_DIRECTORY, BigInt(0));
1082
1095
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1092,7 +1105,7 @@ class WASI {
1092
1105
  if (path === 0 || filestat === 0) {
1093
1106
  return types_1.WasiErrno.EINVAL;
1094
1107
  }
1095
- const { HEAPU8, view } = getMemory(this);
1108
+ const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, filestat + 64));
1096
1109
  const wasi = _wasi.get(this);
1097
1110
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_FILESTAT_GET, BigInt(0));
1098
1111
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1114,7 +1127,7 @@ class WASI {
1114
1127
  if (path === 0 || filestat === 0) {
1115
1128
  return types_1.WasiErrno.EINVAL;
1116
1129
  }
1117
- const { HEAPU8, view } = getMemory(this);
1130
+ const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, filestat + 64));
1118
1131
  const wasi = _wasi.get(this);
1119
1132
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_FILESTAT_GET, BigInt(0));
1120
1133
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1135,7 +1148,7 @@ class WASI {
1135
1148
  path_len = Number(path_len);
1136
1149
  if (path === 0)
1137
1150
  return types_1.WasiErrno.EINVAL;
1138
- const { HEAPU8 } = getMemory(this);
1151
+ const { HEAPU8 } = getMemory(this, path + path_len);
1139
1152
  const wasi = _wasi.get(this);
1140
1153
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
1141
1154
  if (validateFstFlagsOrReturn(fst_flags)) {
@@ -1156,7 +1169,7 @@ class WASI {
1156
1169
  path_len = Number(path_len);
1157
1170
  if (path === 0)
1158
1171
  return types_1.WasiErrno.EINVAL;
1159
- const { HEAPU8 } = getMemory(this);
1172
+ const { HEAPU8 } = getMemory(this, path + path_len);
1160
1173
  const wasi = _wasi.get(this);
1161
1174
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_FILESTAT_SET_TIMES, BigInt(0));
1162
1175
  if (validateFstFlagsOrReturn(fst_flags)) {
@@ -1191,7 +1204,7 @@ class WASI {
1191
1204
  oldWrap = wasi.fds.get(old_fd, types_1.WasiRights.PATH_LINK_SOURCE, BigInt(0));
1192
1205
  newWrap = wasi.fds.get(new_fd, types_1.WasiRights.PATH_LINK_TARGET, BigInt(0));
1193
1206
  }
1194
- const { HEAPU8 } = getMemory(this);
1207
+ const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
1195
1208
  const fs = getFs(this);
1196
1209
  const resolvedOldPath = resolvePathSync(fs, oldWrap, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, old_path, old_path + old_path_len)), old_flags);
1197
1210
  const resolvedNewPath = (0, path_1.resolve)(newWrap.realPath, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, new_path, new_path + new_path_len)));
@@ -1215,7 +1228,7 @@ class WASI {
1215
1228
  oldWrap = wasi.fds.get(old_fd, types_1.WasiRights.PATH_LINK_SOURCE, BigInt(0));
1216
1229
  newWrap = wasi.fds.get(new_fd, types_1.WasiRights.PATH_LINK_TARGET, BigInt(0));
1217
1230
  }
1218
- const { HEAPU8 } = getMemory(this);
1231
+ const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
1219
1232
  const fs = getFs(this);
1220
1233
  const resolvedOldPath = await resolvePathAsync(fs, oldWrap, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, old_path, old_path + old_path_len)), old_flags);
1221
1234
  const resolvedNewPath = (0, path_1.resolve)(newWrap.realPath, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, new_path, new_path + new_path_len)));
@@ -1281,7 +1294,7 @@ class WASI {
1281
1294
  const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
1282
1295
  const wasi = _wasi.get(this);
1283
1296
  const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
1284
- const memory = getMemory(this);
1297
+ const memory = getMemory(this, Math.max(path + path_len, fd + 4));
1285
1298
  const HEAPU8 = memory.HEAPU8;
1286
1299
  const pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
1287
1300
  const fs = getFs(this);
@@ -1317,7 +1330,7 @@ class WASI {
1317
1330
  const { flags: flagsRes, needed_base: neededBase, needed_inheriting: neededInheriting } = pathOpen(o_flags, fs_rights_base, fs_rights_inheriting, fs_flags);
1318
1331
  const wasi = _wasi.get(this);
1319
1332
  const fileDescriptor = wasi.fds.get(dirfd, neededBase, neededInheriting);
1320
- const memory = getMemory(this);
1333
+ const memory = getMemory(this, Math.max(path + path_len, fd + 4));
1321
1334
  const HEAPU8 = memory.HEAPU8;
1322
1335
  const pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
1323
1336
  const fs = getFs(this);
@@ -1349,7 +1362,7 @@ class WASI {
1349
1362
  if (path === 0 || buf === 0 || bufused === 0) {
1350
1363
  return types_1.WasiErrno.EINVAL;
1351
1364
  }
1352
- const { HEAPU8, view } = getMemory(this);
1365
+ const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, buf + buf_len, bufused + 4));
1353
1366
  const wasi = _wasi.get(this);
1354
1367
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_READLINK, BigInt(0));
1355
1368
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1373,7 +1386,7 @@ class WASI {
1373
1386
  if (path === 0 || buf === 0 || bufused === 0) {
1374
1387
  return types_1.WasiErrno.EINVAL;
1375
1388
  }
1376
- const { HEAPU8, view } = getMemory(this);
1389
+ const { HEAPU8, view } = getMemory(this, Math.max(path + path_len, buf + buf_len, bufused + 4));
1377
1390
  const wasi = _wasi.get(this);
1378
1391
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_READLINK, BigInt(0));
1379
1392
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1395,7 +1408,7 @@ class WASI {
1395
1408
  if (path === 0) {
1396
1409
  return types_1.WasiErrno.EINVAL;
1397
1410
  }
1398
- const { HEAPU8 } = getMemory(this);
1411
+ const { HEAPU8 } = getMemory(this, path + path_len);
1399
1412
  const wasi = _wasi.get(this);
1400
1413
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
1401
1414
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1409,7 +1422,7 @@ class WASI {
1409
1422
  if (path === 0) {
1410
1423
  return types_1.WasiErrno.EINVAL;
1411
1424
  }
1412
- const { HEAPU8 } = getMemory(this);
1425
+ const { HEAPU8 } = getMemory(this, path + path_len);
1413
1426
  const wasi = _wasi.get(this);
1414
1427
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_REMOVE_DIRECTORY, BigInt(0));
1415
1428
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1436,7 +1449,7 @@ class WASI {
1436
1449
  oldWrap = wasi.fds.get(old_fd, types_1.WasiRights.PATH_RENAME_SOURCE, BigInt(0));
1437
1450
  newWrap = wasi.fds.get(new_fd, types_1.WasiRights.PATH_RENAME_TARGET, BigInt(0));
1438
1451
  }
1439
- const { HEAPU8 } = getMemory(this);
1452
+ const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
1440
1453
  const resolvedOldPath = (0, path_1.resolve)(oldWrap.realPath, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, old_path, old_path + old_path_len)));
1441
1454
  const resolvedNewPath = (0, path_1.resolve)(newWrap.realPath, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, new_path, new_path + new_path_len)));
1442
1455
  const fs = getFs(this);
@@ -1460,7 +1473,7 @@ class WASI {
1460
1473
  oldWrap = wasi.fds.get(old_fd, types_1.WasiRights.PATH_RENAME_SOURCE, BigInt(0));
1461
1474
  newWrap = wasi.fds.get(new_fd, types_1.WasiRights.PATH_RENAME_TARGET, BigInt(0));
1462
1475
  }
1463
- const { HEAPU8 } = getMemory(this);
1476
+ const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
1464
1477
  const resolvedOldPath = (0, path_1.resolve)(oldWrap.realPath, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, old_path, old_path + old_path_len)));
1465
1478
  const resolvedNewPath = (0, path_1.resolve)(newWrap.realPath, decoder.decode((0, util_1.unsharedSlice)(HEAPU8, new_path, new_path + new_path_len)));
1466
1479
  const fs = getFs(this);
@@ -1475,7 +1488,7 @@ class WASI {
1475
1488
  if (old_path === 0 || new_path === 0) {
1476
1489
  return types_1.WasiErrno.EINVAL;
1477
1490
  }
1478
- const { HEAPU8 } = getMemory(this);
1491
+ const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
1479
1492
  const wasi = _wasi.get(this);
1480
1493
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_SYMLINK, BigInt(0));
1481
1494
  const oldPath = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, old_path, old_path + old_path_len));
@@ -1495,7 +1508,7 @@ class WASI {
1495
1508
  if (old_path === 0 || new_path === 0) {
1496
1509
  return types_1.WasiErrno.EINVAL;
1497
1510
  }
1498
- const { HEAPU8 } = getMemory(this);
1511
+ const { HEAPU8 } = getMemory(this, Math.max(old_path + old_path_len, new_path + new_path_len));
1499
1512
  const wasi = _wasi.get(this);
1500
1513
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_SYMLINK, BigInt(0));
1501
1514
  const oldPath = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, old_path, old_path + old_path_len));
@@ -1511,7 +1524,7 @@ class WASI {
1511
1524
  if (path === 0) {
1512
1525
  return types_1.WasiErrno.EINVAL;
1513
1526
  }
1514
- const { HEAPU8 } = getMemory(this);
1527
+ const { HEAPU8 } = getMemory(this, path + path_len);
1515
1528
  const wasi = _wasi.get(this);
1516
1529
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_UNLINK_FILE, BigInt(0));
1517
1530
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));
@@ -1525,7 +1538,7 @@ class WASI {
1525
1538
  if (path === 0) {
1526
1539
  return types_1.WasiErrno.EINVAL;
1527
1540
  }
1528
- const { HEAPU8 } = getMemory(this);
1541
+ const { HEAPU8 } = getMemory(this, path + path_len);
1529
1542
  const wasi = _wasi.get(this);
1530
1543
  const fileDescriptor = wasi.fds.get(fd, types_1.WasiRights.PATH_UNLINK_FILE, BigInt(0));
1531
1544
  let pathString = decoder.decode((0, util_1.unsharedSlice)(HEAPU8, path, path + path_len));