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.

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

671671 if len(self._segment_headerlist) >= self.max_header_count:
672672 raise ParserLimitReached("Maximum segment header count exceeded")
673673
674- # Decode headers into header name and value
674+ # Decode headerline into normalized (name, value) pairs
675675 try:
676676 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()
683677 except UnicodeDecodeError as err:
684678 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")
685685
686686 if name == "Content-Length":
687+ if self._segment_limit >= 0:
688+ raise ParserError("Multiple segment Content-Length headers")
687689 try:
688690 content_length = int(value)
689691 if content_length < 0 or str(content_length) != value:

The check that tells the two apart

failpass·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