Conversation
Add bytearray_check_consistency() and bytearray_check_trailing_null_byte() functions in call them in most bytearray methods.
Reset the trailing byte before destroying the bytes/bytearray object.
It's a legit bug: I reported the failure as #157415 and I proposed a fix (skip the test if TSAN is used). |
|
The PR adds
|
|
@cmaloney: Would you mind to review this change? I didn't measure the overhead on runtime benchmark of a Python debug build. If |
|
I just made a similar change to detect buffer overflow in PyBytesWriter: PR gh-156943. |
|
I am a bit unsure about the usefulness of these checks, see my comment on issue. |
|
This change is quite big. It adds checks (check for buffer overflow and/or check consistency) to basically every single bytearray method. I wrote a way smaller change which only checks for buffer overflow in bytearray destructor: PR gh-157529. Bonus: I also added a similar check for bytes! |
|
I think this would be effective but unlikely to be remembered when adding new methods, prefer the smaller / simpler just checking at destruction time. |
|
I wasn't sure if my change was worth it when I wrote it. It modifies a lot of code, and I'm not sure that buffer overflows are common enough to justify added code. After reading @kumaraditya303 and @cmaloney comments, I'm now confident that no, it's not worth it. I abandon this large change to focus on the simpler and shorter PR gh-157529. |
Add bytearray_check_consistency() and
bytearray_check_trailing_null_byte() functions in call them in most bytearray methods.