Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect Results for Parssing Data Time #196

Open
OrianeK opened this issue May 10, 2022 · 1 comment
Open

Incorrect Results for Parssing Data Time #196

OrianeK opened this issue May 10, 2022 · 1 comment

Comments

@OrianeK
Copy link

OrianeK commented May 10, 2022

Hi,
I am a high school student just starting to learn about testing techniques. I found a bug in the latest version (0.6.1) of maya while doing some fuzzing using the fuzzing tool Atheris. The reproducing process is shown below:

maya.parse('may15,2021').datetime()

result
datetime.datetime(2022, 5, 15, 0, 0, tzinfo=<UTC>)

my Environment

Python 3.8.10 (default, Mar 15 2022, 12:22:08) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import maya
>>> print(maya.__version__)
0.6.1
>>> 

I am not very sure about the bug so I would very much appreciate any kind of feedback regarding it.
Thanks.

@FluffyDietEngine
Copy link

Looks like the issue is from underlying pendulum parser.

Python 3.11.5 (main, Aug 24 2023, 12:23:19) [Clang 15.0.0 (clang-1500.0.40.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from maya import parse
>>> dt = "june 15,1987"
>>> parse(dt)
<MayaDT epoch=1686787200.0>
>>> parse(dt).datetime()
datetime.datetime(2023, 6, 15, 0, 0, tzinfo=<UTC>)
>>> from pendulum import parse
>>> parse(dt)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/santhoshsolomon/Desktop/venv/lib/python3.11/site-packages/pendulum/parser.py", line 29, in parse
    return _parse(text, **options)
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Desktop/venv/lib/python3.11/site-packages/pendulum/parser.py", line 45, in _parse
    parsed = base_parse(text, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Desktop/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 74, in parse
    return _normalize(_parse(text, **_options), **_options)
                      ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/santhoshsolomon/Desktop/venv/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 128, in _parse
    raise ParserError("Unable to parse string [{}]".format(text))
pendulum.parsing.exceptions.ParserError: Unable to parse string [june 15,1987]

When pendulum parser is failing, I have tried with other underlying tools, dateparser and python-dateutils.

>>> from dateparser import parse as dp_parse
>>> dt = "june 15,1987"
>>> dp_parse(dt)
datetime.datetime(1987, 6, 15, 0, 0) # correct value
>>> from dateutil.parser import parse as du_parse
>>> du_parse(dt)
datetime.datetime(2023, 6, 15, 0, 0) # wrong value

So the issue is happening at fallback parser python-dateutil.

Library versions

>>>
>>> import maya
>>> print(maya.__version__)
0.6.1
>>> import dateutil
>>> print(dateutil.__version__)
2.8.2
>>> import dateparser
>>> print(dateparser.__version__)
1.2.0
>>> import pendulum
>>> print(pendulum.__version__)
2.1.2

Added upstream issue at

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants