Movatterモバイル変換


[0]ホーム

URL:


homepage

Issue24731

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:Incorrect assert in str_subtype_new
Type:crashStage:resolved
Components:Interpreter CoreVersions:Python 3.6, Python 3.4, Python 3.5, Python 2.7
process
Status:closedResolution:fixed
Dependencies:Superseder:
Assigned To: serhiy.storchakaNosy List: Kevin Modzelewski, mark.dickinson, python-dev, serhiy.storchaka
Priority:normalKeywords:patch

Created on2015-07-26 23:21 byKevin Modzelewski, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.

Files
File nameUploadedDescriptionEdit
issue24731.patchserhiy.storchaka,2015-11-22 23:11Patch for 3.6review
issue24731-2.7.patchserhiy.storchaka,2015-11-22 23:11Patch for 2.7review
Messages (5)
msg247451 -(view)Author: Kevin Modzelewski (Kevin Modzelewski)Date: 2015-07-26 23:21
(Using python 3 terminology)  str_subtype_new is the function that creates instances of any subtypes of bytes (ie is called by bytes_new if the requested type is not PyBytes_Type -- looks like this function's name comes from python 2).  Its approach is to create a bytes object using the same arguments, and then copy the resulting data into the subclass-instance's memory.  It does    tmp = bytes_new(&PyBytes_Type, args, kwds);    [error checking]    assert(PyBytes_CheckExact(tmp));The problem is that bytes_new can return a subclass of bytes, if the argument provides a __bytes__ method that returns a bytes-subtype.  For example    class MyBytes(bytes):        pass    class C(object):        def __bytes__(self):            return MyBytes(b"hello world")    MyBytes(C()) # fails the assertThis doesn't seem to cause any issues other than the failing assert in debug builds; it seems like the assert should just be relaxed from PyBytes_CheckExact to PyBytes_Check since that's enough to guarantee that the upcoming manipulation of the "tmp" variable is going to be valid.  Also, this would match how unicode_subtype_new behaves.This bug also applies to Python 2, since I think the relevant code is the same, though in that case it applies to str instead of bytes.
msg255117 -(view)Author: Serhiy Storchaka (serhiy.storchaka)*(Python committer)Date: 2015-11-22 23:11
Thank you for your report Kevin and sorry for the delay. I confirm the bug and agree with your solution. The same bug exists for ints and floats.Here are patches that fix crashes.
msg255351 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2015-11-25 13:56
New changesetd8e0b54ece62 by Serhiy Storchaka in branch '3.4':Issue#24731: Fixed crash on converting objects with special methodshttps://hg.python.org/cpython/rev/d8e0b54ece62New changeset80efe5cc8934 by Serhiy Storchaka in branch '3.5':Issue#24731: Fixed crash on converting objects with special methodshttps://hg.python.org/cpython/rev/80efe5cc8934New changeset1c4d256cc370 by Serhiy Storchaka in branch 'default':Issue#24731: Fixed crash on converting objects with special methodshttps://hg.python.org/cpython/rev/1c4d256cc370New changeset37158c067b25 by Serhiy Storchaka in branch '2.7':Issue#24731: Fixed crash on converting objects with special methodshttps://hg.python.org/cpython/rev/37158c067b25
msg255583 -(view)Author: Roundup Robot (python-dev)(Python triager)Date: 2015-11-29 18:14
New changeset2ea1a3bf448f by Serhiy Storchaka in branch '2.7':Fixed Py3k warnings in tests for issue#24731.https://hg.python.org/cpython/rev/2ea1a3bf448f
msg255683 -(view)Author: Kevin Modzelewski (Kevin Modzelewski)Date: 2015-12-01 23:25
Awesome, thanks!
History
DateUserActionArgs
2022-04-11 14:58:19adminsetgithub: 68919
2015-12-01 23:25:40Kevin Modzelewskisetmessages: +msg255683
2015-11-29 18:14:17python-devsetmessages: +msg255583
2015-11-25 13:57:54serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2015-11-25 13:56:49python-devsetnosy: +python-dev
messages: +msg255351
2015-11-22 23:11:59serhiy.storchakasetfiles: +issue24731-2.7.patch
2015-11-22 23:11:11serhiy.storchakasetfiles: +issue24731.patch

nosy: +mark.dickinson
messages: +msg255117

keywords: +patch
stage: needs patch -> patch review
2015-07-27 04:33:54serhiy.storchakasetversions: + Python 3.4, Python 3.6
nosy: +serhiy.storchaka

assignee:serhiy.storchaka
type: crash
stage: needs patch
2015-07-26 23:21:25Kevin Modzelewskicreate
Supported byThe Python Software Foundation,
Powered byRoundup
Copyright © 1990-2022,Python Software Foundation
Legal Statements

[8]ページ先頭

©2009-2026 Movatter.jp