Skip to content

modules: report a broken .vxlib file as an error that names the file - #4623

Open
hiraditya wants to merge 1 commit into
fix/macro-trusted-code-writerfrom
fix/broken-vxlib-is-an-error
Open

hiraditya wants to merge 1 commit into
fix/macro-trusted-code-writerfrom
fix/broken-vxlib-is-an-error

Conversation

@hiraditya

@hiraditya hiraditya commented Dec 4, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #4619. The change does not need #4619, but #4624 (the fix for #4599) needs both, and a stack is one line.

vxc reads a .vxlib file in place of the .vx file beside it. An empty .vxlib made vxc panic in gid.rs, because the decoder sliced the file without checking its length. Other broken files could panic or overflow the stack too.

What changed

  • The decoder checks each read:

    • The header length, and the overflow of the type count.
    • Each count of items. A count larger than the bytes left is an error. Before, a large count made Vec::with_capacity panic.
    • How deep a type nests. A type deeper than 256 is an error. Before, a deep type overflowed the stack.
  • The new read_interface_file decodes the whole file when an import or --link-interface finds it. A broken file gives this error:

    <file> is not a valid module interface: <reason>. Remove the file, or write it again with `vxc --emit-interface`
    

Tests

  • a_broken_file_is_an_error in src/metadata.rs: an empty file, a header count or a body count that is too large, and a deep type (100,000 levels).
  • tests/frontend/fail/a_broken_vxlib_file_is_an_error_that_names_it.vx: an empty file, a cut file, a file with the wrong version stamp, a plain text file, and a whole file that runs.
  • Each check was broken once on purpose, and the expected check failed.
  • The agent also cut a valid file at every length and changed each of its 362 bytes in turn. vxc never panicked.

The pre-commit hook passed on the top of the stack: #4619, this PR and #4624 on main.

Not covered

The decoder checks the format of a file, not that each function body in it is well formed. A body with a changed byte can still make vxc panic later. See #4622.

Fixes #4600

vxc reads a .vxlib in place of the .vx file beside it. An empty .vxlib
made vxc panic in gid.rs, because the decoder sliced the file without
checking its length. Now the decoder checks each read: the header, each
count, and how deep a type nests. vxc decodes the whole file when an
import or --link-interface finds it. So an empty, cut, stale or garbled
file is an error that names the file and says to remove or rewrite it.

Fixes: #4600

This branch has not been deployed

No deployments
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.

1 participant