Whole file
defnull/multipart
The author described this change as “fix: Properly handle completely empty input stream.”. It counts as a record because the check below fails on the code as it stood at 0be4b9ba1 and passes on 8039d663b, with nothing else changed between the two runs.
Projectdefnull/multipart
Fix saved2024-08-26
Sharing licenceMIT · LICENSE
Change size+6 −8
What the code was meant to do, written into the code itself as a save note
fix: Properly handle completely empty input stream.
The change
| 250 | 250 | data = read(maxbuf if maxread < 0 else min(maxbuf, maxread)) | |
| 251 | 251 | maxread -= len(data) | |
| 252 | 252 | lines = (buffer + data).splitlines(True) | |
| 253 | - | len_first_line = len(lines[0]) | |
| 254 | 253 | ||
| 255 | - | # be sure that the first line does not become too big | |
| 256 | - | if len_first_line > self.buffer_size: | |
| 254 | + | # make sure that the first line does not exceed buffer_size | |
| 255 | + | if lines and len(lines[0]) > self.buffer_size: | |
| 256 | + | split = self.buffer_size | |
| 257 | 257 | # at the same time don't split a '\r\n' accidentally | |
| 258 | - | if len_first_line == self.buffer_size + 1 and lines[0].endswith(b"\r\n"): | |
| 259 | - | splitpos = self.buffer_size - 1 | |
| 260 | - | else: | |
| 261 | - | splitpos = self.buffer_size | |
| 262 | - | lines[:1] = [lines[0][:splitpos], lines[0][splitpos:]] | |
| 258 | + | if len(lines[0]) == split + 1 and lines[0].endswith(b"\r\n"): | |
| 259 | + | split -= 1 | |
| 260 | + | lines[:1] = [lines[0][:split], lines[0][split:]] | |
| 263 | 261 | ||
| 264 | 262 | if data: | |
| 265 | 263 | buffer = lines[-1] |
The check that tells the two apart
fail→pass·test/test_multipart.py::TestBrokenMultipart::test_empty
Check file test/test_multipart.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 it0be4b9ba11c88d9f51115932dcb975feb15deb15
Broken version dated2024-08-26
Modulemultipart
Units changedMultipartParser
Fingerprint5001424f6ca838ff
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-07-26fix: Hardened header parsing.
- 2025-01-21MultipartPart
- 2024-09-28fix: Allow empty segment names
- 2024-08-26parse_form_data