gh-156939: Detect buffer overflow in PyBytesWriter in debug mode - #156943
Conversation
|
Oh, the test_xml_etree_c failure is a legit failure: unicode_encode_ucs1() calls with |
|
The test_struct error is also a legit bug: a Pascal string of 0 characters writes a NUL byte into an empty buffer, and so triggers a buffer overflow. |
|
On Ubuntu, 8 tests are failing: |
Reserve one byte in PyBytesWriter used as a canary byte: set it to a special value. PyBytesWriter_Finish() checks if the canary byte has been overriden. Add a test on the feature. Update buffer overflow check in fcntl: allocate extra guard bytes in the writer and then truncate these bytes.
42640e3 to
89a8ac9
Compare
Avoid calling PyBytesWriter_Grow().
* Add test_get_data_canary() * Update test_get_data()
unicode_encode_ucs1() now calls PyBytesWriter_Grow() to update the PyBytesWriter size.
PyBytesWriter_Grow() no longer calls byteswriter_resize() if grow is smaller than 0.
|
Android x86_64 fails with: This error comes from >>> "\ud800\udc00".encode('utf8', 'backslashreplace')
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
"\ud800\udc00".encode('utf8', 'backslashreplace')
~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: size larger than allocated sizeAh! I forgot to update the UTF-8 encoder. |
I wrote PR gh-157383 for that. |
|
|
Reserve one byte in PyBytesWriter used as a canary byte: set it to a special value. PyBytesWriter_Finish() checks if the canary byte has been overriden. Add a test on the feature.
Update buffer overflow check in fcntl: allocate extra guard bytes in the writer and then truncate these bytes.