
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2015-07-26 23:21 byKevin Modzelewski, last changed2022-04-11 14:58 byadmin. This issue is nowclosed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| issue24731.patch | serhiy.storchaka,2015-11-22 23:11 | Patch for 3.6 | review | |
| issue24731-2.7.patch | serhiy.storchaka,2015-11-22 23:11 | Patch for 2.7 | review | |
| 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)*![]() | 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)![]() | 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)![]() | 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 | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:19 | admin | set | github: 68919 |
| 2015-12-01 23:25:40 | Kevin Modzelewski | set | messages: +msg255683 |
| 2015-11-29 18:14:17 | python-dev | set | messages: +msg255583 |
| 2015-11-25 13:57:54 | serhiy.storchaka | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2015-11-25 13:56:49 | python-dev | set | nosy: +python-dev messages: +msg255351 |
| 2015-11-22 23:11:59 | serhiy.storchaka | set | files: +issue24731-2.7.patch |
| 2015-11-22 23:11:11 | serhiy.storchaka | set | files: +issue24731.patch nosy: +mark.dickinson messages: +msg255117 keywords: +patch stage: needs patch -> patch review |
| 2015-07-27 04:33:54 | serhiy.storchaka | set | versions: + Python 3.4, Python 3.6 nosy: +serhiy.storchaka assignee:serhiy.storchaka type: crash stage: needs patch |
| 2015-07-26 23:21:25 | Kevin Modzelewski | create | |