classification
Title: Py_SAFE_DOWNCAST in FILE_TIME_to_time_t_nsec failing
Type: behavior Stage:
Components: None Versions: Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, belopolsky, kevinwatters, loewis, vstinner
Priority: normal Keywords: patch

Created on 2008-11-21 17:20 by kevinwatters, last changed 2011-02-17 22:13 by vstinner. This issue is now closed.

Files
File name Uploaded Description Edit
time_t_64.patch amaury.forgeotdarc, 2008-11-21 21:16 review
Messages (6)
msg76193 - (view) Author: Kevin Watters (kevinwatters) Date: 2008-11-21 17:20
After releasing a Py_DEBUG build to some users who were experiencing 
problems, I noticed a pattern in some of the crash reports I got back:

msvcr90d!_wassert+0xb64
python25_d!FILE_TIME_to_time_t_nsec+0xac
python25_d!attribute_data_to_stat+0x67
python25_d!win32_wstat+0x6f
python25_d!posix_do_stat+0x51
python25_d!posix_stat+0x24
python25_d!PyCFunction_Call+0x65
python25_d!call_function+0x34f
python25_d!PyEval_EvalFrameEx+0x4741

The only way I can see _wassert being hit in FILE_TIME_to_time_t_nsec is 
in the Py_SAFE_DOWNCAST used to downcast an __int64 to int. 
Py_SAFE_DOWNCAST checks that there is equality between the casted and 
non-casted values with Py_DEBUG enabled--maybe in this function we 
should remove Py_SAFE_DOWNCAST?

I can't find a way to see the actual value for "in" before the assert is 
hit--I'm unfamiliar with picking through minidumps with WinDbg, which 
for some reason will show me the stack for these dumps when Visual 
Studio won't. But if I need to investigate more about them I can.
msg76201 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-11-21 20:29
You almost gave the answer in your question - the FILE_TIME is about to be 
converted to a time_t greater than 2**31.

in posixmodule.c::FILE_TIME_to_time_t_nsec(), a comment says:
/* XXX Win32 supports time stamps past 2038; we currently don't */
just before the assert()...

And indeed to reproduce the same crash it is enough to call os.stat() on a 
file with a creation date in 2050 for example.
msg76204 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2008-11-21 21:16
The attached patch corrects the problem: since VS2008 time_t is a 64bit 
integer; now os.stat() can return times after 2038 on Windows.

This prevents the crash, but the functionality is far from complete: 
os.utime() at least should accept 64bit times.
msg77506 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2008-12-10 08:47
IIUC, the patch relies on VS 2008. So it is not a candidate for 2.5.3.
msg128762 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-02-17 22:13
Oh, this issue was already fixed by r87666 to fix the duplicate issue #8278.
msg128763 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2011-02-17 22:13
> Oh, this issue was already fixed by r87666

... in py3k, and then merged into release31-maint (r87668) and release27-maint (r87669).
History
Date User Action Args
2011-02-17 22:13:56vstinnersetnosy: loewis, amaury.forgeotdarc, belopolsky, vstinner, kevinwatters
messages: + msg128763
2011-02-17 22:13:01vstinnersetstatus: open -> closed

nosy: + vstinner
messages: + msg128762

resolution: fixed
2010-09-04 00:34:01pitrousetnosy: + belopolsky
2008-12-10 08:47:49loewissetnosy: + loewis
messages: + msg77506
versions: + Python 2.6, Python 2.7, - Python 2.5.3
2008-11-21 21:16:09amaury.forgeotdarcsetfiles: + time_t_64.patch
keywords: + patch
messages: + msg76204
2008-11-21 20:29:36amaury.forgeotdarcsetnosy: + amaury.forgeotdarc
messages: + msg76201
2008-11-21 17:20:05kevinwatterscreate