-
-
Notifications
You must be signed in to change notification settings - Fork 29.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[C API] Segmentation fault in PyUnicodeWriter when writing nothing and with initial length = 0 #121849
Labels
Comments
This is a bug. The problem is that The "band-aid" fix would be to simply add 1 to the length if it's zero. |
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Jul 17, 2024
Do nothing if start=end.
vstinner
added a commit
to vstinner/cpython
that referenced
this issue
Jul 17, 2024
Do nothing if start=end.
I wrote #121896 to fix the bug. |
Fixed by #121896 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Bug description:
While working on accelerating fnmatch, I wanted to use the PyUnicodeWriter API instead of extracting two substrings and use concat(). I encountered a segmentation fault when attempting to write an empty range if the writer allocated actually 0 characters:
Note that changing
PyUnicodeWriter_Create(0)
toPyUnicodeWriter_Create(1)
make it work:@vstinner I can investigate or you can take the task if you want (best is to also add a test and confirm that I did not misused the API). By the way, keeping 0 as a length estimation but writing a non-empty string works:
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Linked PRs
NULL
pointer dereference whenlength
is zero inPyUnicodeWriter_Create
#121875The text was updated successfully, but these errors were encountered: