Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue33817

This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title:PyString_FromFormatV() fails to build empty strings
Type:behaviorStage:resolved
Components:Interpreter CoreVersions:Python 2.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: Tey, miss-islington, serhiy.storchaka
Priority:normalKeywords:patch, patch, patch

Created on2018-06-09 20:36 byTey, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.

Pull Requests
URLStatusLinkedEdit
PR 11515mergedserhiy.storchaka,2019-01-11 09:19
PR 11515mergedserhiy.storchaka,2019-01-11 09:19
PR 11515mergedserhiy.storchaka,2019-01-11 09:19
PR 11516mergedserhiy.storchaka,2019-01-11 09:20
PR 11516mergedserhiy.storchaka,2019-01-11 09:20
PR 11516mergedserhiy.storchaka,2019-01-11 09:20
PR 11532mergedmiss-islington,2019-01-12 07:22
PR 11532mergedmiss-islington,2019-01-12 07:22
Messages (6)
msg319180 -(view)Author: Tey (Tey)Date: 2018-06-09 20:36
Making PyString_FromFormatV() build an empty string on 2.7 will fail and raise the following error:SystemError:Objects/stringobject.c:3903: bad argument to internal functionIt does not matter if format is empty or not (e.g., both PyString_FromFormat("") and PyString_FromFormat("%s", "")).The exception is raised from _PyString_Resize() (called at the end of PyString_FromFormatV()), because the string given to that method has a ref count different than 1. This is expected for empty strings, because PyString_FromStringAndSize() returns a reference to <nullstring> when <size> is 0.A possible fix would be to prevent the call to _PyString_Resize() from PyString_FromFormatV() if <string> is equal to <nullstring>, or if there is no need to resize the string.Python 3 versions before 3.6 might be impacted as well through PyBytes_FromFormatV() (cannot check).The following code can be used to trigger the bug:    static int dobug(const char *fmt, ...) {        va_list args;        va_start(args, fmt);            PyObject *str = PyString_FromFormatV(fmt, args);        va_end(args);            if(str == NULL) {            fprintf(stderr, "Error: PyString_FromFormatV(%s) returned NULL\n", fmt);            return -1;        }            Py_DECREF(str);            return 0;    }    static PyObject* bug(PyObject *self) {        fprintf(stderr, "dobug(\"\") => %d\n", dobug(""));        fprintf(stderr, "dobug(\"%%s\", \"\") => %d\n", dobug("%s", ""));            if(PyErr_Occurred()) return NULL;        Py_RETURN_NONE;    }
msg319226 -(view)Author: Tey (Tey)Date: 2018-06-10 17:43
For the record, it does not fail on 3.x because _PyBytes_Resize() checks if the "string" needs to be resized (and returns if not) before checking its ref count. Maybe something similar should be done in _PyString_Resize() for 2.x.
msg319227 -(view)Author: Tey (Tey)Date: 2018-06-10 17:53
BTW, problem does appear in 3.4 as it's only been fixed in 3.5+ as a fix for issue#25270
msg333518 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2019-01-12 07:22
New changeset44cc4822bb3799858201e61294c5863f93ec12e2 by Serhiy Storchaka in branch 'master':bpo-33817: Fix _PyBytes_Resize() for empty bytes object. (GH-11516)https://github.com/python/cpython/commit/44cc4822bb3799858201e61294c5863f93ec12e2
msg333519 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2019-01-12 07:22
New changeset08a81df05004147ee174ece645679576ab867860 by Serhiy Storchaka in branch '2.7':bpo-33817: Fix _PyString_Resize() and _PyUnicode_Resize() for empty strings. (GH-11515)https://github.com/python/cpython/commit/08a81df05004147ee174ece645679576ab867860
msg333520 -(view)Author: miss-islington (miss-islington)Date: 2019-01-12 07:40
New changesetd39c19255910b9dce08c595f511597e98b09e91f by Miss Islington (bot) in branch '3.7':bpo-33817: Fix _PyBytes_Resize() for empty bytes object. (GH-11516)https://github.com/python/cpython/commit/d39c19255910b9dce08c595f511597e98b09e91f
History
DateUserActionArgs
2022-04-11 14:59:01adminsetgithub: 77998
2019-01-12 07:48:00serhiy.storchakasetkeywords:patch,patch,patch
status: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-01-12 07:40:15miss-islingtonsetnosy: +miss-islington
messages: +msg333520
2019-01-12 07:22:55serhiy.storchakasetmessages: +msg333519
2019-01-12 07:22:51miss-islingtonsetpull_requests: +pull_request11130
2019-01-12 07:22:47miss-islingtonsetpull_requests: +pull_request11129
2019-01-12 07:22:36serhiy.storchakasetmessages: +msg333518
2019-01-11 09:20:35serhiy.storchakasetpull_requests: +pull_request11084
2019-01-11 09:20:30serhiy.storchakasetpull_requests: +pull_request11083
2019-01-11 09:20:26serhiy.storchakasetpull_requests: +pull_request11082
2019-01-11 09:20:05serhiy.storchakasetkeywords: +patch
stage: patch review
pull_requests: +pull_request11081
2019-01-11 09:20:00serhiy.storchakasetkeywords: +patch
stage: (no value)
pull_requests: +pull_request11080
2019-01-11 09:19:55serhiy.storchakasetkeywords: +patch
stage: (no value)
pull_requests: +pull_request11079
2018-06-10 17:53:53Teysetmessages: +msg319227
2018-06-10 17:43:47Teysetmessages: +msg319226
2018-06-10 06:58:13serhiy.storchakasetassignee:serhiy.storchaka

nosy: +serhiy.storchaka
versions: - Python 3.4, Python 3.5
2018-06-09 20:36:16Teycreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp