Skip to content

Add bounds checking in codec decode functions to prevent DoS via crafted buffers #6

@goulvenclech

Description

@goulvenclech

decode_mdx_jsx_attr (crates/mdast/src/codec.rs), decode_element_prop and decode_mdx_jsx_attr (crates/hast/src/codec.rs), and decode_table_data (crates/mdast/src/codec.rs) compute offsets from counts read from type_data (e.g. base = 16 + index * 20) without verifying the data is large enough. Since buffers arrive from JS via NAPI, a crafted buffer with attr_count=1000 but only 16 bytes of type_data triggers an index out-of-bounds panic, which aborts the Node.js process (DoS).

from_raw_buffer validates global buffer structure but not per-node type_data semantic consistency.

Suggested fix: Add size guards at call sites before decode loops: data.len() >= 16 + count * 20, or make decode functions return Option/Result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions