Skip to content

Commit 80d7b6e

Browse files
cjihrigtargos
authored andcommitted
wasi: fix serdes bugs from snapshot1 migration
During the migration to WASI snapshot1, a field was removed from the subscription type. The field was removed from the code, but the bounds checking logic was not updated. This commit updates that check. Similarly, __wasi_linkcount_t changed from a uint32_t to a uint64_t. However, the bounds checks were missed, and the code was still writing uint32_t's (to the new correct offset) instead of uint64_t's. This commit updates that logic as well. Refs: #30980 PR-URL: #31122 Reviewed-By: David Carlier <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 4a7e860 commit 80d7b6e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/node_wasi.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -544,15 +544,15 @@ void WASI::FdFilestatGet(const FunctionCallbackInfo<Value>& args) {
544544
ASSIGN_OR_RETURN_UNWRAP(&wasi, args.This());
545545
Debug(wasi, "fd_filestat_get(%d, %d)\n", fd, buf);
546546
GET_BACKING_STORE_OR_RETURN(wasi, args, &memory, &mem_size);
547-
CHECK_BOUNDS_OR_RETURN(args, mem_size, buf, 56);
547+
CHECK_BOUNDS_OR_RETURN(args, mem_size, buf, 64);
548548
uvwasi_filestat_t stats;
549549
uvwasi_errno_t err = uvwasi_fd_filestat_get(&wasi->uvw_, fd, &stats);
550550

551551
if (err == UVWASI_ESUCCESS) {
552552
wasi->writeUInt64(memory, stats.st_dev, buf);
553553
wasi->writeUInt64(memory, stats.st_ino, buf + 8);
554554
wasi->writeUInt8(memory, stats.st_filetype, buf + 16);
555-
wasi->writeUInt32(memory, stats.st_nlink, buf + 24);
555+
wasi->writeUInt64(memory, stats.st_nlink, buf + 24);
556556
wasi->writeUInt64(memory, stats.st_size, buf + 32);
557557
wasi->writeUInt64(memory, stats.st_atim, buf + 40);
558558
wasi->writeUInt64(memory, stats.st_mtim, buf + 48);
@@ -1068,7 +1068,7 @@ void WASI::PathFilestatGet(const FunctionCallbackInfo<Value>& args) {
10681068
path_len);
10691069
GET_BACKING_STORE_OR_RETURN(wasi, args, &memory, &mem_size);
10701070
CHECK_BOUNDS_OR_RETURN(args, mem_size, path_ptr, path_len);
1071-
CHECK_BOUNDS_OR_RETURN(args, mem_size, buf_ptr, 56);
1071+
CHECK_BOUNDS_OR_RETURN(args, mem_size, buf_ptr, 64);
10721072
uvwasi_filestat_t stats;
10731073
uvwasi_errno_t err = uvwasi_path_filestat_get(&wasi->uvw_,
10741074
fd,
@@ -1080,7 +1080,7 @@ void WASI::PathFilestatGet(const FunctionCallbackInfo<Value>& args) {
10801080
wasi->writeUInt64(memory, stats.st_dev, buf_ptr);
10811081
wasi->writeUInt64(memory, stats.st_ino, buf_ptr + 8);
10821082
wasi->writeUInt8(memory, stats.st_filetype, buf_ptr + 16);
1083-
wasi->writeUInt32(memory, stats.st_nlink, buf_ptr + 24);
1083+
wasi->writeUInt64(memory, stats.st_nlink, buf_ptr + 24);
10841084
wasi->writeUInt64(memory, stats.st_size, buf_ptr + 32);
10851085
wasi->writeUInt64(memory, stats.st_atim, buf_ptr + 40);
10861086
wasi->writeUInt64(memory, stats.st_mtim, buf_ptr + 48);
@@ -1422,7 +1422,7 @@ void WASI::PollOneoff(const FunctionCallbackInfo<Value>& args) {
14221422
nsubscriptions,
14231423
nevents_ptr);
14241424
GET_BACKING_STORE_OR_RETURN(wasi, args, &memory, &mem_size);
1425-
CHECK_BOUNDS_OR_RETURN(args, mem_size, in_ptr, nsubscriptions * 56);
1425+
CHECK_BOUNDS_OR_RETURN(args, mem_size, in_ptr, nsubscriptions * 48);
14261426
CHECK_BOUNDS_OR_RETURN(args, mem_size, out_ptr, nsubscriptions * 32);
14271427
CHECK_BOUNDS_OR_RETURN(args, mem_size, nevents_ptr, 4);
14281428
uvwasi_subscription_t* in =

0 commit comments

Comments
 (0)