Skip to content

Refuse to encode payloads above the framed file cap - #1697

Open
Chessing234 wants to merge 1 commit into
permissionlesstech:mainfrom
Chessing234:fix/encode-respects-framed-file-cap
Open

Refuse to encode payloads above the framed file cap#1697
Chessing234 wants to merge 1 commit into
permissionlesstech:mainfrom
Chessing234:fix/encode-respects-framed-file-cap

Conversation

@Chessing234

@Chessing234 Chessing234 commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Test plan

  • BinaryProtocolTests oversized + framed-cap round-trip
  • Confirm encode returns nil for maxFramedFileBytes + 1

Refs #1618 #1629

Decode already drops compressed frames whose declared originalSize
exceeds FileTransferLimits.maxFramedFileBytes. Encode only checked the
wire length-field width, so v2 could emit frames every honest peer
(including ourselves) silently rejects. Mirror the decode ceiling on
encode and update the oversized-payload test.

@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: db187711ca

ℹ️ 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".

// Decode enforces FileTransferLimits.maxFramedFileBytes; encode previously only checked
// the on-wire length field width, so v2 could compress up to UInt32.max and produce
// frames peers (including ourselves) silently drop.
guard payload.count <= FileTransferLimits.maxFramedFileBytes else { return nil }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Recheck the framed limit after adding compression metadata

For a v2 payload at (or within three bytes of) maxFramedFileBytes that is only slightly compressible, this guard passes based on the original size, but encoding then adds the 4-byte original-size preamble. payloadDataSize can therefore exceed the decoder's framed cap even though the source payload did not, and decodeCore will reject the emitted frame before decompression. Validate payloadDataSize against maxFramedFileBytes after compression as well.

Useful? React with 👍 / 👎.

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.

1 participant