-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check offset overflow in fd_pwrite #254
Conversation
This commit fixes a potential overflow in fd_pwrite. Since `uv_fs_write` takes an `int64_t` as the offset while `fd_pwrite` accepts an `uint64_t`, we need to check it doesn't overflow when cast.
69ef286
to
a449870
Compare
Strictly speaking, this is not actually an overflow though I believe because Wasm treats u64 types as i64 types in the host integration layer since it doesn't distinguish between them. Thus while to native callers it is taking an i64, negative values passed should still be interpreted as their unsigned equivalents. See https://webassembly.github.io/spec/core/syntax/types.html#number-types for more info on this from a Wasm perspective. |
That said, ideally uvwasi would be properly typed here in having a signature that takes a |
But we should not land this overflow check as the correct interpretation of the code is as an unsigned argument. |
Hi @guybedford I created an issue #256 explaining the motivation. I don't think this statement:
applies to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Here is the preview1 spec for
Therefore the interface is not correct by the spec. Implementation behaviour is another question of course, and we can choose to ban this, but my clarification is that this is valid per the preview1-specified function signature. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second read I see what you mean about the implementation detail here.
That the function signature is not u64 is actually a separate question I suppose then, regardless of implementation bounds per this PR.
Thanks for talking it through.
The proposed fix looks good for now, and I've now filed WebAssembly/wasi-filesystem#146 to discuss what should do in the spec. |
This commit fixes a potential overflow in fd_pwrite. Since
uv_fs_write
takes anint64_t
as the offset whilefd_pwrite
accepts anuint64_t
, we need to check it doesn't overflow when cast.