Issue 19545: time.strptime exception context (original) (raw)

time.strptime leaks an IndexError, as seen in the following traceback.

[root@clnstor /tank/libs/cpython]# ./python Python 3.4.0a4+ (default:0aa2aedc6a21+, Nov 5 2013, 17:10:42) [GCC 4.2.1 20070831 patched [FreeBSD]] on freebsd8 Type "help", "copyright", "credits" or "license" for more information.

import time time.strptime('19', '%Y %') Traceback (most recent call last): File "/tank/libs/cpython/Lib/_strptime.py", line 320, in _strptime format_regex = _TimeRE_cache.compile(format) File "/tank/libs/cpython/Lib/_strptime.py", line 268, in compile return re_compile(self.pattern(format), IGNORECASE) File "/tank/libs/cpython/Lib/_strptime.py", line 262, in pattern self[format[directive_index]]) IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "", line 1, in File "/tank/libs/cpython/Lib/_strptime.py", line 494, in _strptime_time tt = _strptime(data_string, format)[0] File "/tank/libs/cpython/Lib/_strptime.py", line 332, in _strptime raise ValueError("stray %% in format '%s'" % format) ValueError: stray % in format '%Y %'

The attached patch suppresses the exception. This issue is similar (and based on) the .