Skip to content

Fix setDatatype endianness when writing to Wasm memory#553

Open
vinayakray19 wants to merge 2 commits into
proxy-wasm:mainfrom
vinayakray19:bugfix/le-to-be-conversion
Open

Fix setDatatype endianness when writing to Wasm memory#553
vinayakray19 wants to merge 2 commits into
proxy-wasm:mainfrom
vinayakray19:bugfix/le-to-be-conversion

Conversation

@vinayakray19

@vinayakray19 vinayakray19 commented Jun 18, 2026

Copy link
Copy Markdown

Summary

  • Fix WasmBase::setDatatype to convert integers to Wasm (little-endian) byte order via htowasm before writing to linear memory
  • Add SetDatatypeWritesLittleEndian regression test in wasm_vm_test.cc

Fixes #552

Problem

On big-endian hosts (s390x), setDatatype wrote host-native integer bytes into Wasm memory. This broke hostcalls that return primitives via output pointers (e.g. proxy_get_log_level) and could cause proxy_on_configure failures in Rust Wasm plugins.

setWord already handled endianness correctly; setDatatype did not.

Test Added

  • Added SetDatatypeWritesLittleEndian regression test (asserts LE bytes 01 00 00 02 for value 0x02000001)

@google-cla

google-cla Bot commented Jun 18, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@vinayakray19 vinayakray19 force-pushed the bugfix/le-to-be-conversion branch 2 times, most recently from 2d56183 to ccb0e1d Compare June 18, 2026 12:42
Wasm linear memory is little-endian, but setDatatype wrote host-native
integer bytes via setMemory. On big-endian hosts such as s390x this broke
hostcalls that return primitives (for example proxy_get_log_level) and
could cause plugin configure failures.

Apply htowasm using the VM's usesWasmByteOrder flag, matching setWord.
Add a regression test that asserts setDatatype stores little-endian bytes.

Signed-off-by: vinayakray19 <vinayak.ray@ibm.com>
@vinayakray19 vinayakray19 force-pushed the bugfix/le-to-be-conversion branch from ccb0e1d to 0e3cec0 Compare June 18, 2026 12:43
@leonm1

leonm1 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Thank you for your contribution! Could you add a test to test/endianness_test.cc that uses setDatatype? That way, we have an end-to-end test to ensure the bytes writen by the host are properly interpreted by the wasm module.

@vinayakray19

Copy link
Copy Markdown
Author

sure @leonm1

Extend endianness.wasm with test_host_set_datatype, which calls
proxy_get_log_level and verifies the u32 written by the host via
setDatatype. EndiannessContext returns 0x02000001 so the test fails on
big-endian hosts if bytes are not converted to Wasm little-endian order.
Signed-off-by: vinayakray19 <vinayak.ray@ibm.com>
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

Successfully merging this pull request may close these issues.

setDatatype writes host-endian integers to Wasm memory on big-endian (s390x)

2 participants