Skip to content

fix(abi): limit decoded bytes and string size - #5483

Merged
jxom merged 6 commits into
mainfrom
fix/abi-decode-size-limit
Nov 11, 2026
Merged

jxom merged 6 commits into
mainfrom
fix/abi-decode-size-limit

Conversation

@jxom

@jxom jxom commented Nov 11, 2026

Copy link
Copy Markdown
Member

decodeAbiParameters now limits the total size of decoded bytes and string values to 32 times the input size, and throws AbiDecodingSizeLimitExceededError beyond it. Ordinary inputs, including offsets that share a tail, decode as before.

@changeset-bot

changeset-bot Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 995944e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
viem Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@vercel

vercel Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
viem Error Error Nov 11, 2026 4:57am UTC

Request Review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T04:55:18.008194Z 995944e New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e777b3db6e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/errors/abi.ts Outdated
AbiDecodingSizeLimitExceededError & {
name: 'AbiDecodingSizeLimitExceededError'
}
export class AbiDecodingSizeLimitExceededError extends BaseError {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Export the new decoding error from the package entrypoint

When consumers need to handle the newly introduced size-limit failure, they cannot import AbiDecodingSizeLimitExceededError from viem to use instanceof or BaseError.walk. Repository-wide search shows the class is only exported from this internal module, while src/index.ts explicitly re-exports the other ABI errors and src/package.json does not expose an errors subpath. Re-export the class and its error type from src/index.ts so this new public failure can be handled consistently with existing decoding errors.

AGENTS.md reference: AGENTS.md:L92-L92

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exported AbiDecodingSizeLimitExceededError and its type from viem and listed it in the errors glossary in e99e268.

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Published [email protected] under the pr-5483 dist-tag, which follows this pull request until it closes.

pnpm add viem@pr-5483
pnpm add [email protected]

@jxom
jxom force-pushed the fix/abi-decode-size-limit branch from 8a95bc0 to 90adea7 Compare November 11, 2026 04:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 90adea70e7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/errors/abi.ts Outdated
Comment on lines +103 to +104
export class AbiDecodingSizeLimitExceededError extends BaseError {
constructor({ limit }: { limit: number }) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Keep the new decoding error in its owning module

The new error is specific to decodeAbiParameters, but its implementation is added to the shared error module. AGENTS.md explicitly requires module-specific failure classes to live near the bottom of the module that throws them. Move this class and its associated type into decodeAbiParameters.ts and update the entrypoint re-exports accordingly.

AGENTS.md reference: AGENTS.md:L29-L31

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved AbiDecodingSizeLimitExceededError and its type to the bottom of decodeAbiParameters.ts and re-exported them from viem alongside decodeAbiParameters in 995944e.

Comment thread src/index.ts Outdated
Comment on lines +813 to +814
AbiDecodingSizeLimitExceededError,
type AbiDecodingSizeLimitExceededErrorType,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the newly exported size-limit error

The new class and error type are now exported, but neither has TSDoc explaining the failure condition, and the entrypoint additions contain no documentation block. The glossary addition only lists the name, leaving consumers without API documentation for when the new exception is raised. Add the required TSDoc describing the cumulative decoded-size limit; AGENTS.md explicitly requires a TSDoc block when adding a public export.

AGENTS.md reference: AGENTS.md:L92-L92

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added TSDoc to the class and its type describing when it is thrown (decoded bytes and string values exceeding 32 times the input size) in 995944e.

import { getAddress } from '../address/getAddress.js'
import { size } from '../data/size.js'
import { hexToBytes } from '../encoding/toBytes.js'
import { numberToHex, stringToHex } from '../encoding/toHex.js'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Import the new public test helpers through the package entrypoint

The new tests import numberToHex and stringToHex directly from their implementation module even though both are public exports of viem. This bypasses the package surface and violates the explicit test-import convention in AGENTS.md. Import these helpers from 'viem' rather than adding new relative imports for public APIs.

AGENTS.md reference: AGENTS.md:L188-L192

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests now import numberToHex, size and stringToHex from viem in 995944e.

@jxom
jxom merged commit 78060db into main Nov 11, 2026
39 of 40 checks passed
@jxom
jxom deleted the fix/abi-decode-size-limit branch November 11, 2026 05:12
@github-actions github-actions Bot mentioned this pull request Nov 11, 2026

This branch had an error being deployed

1 failed deployment
Preview — 995944e7 Deployed Nov 11, 2026 by vercel[bot]
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.

2 participants