THRIFT-6148: Enforce complete Ruby Header frame limits - #3712
Merged
Conversation
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a mismatch in Ruby HeaderTransport frame size enforcement by validating max_frame_size against the fully constructed Header frame (post-transforms, metadata, and padding), aligning write-side behavior with what the reader enforces on the declared on-wire frame size (excluding the 4-byte length prefix).
Changes:
- Validate Header-format frame size after header construction/transforms and before writing bytes, so writers and readers with the same
max_frame_sizeagree. - Centralize size checking via
validate_frame_size!and apply it consistently to framed/unframed compatibility write paths. - Expand Ruby specs to cover complete-frame accounting, metadata/padding inclusion, transform effects, and header preservation across rejected flushes.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/rb/lib/thrift/transport/header_transport.rb | Moves size validation to occur after Header frame construction; adds validate_frame_size! and uses it for legacy framed/unframed write paths. |
| lib/rb/spec/header_transport_spec.rb | Adds targeted tests to ensure the limit applies to the complete Header frame (including transforms/metadata/padding) and verifies retry behavior after local validation failures. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ruby
HeaderTransportcurrently appliesmax_frame_sizeto the payload before constructing the Header frame. The reader applies the same limit to the complete size declared on the wire, which also includes the fixed Header envelope, transformed payload, metadata, and padding. A writer can therefore emit a frame that a reader configured with the identical limit rejects.This change validates the completed declared Header frame after transforms and header construction, before writing any bytes. The four-byte length prefix remains excluded, matching the read-side contract; each Header field and payload byte is counted exactly once. Framed and unframed Binary/Compact compatibility modes keep their existing accounting. Pending one-shot headers also remain available when this local validation rejects a frame before delivery.
Benchmarks
The repository Header write benchmark ran 10,000 small-structure writes per scenario for six trials, with the first trial discarded as warm-up:
Pure-Ruby controls used the identical command with
THRIFT_BENCHMARK_SKIP_NATIVE=1. Current master and the proposed change used the same Ruby container and rebuilt native extension. Times are median seconds, with the measured five-trial range in parentheses.All before-and-after ranges overlap; the results show no meaningful performance change.
[skip ci]anywhere in the commit message to free up build resources.