IndexError in DateTimeParser.parse
- Dominant language
- Python
- Stars
- 9.1k
- Forks
- 784
- PR merge metrics
- No merged PRs in 30d
Description
The below code triggers a list index out of range error when provided a malformed input. This occurs in `parse` at line 335 in arrow/parser.py.
It seems that when the fmt string is malformed this can lead to a matching error in the regex parsing later in the function.
```
from arrow.parser import DateTimeParser
import sys
buf = open(sys.argv[1], "rb").read().decode("utf-8")
parser = DateTimeParser()
parser.parse("foo", buf)
```
### Version
1.3.0
### POC File
https://github.com/FuturesLab/POC/blob/main/arrow-py/poc-01
### How to trigger
python filename.py poc-01
### Trace Report
```
Traceback (most recent call last):
File "rep.py", line 6, in
parser.parse("foo", buf)
File "anon/lib/python3.8/site-packages/arrow/parser.py", line 331, in parse
value = match.group(token)
IndexError: no such group
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the failure with the DateTimeParser example in the issue and inspect arrow/parser.py around parse line 335, where match.group(token) raises IndexError. Compare the malformed fmt and regex match behavior, then verify that the reported input no longer produces this exception and that the resulting behavior is covered by the parser tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100