[Python-Dev] Checking input range in time.asctime and time.ctime

Eric Smith eric at trueblade.com
Thu Jan 6 17:30:17 CET 2011


On 01/06/2011 11:08 AM, Victor Stinner wrote:
> Le jeudi 06 janvier 2011 à 10:47 -0500, R. David Murray a écrit :
>> On Thu, 06 Jan 2011 12:55:24 +0100, Victor Stinner<victor.stinner at haypocalc.com>  wrote:
>>> Le jeudi 06 janvier 2011 à 00:10 -0500, Alexander Belopolsky a écrit :
>>>>   If calling specific system functions such as strftime with tm_year<
>>>> 0 is deemed unsafe, we can move the check to where the system function
>>>> is called.
>>>
>>> What do you mean by "unsafe"? Does it crash? On my Linux box,
>>> strftime("%Y") is able to format integers in [-2^31-1900; 2^31-1-1900]
>>> (full range of the int type).
>>
>> I believe that we have had several cases where Windows "crashed" when
>> out-of-range values were passed to the CRT that other platforms
>> accepted.
>
> If there are only issues on Windows, we can add a #ifdef _MSC_VER and
> raise a ValueError("Stupid OS, install Linux or recompile with Cygwin")
> for year<  1900.

Is strftime really so complex that we shouldn't just write our own? I'd 
be willing to do it. Over the years the platform strftime has caused any 
number of problems. The last time I looked at it we already have to do 
some work pre-parsing the format string and passing it off to platform 
strftime, so it's not like it's not already a maintenance hassle.

I understand strptime is probably more complex and there's some value to 
having strptime/strftime coming from the same library. But I'd be 
willing to look at it, too.

Eric.


More information about the Python-Dev mailing list