Skip to content

ValueError exception when asking for authored_datetime #741

Description

@ishepard

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.

Activity

Byron commented on Apr 3, 2018

@Byron
Member

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.

reopened this on Apr 3, 2018

ishepard commented on Apr 3, 2018

@ishepard
ContributorAuthor

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 commented on Apr 3, 2018

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions