Whole file
defnull/multipart
The author described this change as “fix: Hardened header parsing.”. It counts as a record because the check below fails on the code as it stood at 90a72973f and passes on a6cdc6d4a, with nothing else changed between the two runs.
Projectdefnull/multipart
Fix saved2025-07-26
Sharing licenceMIT · LICENSE
Change size+9 −7
What the code was meant to do, written into the code itself as a save note
fix: Hardened header parsing.
The change
| 671 | 671 | if len(self._segment_headerlist) >= self.max_header_count: | |
| 672 | 672 | raise ParserLimitReached("Maximum segment header count exceeded") | |
| 673 | 673 | ||
| 674 | - | # Decode headers into header name and value | |
| 674 | + | # Decode headerline into normalized (name, value) pairs | |
| 675 | 675 | try: | |
| 676 | 676 | name, col, value = line.decode(self.header_charset).partition(":") | |
| 677 | - | name = name.strip().title() | |
| 678 | - | if not col or not name: | |
| 679 | - | raise ParserError("Malformed segment header") | |
| 680 | - | if not (name in _KNOWN_HEADERS or _re_hname.fullmatch(name)): | |
| 681 | - | raise ParserError("Invalid segment header name") | |
| 682 | - | value = value.strip() | |
| 683 | 677 | except UnicodeDecodeError as err: | |
| 684 | 678 | raise ParserError("Segment header failed to decode", err) | |
| 679 | + | if not col: | |
| 680 | + | raise ParserError("Malformed segment header") | |
| 681 | + | name = name.strip().title() | |
| 682 | + | value = value.strip() | |
| 683 | + | if not (name in _KNOWN_HEADERS or _re_hname.fullmatch(name)): | |
| 684 | + | raise ParserError("Invalid segment header name") | |
| 685 | 685 | ||
| 686 | 686 | if name == "Content-Length": | |
| 687 | + | if self._segment_limit >= 0: | |
| 688 | + | raise ParserError("Multiple segment Content-Length headers") | |
| 687 | 689 | try: | |
| 688 | 690 | content_length = int(value) | |
| 689 | 691 | if content_length < 0 or str(content_length) != value: |
The check that tells the two apart
fail→pass·test/test_push_parser.py::TestPushParser::test_header_empty_name
Check file test/test_push_parser.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before it90a72973f179c3b327007e4c8ca6b955d8739b57
Broken version dated2025-07-26
Modulemultipart
Units changedPushMultipartParser
Fingerprint89ee7ed6e1d9f09c
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.
Other bugs found in defnull/multipart
- 2026-03-09change: Raise ParserStateError on invalid boundaries.
- 2025-01-21MultipartPart
- 2024-09-28fix: Allow empty segment names
- 2024-08-26parse_form_data
- 2024-08-26fix: Properly handle completely empty input stream.