Fix incorrect parameter index in WASI fd_read#2700
Merged
Conversation
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
approved these changes
Feb 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a copy-paste bug in the WASI
fd_readimplementation whereparams[2]was used for bothiovcntandout_ptr.Details
In
src/interp/interp-wasi.cc, thefd_readfunction extracts its four parameters from theparamsarray:However,
out_ptrwas incorrectly reading fromparams[2]instead ofparams[3], causing it to receive the same value asiovcnt. 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_writeimplementation, which properly usesparams[3]for its output pointer.Test plan
cmake --build build --target wabt-unittests)fd_writeimplementation which correctly usesparams[3]