Skip to content

Correct padded HEADERS length and reject padding over fixed fields - #170

Open
vitalivo wants to merge 1 commit into
python-hyper:masterfrom
vitalivo:fix/padded-header-lengths
Open

vitalivo wants to merge 1 commit into
python-hyper:masterfrom
vitalivo:fix/padded-header-lengths

Conversation

@vitalivo

Copy link
Copy Markdown

Parsing a padded HEADERS frame drops the pad-length byte from body_len. This also rejects a valid frame containing only padding and an empty header block. Separately, HEADERS with PRIORITY and PUSH_PROMISE can accept padding that overlaps their fixed fields.

Keep the full HEADERS body length and compare padding against the bytes available after the fixed fields. Regression cases cover zero/nonzero padding, empty/nonempty header blocks, both priority modes, and overlapping fixed fields in both frame types.

All 14 regression cases fail before the fix. Full Python 3.12 suite: 162 passed, 100% branch coverage. Ruff and strict mypy pass. Includes a changelog entry.

Comment thread src/hyperframe/frame.py
raise InvalidDataError(msg)

if self.pad_length and self.pad_length >= self.body_len:
if self.pad_length > self.body_len - padding_data_length - 4:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

please add a comment to explain the origin of the -4 in this calculation.

@adenzhou1350

Copy link
Copy Markdown

Independently checked 726cc56 against its parent 632e309 on Linux / CPython 3.12. The same 22 stdlib unittest cases use the complete source modules: your 12 padded-HEADERS and two fixed-field-overlap cases, plus eight unchanged DATA/unpadded controls. The parent has eight passes, 12 assertion failures and two InvalidPaddingError exceptions on valid empty fragments; this head passes all 22.

Source hashes stayed unchanged and both isolated runs cleaned up. This is scoped independent validation, not a rerun of the full upstream suite, external fixture corpus or CI. AI assistance was used to prepare the checks; I reviewed the source and results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants