fix(sdk-python): cap wire-controlled frame lengths before allocation (PILOT-103)#3
Merged
Merged
Conversation
…(PILOT-103) SDK read data-exchange ACK payloads and event-stream topic/payload frames using wire-controlled lengths (struct.unpack from remote bytes) without any size cap. A malicious peer could advertise a 4 GiB length and force the SDK to attempt a single huge allocation, causing memory exhaustion and OOM kill on the host process. Add MAX_PAYLOAD_SIZE (1 MiB) and MAX_TOPIC_SIZE (4 KiB) guards: - send_data / send_file: if ack_len > 1 MiB, skip ack and return - read_event: if topic_len > 4 KiB or payload_len > 1 MiB, return None (treated identically to an incomplete read — benign) All 204 existing tests pass; 3 new cap constant tests added. Closes PILOT-103
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Collaborator
Author
|
📊 PR Status Report
Note: codecov/patch failure on sdk-python #3 — the uncovered lines are the new early-return guards for oversized frames (only hit with malicious peers). This is expected and matches what the PR body describes. |
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.
What failed
pilotprotocol/client.pyreads data-exchange ACK payloads (conn.read(ack_len)) and event-stream topic/payload frames (conn.read(topic_len),conn.read(payload_len)) using wire-controlled lengths parsed from remote bytes without any size cap. A malicious or buggy peer can advertise a 4 GiB length and force the SDK to attempt a single huge allocation → memory exhaustion / OOM kill DoS on the host process.What was changed
Added
MAX_PAYLOAD_SIZE = 1_048_576(1 MiB) andMAX_TOPIC_SIZE = 4_096(4 KiB) constants. Before eachconn.read(N)where N comes from the wire:ack_len > 1 MiB, skip the ACK read and return the basic result (same as a failed/incomplete ACK read today — already handled by the caller)topic_len > 4 KiBorpayload_len > 1 MiB, returnNone(treated identically to an incomplete read — benign)Verification
go build ./...: ✅Closes PILOT-103