Skip to content

WASM write creates slice with null pointer #108

Closed
@GnomedDev

Description

@GnomedDev

Describe the bug
The WASM write function is called with null pointer via the JS wrapper, which causes a panic when compiled in debug mode and UB in release mode.

sax-wasm/src/js/saxWasm.ts

Lines 674 to 675 in e4ea343

this.writeBuffer.set(chunk, 0);
write(0, chunk.byteLength);

sax-wasm/src/sax_wasm.rs

Lines 48 to 49 in e4ea343

pub unsafe extern "C" fn write(ptr: *const u8, length: usize) {
let document = slice::from_raw_parts(ptr, length);

To Reproduce

  1. Compile with a recent stable compiler without --release.
  2. Call SAXParser.write.
  3. WASM crashes with unreachable instruction.

Expected behavior
The Rust code does not construct a null slice.

Desktop (please complete the following information):

  • OS: Linux
  • Browser: Firefox 135, Chromium 133.0.6943.98

Additional context
I am trying to use this library to parse XML files that are nearly 1gb, and running into an infinite loop. I found this while trying to debug that.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions