xixi-box removed the review request for wasmtime-core-reviewers from PR #15275.
xixi-box opened PR #15275 from xixi-box:fix/issue-15267-1d4f64d-15780858 to bytecodealliance:main:
Fixes #15267
Root cause: Core dump serialization omits custom memory page sizes and drops the final partial chunk by using chunks_exact.
<!-- oss-scout-job:job-2dbfaeb9-d38b-46de-ae22-157808587588 -->
Tests:
cargo test -p wasmtime --test coredump coredump_custom_page_sizes -- --exact --nocapture(fails on base; passes with this patch).
Regression coverage:crates/wasmtime/tests/coredump.rs.AI assistance: Codex helped implement and test this change. oss-scout independently replayed the regression before opening this PR.
xixi-box requested dicej for a review on PR #15275.
xixi-box requested wasmtime-core-reviewers for a review on PR #15275.
:repeat: pchickey submitted PR review:
The code changes are ok, but the test is overwrought, and its not located where the rest of the tests for coredump are.
Here is an appropriately cut down test to use instead
diff --git a/crates/wasmtime/src/runtime/coredump.rs b/crates/wasmtime/src/runtime/coredump.rs index 2d5f8bf6c1..8f76624de7 100644 --- a/crates/wasmtime/src/runtime/coredump.rs +++ b/crates/wasmtime/src/runtime/coredump.rs @@ -128,7 +128,10 @@ impl WasmCoreDump { maximum: ty.maximum(), memory64: ty.is_64(), shared: ty.is_shared(), - page_size_log2: None, + page_size_log2: match ty.page_size_log2() { + 16 => None, + n => Some(n.into()), + }, }); // Attach the memory data, balancing number of data segments and @@ -142,7 +145,7 @@ impl WasmCoreDump { // into reasonably-sized chunks and then trim runs of zeroes // from the start and end of each chunk. const CHUNK_SIZE: usize = 4096; - for (i, chunk) in mem.data(&store).chunks_exact(CHUNK_SIZE).enumerate() { + for (i, chunk) in mem.data(&store).chunks(CHUNK_SIZE).enumerate() { if let Some(start) = chunk.iter().position(|byte| *byte != 0) { let end = chunk.iter().rposition(|byte| *byte != 0).unwrap() + 1; let offset = i * CHUNK_SIZE + start; diff --git a/tests/all/coredump.rs b/tests/all/coredump.rs index 8001fba646..21d04837a0 100644 --- a/tests/all/coredump.rs +++ b/tests/all/coredump.rs @@ -200,6 +200,77 @@ fn coredump_has_defined_globals_and_memory() -> Result<()> { Ok(()) } +#[test] +#[cfg_attr(miri, ignore)] +fn coredump_with_custom_page_size_and_partial_chunk() -> Result<()> { + let mut config = Config::default(); + config.coredump_on_trap(true); + config.wasm_custom_page_sizes(true); + let engine = Engine::new(&config)?; + + // Core dump serialization splits memory into 4096-byte chunks. With the + // default 64KiB page size every memory is a multiple of that chunk size, + // but with custom page sizes it need not be. This memory is 5000 bytes: + // one full chunk plus a 904-byte tail, with non-zero data in the tail. + let module = Module::new( + &engine, + r#" + (module + (memory 5000 (pagesize 1)) + (data (i32.const 4999) "\2a") + (func (export "a") unreachable) + ) + "#, + )?; + let mut store = Store::<()>::new(&engine, ()); + let instance = Instance::new(&mut store, &module, &[])?; + let a_func = instance.get_typed_func::<(), ()>(&mut store, "a")?; + let err = a_func.call(&mut store, ()).unwrap_err(); + let core_dump = err.downcast_ref::<WasmCoreDump>().unwrap(); + assert_eq!(core_dump.memories().len(), 1); + let bytes = core_dump.serialize(&mut store, "custom-page-size"); + + let mut memory_types = vec![]; + let mut saw_tail_byte = false; + for payload in wasmparser::Parser::new(0).parse_all(&bytes) { + match payload? { + wasmparser::Payload::MemorySection(s) => { + for ty in s { + memory_types.push(ty?); + } + } + wasmparser::Payload::DataSection(s) => { + for data in s { + let data = data?; + let wasmparser::DataKind::Active { offset_expr, .. } = data.kind else { + continue; + }; + let mut ops = offset_expr.get_operators_reader(); + let wasmparser::Operator::I32Const { value } = ops.read()? else { + panic!("unexpected data segment offset expression"); + }; + let start = usize::try_from(value).unwrap(); + if (start..start + data.data.len()).contains(&4999) { + assert_eq!(data.data[4999 - start], 0x2a); + saw_tail_byte = true; + } + } + } + _ => {} + } + } + + assert!( + saw_tail_byte, + "data in the final partial chunk of memory was dropped" + ); + assert_eq!(memory_types.len(), 1); + assert_eq!(memory_types[0].page_size_log2, Some(0)); + assert_eq!(memory_types[0].initial, 5000); + + Ok(()) +} + #[test] #[cfg_attr(miri, ignore)] fn multiple_globals_memories_and_instances() -> Result<()> {
:repeat: pchickey submitted PR review:
The code changes are ok, but the test is overwrought, and its not located where the rest of the tests for coredump are.
Here is an appropriately cut down test to use instead
diff --git a/crates/wasmtime/src/runtime/coredump.rs b/crates/wasmtime/src/runtime/coredump.rs index 2d5f8bf6c1..8f76624de7 100644 --- a/crates/wasmtime/src/runtime/coredump.rs +++ b/crates/wasmtime/src/runtime/coredump.rs @@ -128,7 +128,10 @@ impl WasmCoreDump { maximum: ty.maximum(), memory64: ty.is_64(), shared: ty.is_shared(), - page_size_log2: None, + page_size_log2: match ty.page_size_log2() { + 16 => None, + n => Some(n.into()), + }, }); // Attach the memory data, balancing number of data segments and @@ -142,7 +145,7 @@ impl WasmCoreDump { // into reasonably-sized chunks and then trim runs of zeroes // from the start and end of each chunk. const CHUNK_SIZE: usize = 4096; - for (i, chunk) in mem.data(&store).chunks_exact(CHUNK_SIZE).enumerate() { + for (i, chunk) in mem.data(&store).chunks(CHUNK_SIZE).enumerate() { if let Some(start) = chunk.iter().position(|byte| *byte != 0) { let end = chunk.iter().rposition(|byte| *byte != 0).unwrap() + 1; let offset = i * CHUNK_SIZE + start; diff --git a/tests/all/coredump.rs b/tests/all/coredump.rs index 8001fba646..21d04837a0 100644 --- a/tests/all/coredump.rs +++ b/tests/all/coredump.rs @@ -200,6 +200,77 @@ fn coredump_has_defined_globals_and_memory() -> Result<()> { Ok(()) } +#[test] +#[cfg_attr(miri, ignore)] +fn coredump_with_custom_page_size_and_partial_chunk() -> Result<()> { + let mut config = Config::default(); + config.coredump_on_trap(true); + config.wasm_custom_page_sizes(true); + let engine = Engine::new(&config)?; + + // Core dump serialization splits memory into 4096-byte chunks. With the + // default 64KiB page size every memory is a multiple of that chunk size, + // but with custom page sizes it need not be. This memory is 5000 bytes: + // one full chunk plus a 904-byte tail, with non-zero data in the tail. + let module = Module::new( + &engine, + r#" + (module + (memory 5000 (pagesize 1)) + (data (i32.const 4999) "\2a") + (func (export "a") unreachable) + ) + "#, + )?; + let mut store = Store::<()>::new(&engine, ()); + let instance = Instance::new(&mut store, &module, &[])?; + let a_func = instance.get_typed_func::<(), ()>(&mut store, "a")?; + let err = a_func.call(&mut store, ()).unwrap_err(); + let core_dump = err.downcast_ref::<WasmCoreDump>().unwrap(); + assert_eq!(core_dump.memories().len(), 1); + let bytes = core_dump.serialize(&mut store, "custom-page-size"); + + let mut memory_types = vec![]; + let mut saw_tail_byte = false; + for payload in wasmparser::Parser::new(0).parse_all(&bytes) { + match payload? { + wasmparser::Payload::MemorySection(s) => { + for ty in s { + memory_types.push(ty?); + } + } + wasmparser::Payload::DataSection(s) => { + for data in s { + let data = data?; + let wasmparser::DataKind::Active { offset_expr, .. } = data.kind else { + continue; + }; + let mut ops = offset_expr.get_operators_reader(); + let wasmparser::Operator::I32Const { value } = ops.read()? else { + panic!("unexpected data segment offset expression"); + }; + let start = usize::try_from(value).unwrap(); + if (start..start + data.data.len()).contains(&4999) { + assert_eq!(data.data[4999 - start], 0x2a); + saw_tail_byte = true; + } + } + } + _ => {} + } + } + + assert!( + saw_tail_byte, + "data in the final partial chunk of memory was dropped" + ); + assert_eq!(memory_types.len(), 1); + assert_eq!(memory_types[0].page_size_log2, Some(0)); + assert_eq!(memory_types[0].initial, 5000); + + Ok(()) +} + #[test] #[cfg_attr(miri, ignore)] fn multiple_globals_memories_and_instances() -> Result<()> {
:repeat: pchickey submitted PR review:
The code changes are ok, but the test is overwrought, and its not located where the rest of the tests for coredump are.
Here is an appropriately cut down test to use instead
diff --git a/crates/wasmtime/src/runtime/coredump.rs b/crates/wasmtime/src/runtime/coredump.rs index 2d5f8bf6c1..8f76624de7 100644 --- a/crates/wasmtime/src/runtime/coredump.rs +++ b/crates/wasmtime/src/runtime/coredump.rs @@ -128,7 +128,10 @@ impl WasmCoreDump { maximum: ty.maximum(), memory64: ty.is_64(), shared: ty.is_shared(), - page_size_log2: None, + page_size_log2: match ty.page_size_log2() { + 16 => None, + n => Some(n.into()), + }, }); // Attach the memory data, balancing number of data segments and @@ -142,7 +145,7 @@ impl WasmCoreDump { // into reasonably-sized chunks and then trim runs of zeroes // from the start and end of each chunk. const CHUNK_SIZE: usize = 4096; - for (i, chunk) in mem.data(&store).chunks_exact(CHUNK_SIZE).enumerate() { + for (i, chunk) in mem.data(&store).chunks(CHUNK_SIZE).enumerate() { if let Some(start) = chunk.iter().position(|byte| *byte != 0) { let end = chunk.iter().rposition(|byte| *byte != 0).unwrap() + 1; let offset = i * CHUNK_SIZE + start; diff --git a/tests/all/coredump.rs b/tests/all/coredump.rs index 8001fba646..21d04837a0 100644 --- a/tests/all/coredump.rs +++ b/tests/all/coredump.rs @@ -200,6 +200,77 @@ fn coredump_has_defined_globals_and_memory() -> Result<()> { Ok(()) } +#[test] +#[cfg_attr(miri, ignore)] +fn coredump_with_custom_page_size_and_partial_chunk() -> Result<()> { + let mut config = Config::default(); + config.coredump_on_trap(true); + config.wasm_custom_page_sizes(true); + let engine = Engine::new(&config)?; + + // Core dump serialization splits memory into 4096-byte chunks. With the + // default 64KiB page size every memory is a multiple of that chunk size, + // but with custom page sizes it need not be. This memory is 5000 bytes: + // one full chunk plus a 904-byte tail, with non-zero data in the tail. + let module = Module::new( + &engine, + r#" + (module + (memory 5000 (pagesize 1)) + (data (i32.const 4999) "\2a") + (func (export "a") unreachable) + ) + "#, + )?; + let mut store = Store::<()>::new(&engine, ()); + let instance = Instance::new(&mut store, &module, &[])?; + let a_func = instance.get_typed_func::<(), ()>(&mut store, "a")?; + let err = a_func.call(&mut store, ()).unwrap_err(); + let core_dump = err.downcast_ref::<WasmCoreDump>().unwrap(); + assert_eq!(core_dump.memories().len(), 1); + let bytes = core_dump.serialize(&mut store, "custom-page-size"); + + let mut memory_types = vec![]; + let mut saw_tail_byte = false; + for payload in wasmparser::Parser::new(0).parse_all(&bytes) { + match payload? { + wasmparser::Payload::MemorySection(s) => { + for ty in s { + memory_types.push(ty?); + } + } + wasmparser::Payload::DataSection(s) => { + for data in s { + let data = data?; + let wasmparser::DataKind::Active { offset_expr, .. } = data.kind else { + continue; + }; + let mut ops = offset_expr.get_operators_reader(); + let wasmparser::Operator::I32Const { value } = ops.read()? else { + panic!("unexpected data segment offset expression"); + }; + let start = usize::try_from(value).unwrap(); + if (start..start + data.data.len()).contains(&4999) { + assert_eq!(data.data[4999 - start], 0x2a); + saw_tail_byte = true; + } + } + } + _ => {} + } + } + + assert!( + saw_tail_byte, + "data in the final partial chunk of memory was dropped" + ); + assert_eq!(memory_types.len(), 1); + assert_eq!(memory_types[0].page_size_log2, Some(0)); + assert_eq!(memory_types[0].initial, 5000); + + Ok(()) +} + #[test] #[cfg_attr(miri, ignore)] fn multiple_globals_memories_and_instances() -> Result<()> {
xixi-box updated PR #15275.
:thumbs_up: pchickey submitted PR review.
pchickey has enabled auto merge for PR #15275.
xixi-box commented on PR #15275:
Thanks for the review! I've applied your suggestions in
a168e74.I simplified the regression test and moved it to
tests/all/coredump.rs, alongside the existing coredump tests. I also removed the standalone test file and adjusted the page-size handling as suggested.I couldn't run the Rust tests locally, so CI verification is still pending. Thanks again for the guidance!
pchickey added PR #15275 fix: Core dumps of custom-page-size memories truncate their data and declare the wrong size to the merge queue.
pchickey commented on PR #15275:
@xixi-box I'd like to ask you to hold off on making more contributions in Bytecode Alliance project repositories using AI, until you have met with the Wasmtime team in a team meeting to discuss a substantial contribution you'll be making without AI assistance. The maintainers are overwhelmed with review load, and review of simple PRs like this takes the same amount of effort as prompting claude to make these fixes ourselves. We are only interested in having new contributors who are going to make the sort of deep engagement with these projects as a community of engineers who have internalized significant parts of the project.
xixi-box commented on PR #15275:
Thank you for the honest feedback. I understand your concerns about maintainer review load, and I'm sorry for adding to that burden.
I'll respect your request and hold off on further AI-assisted contributions to Bytecode Alliance repositories.
I appreciate the time you've spent reviewing my PR and the guidance on what meaningful participation in the project looks like.
:check: pchickey merged PR #15275.
pchickey removed PR #15275 fix: Core dumps of custom-page-size memories truncate their data and declare the wrong size from the merge queue.
Last updated: Nov 19 2026 at 20:05 UTC