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

Allow 65536 pages #2258

Closed
wants to merge 10 commits into from
Closed

Allow 65536 pages #2258

wants to merge 10 commits into from

Conversation

k-nasa
Copy link
Contributor

@k-nasa k-nasa commented Apr 25, 2021

Description

fix: #2187

Memory minimum and maximum sizes range 0..65536 inclusive. The verifier blocks 65537 and higher. However, wasmer only works on 65535 and lower.

I fixed this issue.

Review

  • Add a short description of the change to the CHANGELOG.md file

@k-nasa
Copy link
Contributor Author

k-nasa commented Apr 25, 2021

I would like to add a test to detect this issue. But I don't understand structure of tests in this repository so I don't know where to add it. Can you give me a signpost?

@nlewycky
Copy link
Contributor

Thank you for the patch! A .wast type test in tests/wast/wasmer should do it.

@@ -259,6 +259,7 @@ impl LinearMemory {
let mapped_pages = memory.minimum;
let mapped_bytes = mapped_pages.bytes();

println!("{}", minimum_bytes);
Copy link
Member

Choose a reason for hiding this comment

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

Delete debug print

Copy link
Contributor Author

Choose a reason for hiding this comment

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

🙈 I fixed it. 755639c

@k-nasa
Copy link
Contributor Author

k-nasa commented Apr 26, 2021

Thanks @nlewycky! I was able to add test.

Comment on lines 94 to 95
impl From<u32> for Bytes {
fn from(other: u32) -> Self {
impl From<u64> for Bytes {
fn from(other: u64) -> Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please keep both implementations, otherwise it's a regression :-).

@@ -340,7 +340,7 @@ pub struct VMMemoryDefinition {
pub base: *mut u8,

/// The current logical size of this linear memory in bytes.
pub current_length: u32,
pub current_length: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if we should not create a type alias to represent the memory size, something like pub type MemorySize = u64. Thoughts @nlewycky, @MarkMcCaskey, @syrusakbary?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so in this case, we aren't going to be changing this type or confusing it with other values much.

Copy link
Contributor

@nlewycky nlewycky left a comment

Choose a reason for hiding this comment

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

This:
https://sourcegraph.com/github.com/wasmerio/wasmer/-/blob/lib/compiler-llvm/src/translator/intrinsics.rs#L620:13
also need to be updated from i32 to i64 or else we'll compute the wrong value, and that may require some further changes (llvm is a strongly-typed IR and so any place it's used with another i32 will fail the verifier).

Similarly singlepass loads a 32-bit value into a register here:
https://sourcegraph.com/github.com/wasmerio/wasmer/-/blob/lib/compiler-singlepass/src/codegen_x64.rs#L1280

I'm not sure what the equivalent is in cranelift, possibly the type of the global_value in make_heap in src/func_environ.rs (not src/translator/func_environ.rs)?

@@ -340,7 +340,7 @@ pub struct VMMemoryDefinition {
pub base: *mut u8,

/// The current logical size of this linear memory in bytes.
pub current_length: u32,
pub current_length: u64,
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think so in this case, we aren't going to be changing this type or confusing it with other values much.

@Hywan Hywan self-assigned this Jul 19, 2021
@Hywan Hywan added bug Something isn't working 📦 lib-types About wasmer-types labels Jul 19, 2021
@syrusakbary syrusakbary assigned Amanieu and unassigned Hywan Oct 28, 2021
@syrusakbary syrusakbary removed the request for review from MarkMcCaskey October 28, 2021 15:51
@syrusakbary syrusakbary added the 🕵️ needs investigation The issue/PR needs further investigation label Oct 28, 2021
@Amanieu
Copy link
Contributor

Amanieu commented Nov 10, 2021

Superseded by #2677

@Amanieu Amanieu closed this Nov 10, 2021
@k-nasa k-nasa deleted the fix_bug branch November 11, 2021 01:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working 📦 lib-types About wasmer-types 🕵️ needs investigation The issue/PR needs further investigation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

can't represent 65536 pages
5 participants