Skip to content

Raw returndata Copied / Decoded Unsafely

SAFE-0237 External Calls Checked automatically by the scanner
1

What goes wrong

Assembly copies returndata (returndatacopy) or abi.decode is applied to a call's raw output without validating that the callee returned enough data. A short or crafted return can decode into attacker-favorable values.

2

The vulnerable pattern

proof of concept — how it is exploited
// (bool ok, bytes memory r) = t.call(data); uint v = abi.decode(r,(uint));
// malicious t returns empty -> abi.decode reads zero/garbage,
// e.g. a 'balance' of 0 that skips a require.
3

How to fix it

the pattern that is safe
(bool ok, bytes memory ret) = t.call(data);
require(ok && ret.length >= 32, "bad return");
uint256 v = abi.decode(ret, (uint256));
Check returndata length before decoding.
Check your own contract for this

The SaferICO scanner runs 201 detectors over your Solidity source, SAFE-0237 among them. Paste an address or the source itself — a small per-scan fee, shown before you sign, or unlimited on any plan.

Run the scanner See how it is attacked Read the docs