rust-lang / rust-lang/rust

zkVM args and env length can overflow

Open Beginner friendly
#158,016 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug needs-triage O-risc0
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

A large byte length can overflow to zero and still be used as the slice length.

That's targeting riscv32im-risc0-zkvm-elf where the implementations of std::env::args_os() and std::env::var_os() trust the host length. The code can allocate zero words and then build a huge
slice from that pointer.

Ideally we should panic instead of overflowing to avoid any huge allocation

https://github.com/rust-lang/rust/blob/98594f404ee741f97fefbae4aca049cde911bc94/library/std/src/sys/env/zkvm.rs#L18-L19

https://github.com/rust-lang/rust/blob/98594f404ee741f97fefbae4aca049cde911bc94/library/std/src/sys/args/zkvm.rs#L19

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading library/std/src/sys/env/zkvm.rs and library/std/src/sys/args/zkvm.rs at the referenced length-handling lines. Trace how the host-provided lengths become allocations and slices, then verify that oversized lengths no longer wrap and instead cause a panic without a huge allocation.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.