Skip to content

fix: guard CCIP-Read dataSlice against short error.data to prevent BUFFER_OVERRUN - #5176

Open
yutonakamura-dev wants to merge 1 commit into
ethers-io:mainfrom
yutonakamura-dev:fix/ccip-read-buffer-overrun
Open

fix: guard CCIP-Read dataSlice against short error.data to prevent BUFFER_OVERRUN#5176
yutonakamura-dev wants to merge 1 commit into
ethers-io:mainfrom
yutonakamura-dev:fix/ccip-read-buffer-overrun

Conversation

@yutonakamura-dev

Copy link
Copy Markdown

Problem

When a CCIP-Read enabled contract reverts with empty or short error.data (e.g. 0x), the OffchainLookup check in #call crashes with BUFFER_OVERRUN instead of propagating the original call error.

This happens because the condition on line 1034 checks error.data for truthiness — "0x" is truthy — then immediately passes it to dataSlice(error.data, 0, 4), which throws when the data is shorter than 4 bytes.

Affects any ENS offchain name lookup (e.g. .xyz domains via CCIP resolvers) where the resolver reverts without data.

Root Cause

// before
if (... && error.data && dataSlice(error.data, 0, 4) === "0x556f1830") {
//          ^^^^^^^^^^
//          "0x" is truthy, but dataSlice("0x", 0, 4) → BUFFER_OVERRUN

Fix

Add a dataLength guard before dataSlice. dataLength is already imported and used elsewhere in the file (line 1711).

// after
if (... && error.data && dataLength(error.data) >= 4 && dataSlice(error.data, 0, 4) === "0x556f1830") {

Reproduction

import { getDefaultProvider, EnsResolver } from 'ethers';

const provider = getDefaultProvider();
const resolver = new EnsResolver(provider, '0xf142b308cf687d4358410a4cb885513b30a42025', 'mnhsu.xyz');
const address = await resolver.getAddress();
// → BUFFER_OVERRUN instead of null

Closes #4982

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.

CCIP Read throws BUFFER_OVERRUN when error.data is less than 4 bytes (0x for example)

1 participant