Repository navigation
Commit beb0862
committed
gh-107862: Fix infinite loop folding a character too wide for the line
When an encoded word does not fit in the remaining space of a line,
_fold_as_ew shrinks the chunk being encoded one character at a time
until it fits. Nothing stops it from shrinking the chunk to nothing,
and an empty chunk makes no progress: the loop appends an empty
encoded word and a new continuation line forever.
This is reachable whenever a single character's encoded form is wider
than a fresh continuation line, e.g. any character outside the BMP
with max_line_length=20 (the q-encoded word is 24 characters). The two
earlier fixes in this area (bpo-33529, bpo-36564) handled lines too
short for the RFC 2047 chrome, but not lines too short for the chrome
plus one character.
This keeps at least one character in the chunk, so the loop always
advances and the line runs over max_line_length instead. That matches
what _refold_parse_tree already does when it cannot fold a part at
all, and avoids raising for widths that work for every other input.
The regression test pins the exact output, as the earlier two did. The
Hypothesis property checks that folding any unstructured value at any
width either raises HeaderParseError (only possible at widths of 13 or
fewer, where no encoded word fits) or reparses to the same value modulo
leading whitespace, which the parser drops.1 parent 662beae commit beb0862
3 files changed
Lines changed: 67 additions & 1 deletion
File tree
- Lib
- email
- test/test_email
- Misc/NEWS.d/next/Library
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3125 | 3125 | | |
3126 | 3126 | | |
3127 | 3127 | | |
3128 | | - | |
| 3128 | + | |
3129 | 3129 | | |
3130 | 3130 | | |
3131 | 3131 | | |
3132 | 3132 | | |
3133 | 3133 | | |
| 3134 | + | |
| 3135 | + | |
| 3136 | + | |
3134 | 3137 | | |
3135 | 3138 | | |
3136 | 3139 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
295 | 296 | | |
296 | 297 | | |
297 | 298 | | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
298 | 358 | | |
299 | 359 | | |
300 | 360 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
0 commit comments