Skip to content

fix(dyn-abi): handle short data in decode_error without panicking - #1084

Merged
zerosnacks merged 6 commits into
mainfrom
zerosnacks/fix-decode-error-panic-short-data
Mar 17, 2026
Merged

zerosnacks merged 6 commits into
mainfrom
zerosnacks/fix-decode-error-panic-short-data

Conversation

@decofe

@decofe decofe commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

Summary

DynSolError::decode_error panics when called with data shorter than 4 bytes.

Motivation

The SelectorMismatch error branch unconditionally slices data[0..4] to extract the actual selector, but data may be shorter than 4 bytes (or empty). This causes a panic: range end index 4 out of range for slice of length 0.

Discovered via foundry-rs/foundry#13766 where vm.expectRevert(bytes("")) triggers this panic.

Changes

  • Zero-pad short data when constructing the SelectorMismatch error instead of panicking
  • Added test for empty and short data inputs

Testing

cargo test -p alloy-dyn-abi -- dynamic::error

All 3 tests pass (including the new decode_error_short_data test).

Co-Authored-By: zerosnacks [email protected]

Prompted by: zerosnacks

decofe and others added 5 commits March 16, 2026 07:43
The likely_unlikely feature was stabilized under core_intrinsics,
which is already declared. The separate feature gate is no longer
needed and causes a clippy error on newer nightly.

Co-Authored-By: zerosnacks <[email protected]>
Co-Authored-By: zerosnacks <[email protected]>
decode_error panicked with 'range end index 4 out of range for slice
of length 0' when called with data shorter than 4 bytes, because the
SelectorMismatch error branch unconditionally sliced data[0..4].

Zero-pad short data instead of panicking.

Co-Authored-By: zerosnacks <[email protected]>
Co-Authored-By: zerosnacks <[email protected]>
@decofe
decofe force-pushed the zerosnacks/fix-decode-error-panic-short-data branch from 32d14f6 to 299d4c0 Compare March 16, 2026 08:16
@zerosnacks
zerosnacks changed the base branch from main to zerosnacks/fix-unused-likely-unlikely-feature March 16, 2026 08:29
@zerosnacks
zerosnacks marked this pull request as ready for review March 16, 2026 08:29
Base automatically changed from zerosnacks/fix-unused-likely-unlikely-feature to main March 16, 2026 11:11
@github-project-automation github-project-automation Bot moved this to Done in Alloy Mar 17, 2026
@zerosnacks zerosnacks reopened this Mar 17, 2026
@github-project-automation github-project-automation Bot moved this from Done to In Progress in Alloy Mar 17, 2026
@github-project-automation github-project-automation Bot moved this from In Progress to Reviewed in Alloy Mar 17, 2026
@zerosnacks
zerosnacks merged commit 9888870 into main Mar 17, 2026
62 checks passed
@zerosnacks
zerosnacks deleted the zerosnacks/fix-decode-error-panic-short-data branch March 17, 2026 13:26
@github-project-automation github-project-automation Bot moved this from Reviewed to Done in Alloy Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants