Commit be6f136
committed
Fix infinite loop in email.message.EmailMessage.as_string() with long parameter keys
The infinite loop occurred in _fold_mime_parameters() when processing MIME parameters
with very long keys (64 characters) during RFC 2231 encoding.
Changes made:
1. In email._header_value_parser._fold_mime_parameters():
- Replace infinite 'while True:' loop with 'while splitpoint > 1:'
- Ensure splitpoint is always at least 1 to prevent getting stuck
- Add fallback logic to force minimal splits when values cannot fit
2. In email.header._append_chunk():
- Add comment explaining handling of extremely long strings that can't be split
This fixes GitHub issue #138223 where add_attachment() with long parameter
keys would cause as_string() to hang indefinitely during MIME parameter
folding and header processing.1 parent 0a747e5 commit be6f136
2 files changed
+7
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3081 | 3081 | | |
3082 | 3082 | | |
3083 | 3083 | | |
3084 | | - | |
| 3084 | + | |
| 3085 | + | |
3085 | 3086 | | |
3086 | 3087 | | |
3087 | 3088 | | |
3088 | 3089 | | |
3089 | 3090 | | |
3090 | 3091 | | |
| 3092 | + | |
| 3093 | + | |
| 3094 | + | |
3091 | 3095 | | |
3092 | 3096 | | |
3093 | 3097 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
527 | 527 | | |
528 | 528 | | |
529 | 529 | | |
| 530 | + | |
| 531 | + | |
530 | 532 | | |
531 | 533 | | |
532 | 534 | | |
| |||
0 commit comments