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

SourceForge.net noreply at sourceforge.net
Sun Feb 15 20:23:50 EST 2004


Bugs item #897625, was opened at 2004-02-15 16:33
Message generated for change (Comment added) made by tim_one
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: Tim Peters (tim_one)
Date: 2004-02-15 20: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-15 18: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