[Python-Dev] Boundary checks on arguments to time.strftime()

Brett C. bac at OCF.Berkeley.EDU
Mon Feb 23 02:09:32 EST 2004


Bug #897625 (http://python.org/sf/897625) deals with giving 
time.strftime() date information that is outside of proper bounds (e.g., 
using a negative number for the day of the week).  This can lead to a 
crash since it seems some strftime implementations just index into an 
array for values for text and thus a negative value can lead to bad 
things happening.

I would like to raise a ValueError if the argument is out of range. 
Problem is that this will break code.  I could just force all negative 
values to all values outside the proper bounds to a reasonable value, 
but that seems to go against the path of least surprise.  That is 
question 1.

Question 2 is what to really check.  This really is only a concern for 
month and day of the week since everything else is just a number and 
doesn't have some name representation.  I could check all 9 values, 
though, or just these two.

Question 3 is whether to extend this to time.asctime() .  I have talked 
to Tim about this and his thoughts are to just deal with time.strftime() 
and leave everything else alone.  That's fine with me, but there is the 
same possibility of having problems with asctime().  But then again, 
checking value for asctime() would potentially break even more code.

So, thoughts?

-Brett



More information about the Python-Dev mailing list