Repository navigation
Conversation
|
|
||
| if self.body_len > FRAME_MAX_ALLOWED_LEN: | ||
| msg = f"Frame body exceeds maximum allowed length: {self.body_len} > {FRAME_MAX_ALLOWED_LEN}" | ||
| raise InvalidFrameError(msg) |
There was a problem hiding this comment.
Raising here already, will put us in a tough spot over at https://github.com/python-hyper/h2/blob/2e4d22303af8710642f2f493c103860855710f02/src/h2/connection.py#L423-L424
At runtime, this sits on the hot path, so ideally, we only check /assert / validate the frame length only once. Do you have any suggestions how to unify this? Maybe pass in the currently negotiated max frame size from the connection into, e.g., Frame.serialize(max_size: int = FRAME_MAX_ALLOWED_LEN) ?
There was a problem hiding this comment.
Passing the negotiated limit into serialize() makes sense to me. Hyperframe can check the serialized body length against that limit before emitting the header, with the 24-bit wire limit as the default and upper bound. Once h2 can depend on that API, it can pass max_outbound_frame_size and drop the post-serialize assertion. I’d cover ExtensionFrame.serialize() too so both serializers honor the same limit.
Would you prefer that API change here, or as a follow-up coordinated with h2?
Frame.serialize()currently emits a body of 16,777,216 bytes with a zero-length header because the length is truncated to 24 bits. Reject bodies aboveFRAME_MAX_ALLOWED_LENwithInvalidFrameErrorbefore building the header, while preserving the valid 16,777,215-byte boundary. The check includes padding and other serialized body overhead.Seven regression cases cover DATA and CONTINUATION maximum-size round trips, rejection at maximum plus one and plus two, and overflow caused by the PADDED length byte. Includes a changelog entry naming
Frame.serialize().ExtensionFrame.serialize()is a separate override and remains outside this patch; #169 addresses its stale body length. Peer-negotiated lower frame limits remain the caller's responsibility, and the check runs after body allocation. This is separate from the SETTINGS flag handling in #175 and header parsing tests in #173.Validation on macOS ARM64 / CPython 3.14.4: 155 tests passed, including the pinned HTTP/2 fixture collection, with 100% statement and branch coverage. Configured source Ruff, strict mypy, HTML documentation, and whitespace checks passed. Five of the seven regression cases failed against the original runtime source. Other platforms and Python versions were not run locally.
AI assistance was used for the investigation, implementation, tests, validation, and PR text.