This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: time.strptime exception context
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Claudiu.Popa, belopolsky, ezio.melotti, python-dev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2013-11-10 17:03 by Claudiu.Popa, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
time_strptime.patch Claudiu.Popa, 2013-11-10 17:03 review
Messages (4)
msg202536 - (view) Author: PCManticore (Claudiu.Popa) * (Python triager) Date: 2013-11-10 17:03
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 "<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.
msg204226 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-11-24 16:02
LGTM.
msg204228 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-11-24 16:17
New changeset ce1578f4d105 by Serhiy Storchaka in branch '3.3':
Issue #19545: Avoid chained exceptions while passing stray % to
http://hg.python.org/cpython/rev/ce1578f4d105

New changeset 2bf4741515a7 by Serhiy Storchaka in branch 'default':
Issue #19545: Avoid chained exceptions while passing stray % to
http://hg.python.org/cpython/rev/2bf4741515a7
msg204229 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-11-24 16:19
Thank you for your contribution.
History
Date User Action Args
2022-04-11 14:57:53adminsetgithub: 63744
2013-11-24 16:19:48serhiy.storchakasetstatus: open -> closed
resolution: fixed
messages: + msg204229

stage: commit review -> resolved
2013-11-24 16:17:44python-devsetnosy: + python-dev
messages: + msg204228
2013-11-24 16:02:14serhiy.storchakasettype: behavior
messages: + msg204226
stage: commit review
2013-11-24 07:01:14serhiy.storchakasetassignee: serhiy.storchaka
2013-11-24 01:10:08pitrousetnosy: + serhiy.storchaka
2013-11-23 19:17:54Claudiu.Popasetnosy: + ezio.melotti
2013-11-10 17:03:45Claudiu.Popacreate