THRIFT-6140: Reject malformed short JSON UUID values - #3704
Conversation
Client: rb Co-Authored-By: OpenAI Codex (GPT-5.6) <codex@openai.com>
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR fixes Ruby JsonProtocol#read_uuid behavior so that complete-but-malformed short UUID strings are rejected as Thrift::ProtocolException::INVALID_DATA (instead of incorrectly surfacing as EOFError), allowing SimpleServer to close just the bad connection and continue serving.
Changes:
- Remove the
EOFErrorlength check fromJsonProtocol#read_uuidand rely on UUID validation to classify malformed values asINVALID_DATA. - Restructure/expand UUID validation specs to distinguish fixed-width protocol truncation (
EOFError) from JSON malformed-vs-truncated behavior. - Extend server specs to include a malformed short JSON UUID request to ensure the server loop continues after rejecting it.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/rb/lib/thrift/protocol/json_protocol.rb | Removes the short-UUID EOFError guard so malformed complete UUID strings are handled as protocol invalid data. |
| lib/rb/spec/uuid_validation_spec.rb | Refactors protocol grouping and adds targeted specs for fixed-width truncation and JSON malformed/truncated UUID cases. |
| lib/rb/spec/server_spec.rb | Adds a regression test case ensuring malformed short JSON UUID requests don’t stop the server loop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Ruby JSONProtocol raised
EOFErrorafter reading a complete UUID string shorter than 36 characters. Unlike an actual truncated transport value, this represented malformed protocol data, so the exception escaped SimpleServer's per-connection Thrift exception boundary and stopped the serving loop.This change lets the existing UUID validator classify complete malformed UUID strings as
ProtocolException::INVALID_DATA. SimpleServer can then reject the malformed connection and continue accepting clients. Actual truncated JSON input retains its existingEOFErrorbehavior, and valid UUID values continue to round-trip.Benchmarks
Ruby 4.0.6, pure-Ruby implementation, 200,000 valid JSON UUID decodes per trial, seven trials:
ruby -Ilib -rthrift -e 'payload = %q("550e8400-e29b-41d4-a716-446655440000"); iterations = 200000; times = 7.times.map do; GC.start; started = Process.clock_gettime(Process::CLOCK_MONOTONIC); iterations.times { Thrift::JsonProtocol.new(Thrift::MemoryBufferTransport.new(payload.dup)).read_uuid }; Process.clock_gettime(Process::CLOCK_MONOTONIC) - started; end; sorted = times.sort; puts sorted[times.length / 2]'a9663bc6661a5dd1d99d629e1f269c1907592a1aThe microbenchmark includes transport and protocol object allocation, so small deltas should be treated as noise. It shows no regression in the valid-UUID path.
[skip ci]anywhere in the commit message to free up build resources.