Commit b35bea9
committed
fix: bound DNS compression-pointer chain depth in DNSIncoming
A crafted mDNS packet can pack thousands of forward compression
pointers into a single ~3kB datagram. _decode_labels_at_offset
recurses once per pointer it follows, so a deep chain blows
through CPython's default recursion limit. RecursionError was
not in DECODE_EXCEPTIONS, so it escaped DNSIncoming.__init__
and bubbled up to asyncio's exception handler — turning a single
packet into a CPU-burn and debug-log flood from any host on the
local link.
Cap the chain at MAX_DNS_LABELS (the existing 128-label cap from
RFC 6762 §16 / RFC 1035 §3.1) by threading an explicit depth
counter through _decode_labels_at_offset and raising
IncomingDecodeError when exceeded. As belt-and-braces, add
RecursionError to DECODE_EXCEPTIONS so any future regression is
contained as an invalid packet rather than logged by asyncio.
Closes #17131 parent 64d143d commit b35bea9
3 files changed
Lines changed: 33 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
86 | | - | |
| 86 | + | |
87 | 87 | | |
88 | 88 | | |
89 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
60 | 60 | | |
61 | 61 | | |
62 | 62 | | |
63 | | - | |
| 63 | + | |
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
| |||
409 | 409 | | |
410 | 410 | | |
411 | 411 | | |
412 | | - | |
| 412 | + | |
413 | 413 | | |
414 | 414 | | |
415 | 415 | | |
| |||
418 | 418 | | |
419 | 419 | | |
420 | 420 | | |
421 | | - | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
422 | 424 | | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
423 | 429 | | |
424 | 430 | | |
425 | 431 | | |
| |||
457 | 463 | | |
458 | 464 | | |
459 | 465 | | |
460 | | - | |
| 466 | + | |
461 | 467 | | |
462 | 468 | | |
463 | 469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1011 | 1011 | | |
1012 | 1012 | | |
1013 | 1013 | | |
| 1014 | + | |
| 1015 | + | |
| 1016 | + | |
| 1017 | + | |
| 1018 | + | |
| 1019 | + | |
| 1020 | + | |
| 1021 | + | |
| 1022 | + | |
| 1023 | + | |
| 1024 | + | |
| 1025 | + | |
| 1026 | + | |
| 1027 | + | |
| 1028 | + | |
| 1029 | + | |
| 1030 | + | |
| 1031 | + | |
| 1032 | + | |
| 1033 | + | |
| 1034 | + | |
| 1035 | + | |
1014 | 1036 | | |
1015 | 1037 | | |
1016 | 1038 | | |
| |||
0 commit comments