The legacy email.utils.parseaddr function in Python through 3.11.4 allows attackers to trigger "RecursionError: maximum recursion depth exceeded while calling a Python object" via a crafted argument. This argument is plausibly an untrusted value from an application's input data that was supposed to contain a name and an e-mail address. NOTE: email.utils.parseaddr is categorized as a Legacy API in the documentation of the Python email package. Applications should instead use the email.parser.BytesParser or email.parser.Parser class. NOTE: the vendor's perspective is that this is neither a vulnerability nor a bug. The email package is intended to have size limits and to throw an exception when limits are exceeded; they were exceeded by the example demonstration code.
# Bug report

We did a fuzzing test on Python3.9.15, a recursion error happened.

```python
from email.utils import *
import email
import email.utils
import re

class demoCls():

    def __init__(self):
        pass

    def demoFunc(self, arg):
        try:
            ret = email.utils.parseaddr(arg)
        except (AttributeError, LookupError, OSError, TypeError, UnicodeEncodeError, ValueError):
            pass

with open("data.txt","r") as f:
    addr = f.readline()
    dc = demoCls()
    dc.demoFunc(addr)
```
[code](https://github.com/baltsers/fuzzVuls/blob/master/Python3.9.15/email.utils.parseaddr/1%23email%23utils%23parseaddr.py)

The input value:
```
%uselayQWexQeGM4R:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqz
```
[input](https://github.com/baltsers/fuzzVuls/blob/master/Python3.9.15/email.utils.parseaddr/data.txt)

## Bug info
```pytb
Traceback (most recent call last):
  File "/root/fuzzVuls/Python3.9.15/email.utils.parseaddr/1#email#utils#parseaddr.py", line 20, in <module>
    dc.demoFunc(addr)
  File "/root/fuzzVuls/Python3.9.15/email.utils.parseaddr/1#email#utils#parseaddr.py", line 13, in demoFunc
    ret = email.utils.parseaddr(arg)
  File "/root/anaconda3/lib/python3.9/email/utils.py", line 212, in parseaddr
    addrs = _AddressList(addr).addresslist
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 513, in __init__
    self.addresslist = self.getaddrlist()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 257, in getaddrlist
    ad = self.getaddress()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 300, in getaddress
    returnlist = returnlist + self.getaddress()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 300, in getaddress
    returnlist = returnlist + self.getaddress()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 300, in getaddress
    returnlist = returnlist + self.getaddress()
  [Previous line repeated 989 more times]
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 267, in getaddress
    self.gotonext()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 239, in gotonext
    while self.pos < len(self.field):
RecursionError: maximum recursion depth exceeded while calling a Python object

```

# My environment

CPython: 3.9.15
Ubuntu: 18.0.4 (x86 64)



RecursionError in email.utils.parseaddr
This is a GitHub Issue
repo:cpython
owner:python
Title : RecursionError in email.utils.parseaddr
Issue date:

--- start body ---
# Bug report

We did a fuzzing test on Python3.9.15, a recursion error happened.

```python
from email.utils import *
import email
import email.utils
import re

class demoCls():

    def __init__(self):
        pass

    def demoFunc(self, arg):
        try:
            ret = email.utils.parseaddr(arg)
        except (AttributeError, LookupError, OSError, TypeError, UnicodeEncodeError, ValueError):
            pass

with open("data.txt","r") as f:
    addr = f.readline()
    dc = demoCls()
    dc.demoFunc(addr)
```
[code](https://github.com/baltsers/fuzzVuls/blob/master/Python3.9.15/email.utils.parseaddr/1%23email%23utils%23parseaddr.py)

The input value:
```
%uselayQWexQeGM4R:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqzE7C4::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::E7C4:::::::::::::::::::::::::::::set::::::::::::::::::::::::::::::::::::::::::::::_threshold2qR)phqz
```
[input](https://github.com/baltsers/fuzzVuls/blob/master/Python3.9.15/email.utils.parseaddr/data.txt)

## Bug info
```pytb
Traceback (most recent call last):
  File "/root/fuzzVuls/Python3.9.15/email.utils.parseaddr/1#email#utils#parseaddr.py", line 20, in <module>
    dc.demoFunc(addr)
  File "/root/fuzzVuls/Python3.9.15/email.utils.parseaddr/1#email#utils#parseaddr.py", line 13, in demoFunc
    ret = email.utils.parseaddr(arg)
  File "/root/anaconda3/lib/python3.9/email/utils.py", line 212, in parseaddr
    addrs = _AddressList(addr).addresslist
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 513, in __init__
    self.addresslist = self.getaddrlist()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 257, in getaddrlist
    ad = self.getaddress()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 300, in getaddress
    returnlist = returnlist + self.getaddress()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 300, in getaddress
    returnlist = returnlist + self.getaddress()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 300, in getaddress
    returnlist = returnlist + self.getaddress()
  [Previous line repeated 989 more times]
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 267, in getaddress
    self.gotonext()
  File "/root/anaconda3/lib/python3.9/email/_parseaddr.py", line 239, in gotonext
    while self.pos < len(self.field):
RecursionError: maximum recursion depth exceeded while calling a Python object

```

# My environment

CPython: 3.9.15
Ubuntu: 18.0.4 (x86 64)



--- end body ---
