8000 `readMemoryAt` is broken · Issue #54 · dfinity/wasmtime-hs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

readMemoryAt is broken #54

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

Open
kirisaki opened this issue Feb 26, 2025 · 0 comments
Open

readMemoryAt is broken #54

kirisaki opened this issue Feb 26, 2025 · 0 comments

Comments

@kirisaki
Copy link
Contributor

I tried the following test code at test/memory.hs:

  putStrLn "Read memory at 0x1003..."
  x <- readMemoryAt store memory 0x1003 4
  B.decode (LBS.fromStrict x) @?= (4 :: Int32)

But it failed without so much as returning a Left value. Then, I checked the code of readMemoryAt:

readMemoryAt store mem offset sz = do
  max_sz <- getMemorySizeBytes store mem
  unsafeIOToPrim $ do
    if offset + sz > max_sz
      then pure $ Left MemoryAccessError
      else do
        res <- unsafeWithMemory store mem $ \mem_data_ptr mem_size ->
          BI.create (fromIntegral mem_size) $ \dst_ptr ->
            copyBytes
              dst_ptr
              (advancePtr mem_data_ptr (fromIntegral offset))
              (fromIntegral mem_size)
        pure $ Right res

It seems to return the entire memory with the offset. When I set the offset to 0, it yielded a very long byte string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0