[ python-Bugs-897625 ] time.strftime crashes python

SourceForge.net noreply at sourceforge.net
Mon Feb 16 15:36:38 EST 2004


Bugs item #897625, was opened at 2004-02-16 10:33
Message generated for change (Comment added) made by matiu
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=897625&group_id=5470

Category: Python Library
Group: Python 2.3
Status: Open
Resolution: None
Priority: 7
Submitted By: Tom Lynn (tlynn)
Assigned to: Brett Cannon (bcannon)
Summary: time.strftime crashes python

Initial Comment:
On Win2k:

Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 
32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more 
information.
>>> import time
>>> time.strftime("%a",(1900,1,1, 13,0,0, -3,0,-1))

Python dumps core.  Is that (ever) expected behaviour?

----------------------------------------------------------------------

Comment By: Matthew Sherborne (matiu)
Date: 2004-02-17 09:36

Message:
Logged In: YES 
user_id=304464

On WinXP Home does:
>>> import time
>>> time.strftime("%a",(1900,1,1, 13,0,0, -3,0,-1))
'\xfcI\xc1w\xf8I\xc1w\xf4I\xc1w\xf0I\xc1w\xecI\xc1w\xe8I\xc1w\xe4I\xc1w\xdcI\xc1w\xd4I\xc1w\xccI\xc1w\xc0I\xc1w\xb4I\xc1w\xacI\xc1w\xa0I\xc1w\x9cI\xc1w\x98I\xc1w\x94I\xc1w\x90I\xc1w\x8cI\xc1w\x88I\xc1w\x84I\xc1w\x80I\xc1w|I\xc1wxI\xc1wtI\xc1wpI\xc1whI\xc1w\I\xc1wTI\xc1wLI\xc1w\x8cI\xc1wDI\xc1w<I\xc1w4I\xc1w(I\xc1wI\xc1w\x14I\xc1w\x08I\xc1w\x04I\xc1w'

ActivePython 2.3.2 Build 232 (ActiveState Corp.) based on
Python 2.3.2 (#49, Nov 13 2003, 10:34:54) [MSC v.1200 32 bit
(Intel)] on win32


----------------------------------------------------------------------

Comment By: Matthew Sherborne (matiu)
Date: 2004-02-17 09:34

Message:
Logged In: YES 
user_id=304464

On my linux system does:
>>> import time
>>> time.strftime("%a",(1900,1,1, 13,0,0, -3,0,-1))
'\x0e'

Python 2.3.3c1 (#2, Dec  6 2003, 16:44:56)
[GCC 3.3.3 20031203 (prerelease) (Debian)] on linux2

----------------------------------------------------------------------

Comment By: Matthew Sherborne (matiu)
Date: 2004-02-17 09:32

Message:
Logged In: YES 
user_id=304464

Also, please have a look at:
https://sourceforge.net/tracker/index.php?func=detail&aid=898253&group_id=5470&atid=105470

at the same time.

----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2004-02-16 14:23

Message:
Logged In: YES 
user_id=31435

I assume this is specific to Python on Windows using 
Microsoft's C, since this workalike plain C program also dies 
with a memory error while in the bowels of MS's strftime():

#include <stdio.h>
#include <time.h>

void main() {
    struct tm t;
    char buf[256];
    size_t i;

    t.tm_year = 1900 - 1900;
    t.tm_mon = 1 - 1;
    t.tm_mday = 1;
    t.tm_hour = 13;
    t.tm_min = 0;
    t.tm_sec = 0;
    t.tm_wday = -3;
    t.tm_yday = 0;
    t.tm_isdst = -1;

    printf("calling strftime\n");
    i = strftime(buf, sizeof(buf), "%a", &t);
    printf("i: %d\n", i);
}

The problem is the negative value for tm_wday.  MS strftime 
isn't defensive, and uses the negative tm_wday to index into 
nonsense memory.  Ironically, if C had defined the % operator 
in the sane way (meaning Python's way <wink>), a negative 
tm_wday wouldn't have survived for the C library function to 
see.

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2004-02-16 12:41

Message:
Logged In: YES 
user_id=80475

It is expected.  Well, now that I've confirmed it on Py2.3.3
and Py2.4, yes ;-) 

Is it desirable?  Heck no.

Brett, can you take a look at this?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=897625&group_id=5470



More information about the Python-bugs-list mailing list