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: Check return value of _PyBytes_Resize
Type: behavior Stage: resolved
Components: Extension Modules Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, christian.heimes, martin.panter, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-09-17 09:36 by berker.peksag, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
pybytes_resize.diff berker.peksag, 2016-09-17 09:36
pybytes_resize_regenerated.diff berker.peksag, 2016-09-17 11:05 review
Messages (6)
msg276778 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-09-17 09:36
There are a couple of instances that don't check return value of _PyBytes_Resize in Modules/. I noticed this while working on issue 25270.

Patch attached.
msg276779 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-09-17 09:48
Can the resize fail if the buffer is only being strunk? I haven’t looked closely, but maybe that’s why some of the cases don’t check for failure.
msg276780 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2016-09-17 10:41
Yes, it can fail for multiple reasons: wrong type, ref count != 1, realloc() fails to allocate a smaller area.
msg276781 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-17 11:00
Could you please regenerate the patch for Rietveld Berker?

_PyBytes_Resize(&res, r) always sets res to NULL if fails. Thus the following code is correct. No need to check the return value.

    if (n > r)
        _PyBytes_Resize(&res, r);
    return res;
msg276784 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-09-17 11:45
In all cases _PyBytes_Resize is followed by return. Original code is correct. In either way NULL is returned if _PyBytes_Resize fails.
msg276788 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-09-17 12:36
Thanks for the review, Serhiy! Good point, closing this as 'not a bug'.
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72374
2016-09-17 12:36:28berker.peksagsetstatus: open -> closed
resolution: not a bug
messages: + msg276788

stage: patch review -> resolved
2016-09-17 11:45:45serhiy.storchakasetmessages: + msg276784
2016-09-17 11:05:44berker.peksagsetfiles: + pybytes_resize_regenerated.diff
2016-09-17 11:00:50serhiy.storchakasetmessages: + msg276781
2016-09-17 10:41:55christian.heimessetnosy: + christian.heimes
messages: + msg276780
2016-09-17 09:48:29martin.pantersetnosy: + martin.panter
messages: + msg276779
2016-09-17 09:36:45berker.peksagcreate