Skip to content

ValueError exception when asking for authored_datetime #741

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

Closed
ishepard opened this issue Mar 30, 2018 · 3 comments
Closed

ValueError exception when asking for authored_datetime #741

ishepard opened this issue Mar 30, 2018 · 3 comments

Comments

@ishepard
Copy link
Contributor

ishepard commented Mar 30, 2018

I am receiving a ValueError exception when getting the author date of a commit in Rails project. You can replicate it with the following code:

> from git import Repo
> repo = Repo('rails')
> commit = repo.commit('4cf94979c9f4d6683c9338d694d5eb3106a4e734')
> commit.authored_datetime
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dspadini/Documents/pydriller/.venv/lib/python3.6/site-packages/git/objects/commit.py", line 151, in authored_datetime
    return from_timestamp(self.authored_date, self.author_tz_offset)
  File "/Users/dspadini/Documents/pydriller/.venv/lib/python3.6/site-packages/git/objects/util.py", line 124, in from_timestamp
    > local_dt = utc_dt.astimezone(tzoffset(tz_offset))
ValueError: offset must be a timedelta strictly between -timedelta(hours=24) and timedelta(hours=24).

Tracing back the error, I got that the timestamp of the commit is 1312735823, while the tz_offset is -1864800. The problem is when creating the tzoffset: I indeed printed the timedelta

local_dt = utc_dt.astimezone(tzoffset(tz_offset))

class tzoffset(tzinfo):
    def __init__(self, secs_west_of_utc, name=None):
        self._offset = timedelta(seconds=-secs_west_of_utc)
        print('Timedelta is {}'.format(timedelta(seconds=-secs_west_of_utc)))

and it is not in the range of [-24,24] hours, but it is actually 21 days.

EDIT: looking at the information of the commit, the offset is completely wrong:
Date: Mon Aug 29 06:50:23 2011 +51800

So the problem is not of gitpython.

@Byron
Copy link
Member

Byron commented Apr 3, 2018

In a way, it’s a denyal of service attack against GitPython, as it should certainly not choke on it the way it does.
Maybe it’s something worth fixing for that reason.

@ishepard
Copy link
Contributor Author

ishepard commented Apr 3, 2018

I was looking at how jGit solved it, and they simply return UTC timestamp if they fail in retrieving the timestamp of the commit. If you also agree with this solution, I can submit a PR tomorrow (I am UTC+2 ;) )

@Byron
Copy link
Member

Byron commented Apr 3, 2018 via email

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

No branches or pull requests

2 participants