-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
test_time fails: strftime('%Y', y) for negative year #57521
Comments
On builder "AMD64 FreeBSD 8.2 3.x" for the TIME_MINYEAR: ====================================================================== Traceback (most recent call last):
File "/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/test/test_time.py", line 397, in test_negative
return super().test_negative()
File "/usr/home/buildbot/buildarea/3.x.krah-freebsd/build/Lib/test/test_time.py", line 425, in test_negative
self.assertEqual(self.yearstr(TIME_MINYEAR), str(TIME_MINYEAR))
AssertionError: '2147483648' != '-2147483648'
- 2147483648
+ -2147483648
? + |
New changeset 9cb1b85237a9 by Florent Xicluna in branch 'default': |
New changeset d877d7f3b679 by Florent Xicluna in branch 'default': |
It fails for very low negative years: Every other value behaves correctly on this FreeBSD buildbot:
|
I mean formatted with '%Y', of course. |
New changeset 1a0bfc26af57 by Florent Xicluna in branch 'default': |
The failing negative years test is still being skipped. I'm assuming this was not originally intended. |
I believe that this can be closed as the test code was changed completely in bpo-17960. |
Mark, Issue bpo-17960 ("Clarify the required behaviour of locals()") does not seem to be relevant here. I think you meant to refer to a changeset, not issue number. If so please use hash number such as d877d7f3b679. |
As far as I can tell, the original report was about a test failing due to a system-dependent behavior of time.asctime(). However, since changeset 1e62a0cee092 (see issue bpo-8013), we no longer call system asctime. I believe the test disabled in 1a0bfc26af57 can now be restored. |
Sorry should have been bpo-17690. |
We still have the following in Lib/test/test_time.py: # Issue python/cpython#57521: it may return wrong value for year < TIME_MINYEAR + 1900
# Skip the value test, but check that no error is raised
self.yearstr(TIME_MINYEAR) I reviewed the current time.asctime() code and it does look like it invokes undefined behavior for extremely large negative years. The problem is that in C struct tm, year is stored as year - 1900 and for year < -2147481748 (= -2**31 + 1900) we trigger an overflow of a signed integer. Can someone confirm that on AMD64 FreeBSD subtracting 1900 from -2147483648 and then adding it back does not give -2147483648? |
Attached patch eliminates undefined behavior, but I am not sure fixing this is worth the trouble. |
If you enable GCC’s -ftrapv option, the subtraction overflow triggers an abort. Alexander’s patch works around the problem for asctime(), but the problem still exists in other cases, such as: >>> time.mktime((-2**31 + 1899, *(0,) * 8))
Aborted (core dumped)
[Exit 134] Attaching a version of the patch without the conflicting whitespace changes. Why does Python even need to support such extreme time values? It would seem much simpler to raise an exception. |
OverflowError is now raised for negative values that would trigger a problem and the unittest has been updated to test this. |
Note for myself: Python 2.7 is not affected by this bug because it doesn't accept year < 1900. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: