[New-bugs-announce] [issue19545] time.strptime exception context

Claudiu.Popa report at bugs.python.org
Sun Nov 10 18:03:45 CET 2013


New submission from Claudiu.Popa:

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

[root at 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 "<stdin>", line 1, in <module>
  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 issue17572.

----------
components: Library (Lib)
files: time_strptime.patch
keywords: patch
messages: 202536
nosy: Claudiu.Popa, belopolsky
priority: normal
severity: normal
status: open
title: time.strptime exception context
versions: Python 3.4
Added file: http://bugs.python.org/file32563/time_strptime.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19545>
_______________________________________


More information about the New-bugs-announce mailing list