Skip to content

Fix incorrect parameter index in WASI fd_read#2700

Merged
sbc100 merged 1 commit into
WebAssembly:mainfrom
sumleo:fix/wasi-fd-read-param-index
Feb 25, 2026
Merged

Fix incorrect parameter index in WASI fd_read#2700
sbc100 merged 1 commit into
WebAssembly:mainfrom
sumleo:fix/wasi-fd-read-param-index

Conversation

@sumleo

@sumleo sumleo commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix a copy-paste bug in the WASI fd_read implementation where params[2] was used for both iovcnt and out_ptr.

Details

In src/interp/interp-wasi.cc, the fd_read function extracts its four parameters from the params array:

params[0] -> fd
params[1] -> iovptr
params[2] -> iovcnt
params[3] -> out_ptr (nread)

However, out_ptr was incorrectly reading from params[2] instead of params[3], causing it to receive the same value as iovcnt. This meant the number of bytes read would be written to the wrong memory address.

The correct behavior can be seen in the adjacent fd_write implementation, which properly uses params[3] for its output pointer.

Test plan

  • Verified the fix compiles successfully (cmake --build build --target wabt-unittests)
  • Compared with fd_write implementation which correctly uses params[3]

In fd_read, params[2] was used for both iovcnt and out_ptr due to a
copy-paste error. The out_ptr should use params[3], which is the fourth
argument to fd_read (the pointer where the number of bytes read is
written). This matches the correct usage in the fd_write implementation.

WASI fd_read signature: fd_read(fd, iovs, iovcnt, nread) -> errno
  params[0] = fd
  params[1] = iovs (iovptr)
  params[2] = iovcnt
  params[3] = nread (out_ptr)  <-- was incorrectly params[2]
@sbc100 sbc100 enabled auto-merge (squash) February 25, 2026 18:03
@sbc100 sbc100 disabled auto-merge February 25, 2026 18:24
@sbc100 sbc100 merged commit bb29abe into WebAssembly:main Feb 25, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants