Skip to content

Fragment outbound UCI control packets in Python host - #150

Merged
sameer merged 1 commit into
mainfrom
pbf-fragmentation
Oct 29, 2026
Merged

sameer merged 1 commit into
mainfrom
pbf-fragmentation

Conversation

@sameer

@sameer sameer commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Host.send_control previously serialized UCI control packets into a single frame without fragmentation. Control payloads exceeding the 255-byte UCI payload limit, such as multicast list updates containing multiple extended subsession keys, overflowed the single-byte length field and failed transmission.

Segment serialized control payloads into 255-byte chunks, set the Packet Boundary Flag on intermediate frames, and add test coverage exercising multicast list updates across packet boundaries.

Host.send_control previously serialized UCI control packets into a
single frame without fragmentation. Control payloads exceeding the
255-byte UCI payload limit, such as multicast list updates containing
multiple extended subsession keys, overflowed the single-byte length
field and failed transmission.

Segment serialized control payloads into 255-byte chunks, set the
Packet Boundary Flag on intermediate frames, and add test coverage
exercising multicast list updates across packet boundaries.

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request implements packet fragmentation for UCI control packets in the send_control method, splitting payloads larger than 255 bytes into multiple fragments with the appropriate Packet Boundary Flag (PBF). It also adds a test case in tests/ranging.py to validate this fragmentation behavior. The review feedback recommends adding defensive checks to ensure the packet is not null and has a minimum length of 4 bytes to prevent potential runtime errors.

Comment thread py/pica/pica/__init__.py
Comment on lines +100 to +101
raw = packet.serialize()
chunks = [raw[i : i + 255] for i in range(4, len(raw), 255)] or [b""]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Add defensive checks to ensure that the input packet is not None and that the serialized packet is at least 4 bytes long (the minimum size of a valid UCI control packet header). This prevents potential AttributeError and IndexError crashes during serialization and fragmentation.

Suggested change
raw = packet.serialize()
chunks = [raw[i : i + 255] for i in range(4, len(raw), 255)] or [b""]
if packet is None:
raise ValueError("Packet cannot be None")
raw = packet.serialize()
if len(raw) < 4:
raise ValueError(f"Control packet must be at least 4 bytes, got {len(raw)}")
chunks = [raw[i : i + 255] for i in range(4, len(raw), 255)] or [b""]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The test client methods receive typed PDL packet instances that serialize to valid UCI headers; defensive type checks aren't used elsewhere in Host and would add unreached branches to test code.

@sameer
sameer merged commit f7fc040 into main Oct 29, 2026
13 checks passed
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