Code Monkey home page Code Monkey logo

Comments (6)

mathetake avatar mathetake commented on June 3, 2024 1

Thank you @EclesioMeloJunior for reporting this, and I confirmed that this is actually a bug in our API. As you described, when the memory has the maximum of 65536 pages, the buffer length becomes 2^32, which is larger than the maximum of uint32 which is the return type of api.Memory Size.

We could do either

  1. Changing the return type of api.Memory Size to uint64
    • This is somewhat breaking change, though the impact should be really minimum because this is just a integer type conversion.
  2. Adds another for SizeSafe() uint64 or whatever it is while putting deprecation comments on the api.Memory Size.
    • This won't be a breaking change

thoughts? @evacchi @ncruces @achille-roussel

from wazero.

mathetake avatar mathetake commented on June 3, 2024 1

what about checking in the Grow method for this limit? I mean, instead of allowing the buffer size to reach 2^32 (which overflows uint32 only by 1) check and limit the buffer size/cap to be (2^32) - 1 then it will bound to uint32 limits (and the Size will not have problems to calc/return the correct size). I would assume that the problem with this approach is that the latest page will lose 1 byte (65535 instead of 65536), right?

no that's not our option as that means wazero is not compliant with the Wasm spec.

from wazero.

EclesioMeloJunior avatar EclesioMeloJunior commented on June 3, 2024

@mathetake thanks for the response, I have a question regards the SizeSafe, what it will return in a case where the buffer size overflows uint32 limits? Also, I would like to add that wasmtime memory size function returns a u64

I would like to add a third option:

  • what about checking in the Grow method for this limit? I mean, instead of allowing the buffer size to reach 2^32 (which overflows uint32 only by 1) check and limit the buffer size/cap to be (2^32) - 1 then it will bound to uint32 limits (and the Size will not have problems to calc/return the correct size). I would assume that the problem with this approach is that the latest page will lose 1 byte (65535 instead of 65536), right?

from wazero.

ncruces avatar ncruces commented on June 3, 2024

Since memory size can't be (2^32) - 1, I'd return that and document the corner case?
I'd maybe call the other method Size64, in preparation for 64 bit memories?

from wazero.

EclesioMeloJunior avatar EclesioMeloJunior commented on June 3, 2024

@mathetake @ncruces thanks for the clarifications, I took the freedom to create a draft PR that introduces the new method #1856

from wazero.

mathetake avatar mathetake commented on June 3, 2024

So we are looking to release wazero 2.0 next month, and I think we can make the breaking change to this rather than having another confusing api like Size64.

Tomorrow I will raise a PR to do so, which supersedes #1856. Thank you for your help anyway @EclesioMeloJunior

from wazero.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.