Repository navigation
gh-161688: Fixed segmentation fault error in bytearray.strip() - #161701
NotorandXor256 wants to merge 6 commits into
Conversation
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
vstinner
left a comment
There was a problem hiding this comment.
PyMem_Malloc()+strncpy() would make the method way slower.
I would prefer to use exports++ and exports-- to protect self. This way, it's not possible to modify the bytearray while it's being used.
There are more bytearray methods which should be modified with a similar fix.
Should i fix those methods in this PR or open new issue and send a patch. |
|
We can reuse the same issue for fixing stirp() and other methods. You may open a new PR if the fix is different. |
|
CC @vstinner |
vstinner
left a comment
There was a problem hiding this comment.
Ah, I'm fine with this approach: only move PyByteArray_FromStringAndSize() call to avoid the crash.
|
|
||
|
|
||
| PyObject *res = PyByteArray_FromStringAndSize(myptr + left, right - left); | ||
|
|
||
| if (bytes != Py_None) | ||
| PyBuffer_Release(&vbytes); | ||
| return PyByteArray_FromStringAndSize(myptr + left, right - left); | ||
| return res; |
There was a problem hiding this comment.
| PyObject *res = PyByteArray_FromStringAndSize(myptr + left, right - left); | |
| if (bytes != Py_None) | |
| PyBuffer_Release(&vbytes); | |
| return PyByteArray_FromStringAndSize(myptr + left, right - left); | |
| return res; | |
| PyObject *res = PyByteArray_FromStringAndSize(myptr + left, right - left); | |
| if (bytes != Py_None) { | |
| PyBuffer_Release(&vbytes); | |
| } | |
| return res; |
There was a problem hiding this comment.
for some reseaon i couldn't commit this changes in github I will apply this changes in next commit
|
Oh wait, if |
Co-authored-by: Victor Stinner <vstinner@python.org>
I didn't implement |
|
CC @vstinner |
This PR fix segmentation violation in bytearray.strip()
bytearray.strip read freed memory, this PR solves it by copying the content of freed up string first and then free the string
I have add test in test_bytes.py