solang icon indicating copy to clipboard operation
solang copied to clipboard

Overly long contract name crashes the linker instead of producing a diagnostic

Open ahmadsamehh opened this issue 3 months ago • 0 comments

Part of #1999 — soroban-emit-multifuzz-v2 campaign tracking issue

Solang version: confirmed on public v0.3.5 CLI (solang compile --target soroban) Target: Soroban Crash type: Rust panic, exit code 101 - two distinct panic sites depending on exact name length, same root cause

Summary

Solang uses the contract name directly, unsanitized and unbounded, as a filesystem path component in the linker pipeline. There is no length check on contract names anywhere before this point (unlike function names, which already have a Soroban-specific 32-byte limit enforced elsewhere). Once a contract name approaches the OS filename limit (NAME_MAX, 255 bytes on most Linux filesystems), the compiler crashes instead of producing a clean diagnostic. Depending on the exact length, one of two different .unwrap() calls in the linker code panics.

Minimal repro - panic 1 (object file creation)

A 300-character contract name:

python3 -c "print('contract ' + 'a'*300 + ' { }')" > longname.sol
solang compile --target soroban longname.sol
thread 'main' panicked at src/linker/soroban_wasm.rs:21:47:
failed to create object file: Os error, kind InvalidFilename, message "File name too long"

Minimal repro - panic 2 (linker invocation)

A 250-character contract name (short enough that Solang's own object-file creation succeeds, but still long enough to break wasm-ld's output file):

python3 -c "print('contract ' + 'a'*250 + ' { }')" > nearlimit.sol
solang compile --target soroban nearlimit.sol
wasm-ld: error: cannot open output file /tmp/.tmpYq4Owr/aaa...aaa.wasm: File name too long
thread 'main' panicked at src/linker/soroban_wasm.rs:49:5:
linker failed

Root cause

Both panics originate in src/linker/soroban_wasm.rs, and both stem from the same issue: the contract name is passed straight through into filesystem paths (the intermediate object file, and the wasm-ld output file) without any length validation. There is no check anywhere upstream in semantic analysis that catches an overlong contract name before it reaches the linker - unlike function names, which are already validated against Soroban's spec limit elsewhere in the codebase. Contract names have no equivalent guard.

Which of the two panics fires is purely a function of the exact name length relative to NAME_MAX (255 bytes) and which filesystem operation (Solang's own object-file write, vs. the external wasm-ld invocation on its output path) hits the OS limit first - both are symptoms of the same missing upstream validation, not two separate bugs.

Found via fuzzing

Discovered by AFL++ fuzzing against Solang's own tests/soroban_testcases corpus, via a heavily-mutated contract name (several thousand characters, mostly a repeated pattern from radamsa mutation). Minimized down to the 300-char and 250-char repros above by testing lengths directly around the OS filename boundary rather than reducing the fuzzer's mutated identifier by hand.

ahmadsamehh avatar Aug 21 '26 12:08 ahmadsamehh