Repository navigation
BUG,MAINT: Fix utf-8 character stripping memory access - #26919
Conversation
This fixes the memory access bug, the old if was there for a reason (obviously...), but unfortunately only the sanitizer checks noticed that. But to make it clear, I had to just also rename/change things a bit making it unsigned and using a stop range rather than the actual range is just much clearer here where the range can go to length 0 IMO. I.e. the old code had to check for `j >= 0` not `j > 0` (j being the last character index), because `j` could go negative. Fixes the sanitizer tests.
|
Is there an easy way to write a test for this? |
|
One of the test ran into it with asan, so there is some test. Can't think of a way to make that much more sensitive, presumably valgrind would also catch it. Since all that is happening is reading 1-3 bytes in front of an allocation and that probably just doesn't fail that reliably. |
|
I agree this is clearer and after going through it carefully I think the code behaves identically before and after the renaming (except the re-added if block). Right now the whitespace variants aren't being tested. The following patch fixes that and adds a test case too. |
|
Thanks Sebastian! Let's pull this in to unbreak the ASAN tests. I'll try to fix the issue @WarrenWeckesser reported about stripping unicode in a followup. |
|
Thanks both for looking into this and sorry for not being careful enough in my PR. |
This fixes the memory access bug, the old if was there for a reason (obviously...), but unfortunately only the sanitizer checks noticed that.
But to make it clear, I had to just also rename/change things a bit making it unsigned and using a stop range rather than the actual range is just much clearer here where the range can go to length 0 IMO.
I.e. the old code had to check for
j >= 0notj > 0(j being the last character index), becausejcould go negative.Fixes the sanitizer tests.