Skip to content
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

fix(c-api) wasm_limits_t contains Pages, not Bytes + sentinel value #1690

Merged
merged 4 commits into from
Oct 8, 2020

Conversation

Hywan
Copy link
Contributor

@Hywan Hywan commented Oct 8, 2020

When building a wasm_memorytype_t with wasm_memorytype_new, we
pass a wasm_limits_t, where min and max represent Pages. This
semantics is set by wasm_memorytype_new itself where min and max
from wasm_limits_t are used to compute Pages, which are then passed
to MemoryType.

Then, in wasm_memorytype_limits, we expect to get the same
wasm_limits_t given to wasm_memorytype_new. But it's not!

The same MemoryType is read, good. The minimum and maximum
fields are Pages, good. Then, we compute the min and max values
for the resulting wasm_limits_t, which receive Page.bytes().0, not
good! We don't want the number of bytes, but the number of pages.

This patch fixes that.

Edit: This patch also fixes the max limit sentinel value. In wasm.h, it is defined by wasm_limits_max_default (0xffffffff). In our code, it is correctly used in wasm_memorytype_new, but not in wasm_memorytype_limits. A new constant has been introduced: LIMITS_MAX_SENTINEL. Not super happy with this name though.

When building a `wasm_memorytype_t` with `wasm_memorytype_new`, we
pass a `wasm_limits_t`, where `min` and `max` represent `Pages`. This
semantics is set by `wasm_memorytype_new` itself where `min` and `max`
from `wasm_limits_t` are used to compute `Pages`, which are then passed
to `MemoryType`.

Then, in `wasm_memorytype_limits`, we expect to get the same
`wasm_limits_t` given to `wasm_memorytype_new`. But it's not!

The same `MemoryType` is read, good. The `minimum` and `maximum`
fields are `Pages`, good. Then, we compute the `min` and `max` values
for the resulting `wasm_limits_t`, which receive `Page.bytes().0`, not
good! We don't want the number of bytes, but the number of pages.

This patch fixes that.
@Hywan Hywan added the bug Something isn't working label Oct 8, 2020
@Hywan Hywan requested a review from MarkMcCaskey October 8, 2020 15:22
@Hywan Hywan changed the title fix(c-api) wasm_limits_t contains Pages, not Bytes. fix(c-api) wasm_limits_t contains Pages, not Bytes + sentinel value Oct 8, 2020
@Hywan
Copy link
Contributor Author

Hywan commented Oct 8, 2020

bors r+

@bors
Copy link
Contributor

bors bot commented Oct 8, 2020

@bors bors bot merged commit 2459d5d into wasmerio:master Oct 8, 2020
Comment on lines +62 to +66
min: md.minimum.0 as _,
max: md
.maximum
.map(|max| max.0 as _)
.unwrap_or(LIMITS_MAX_SENTINEL),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, I didn't see that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants