Skip to content
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

gh-121849: Fix NULL pointer dereference when length is zero in PyUnicodeWriter_Create #121875

Closed
wants to merge 3 commits into from

Conversation

ZeroIntensity
Copy link
Contributor

This simply allocates 1 byte instead of letting buffer be NULL when the length is 0.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dislike this workaround. WriteSubstring() should do nothing if start=end.

@ZeroIntensity
Copy link
Contributor Author

I dislike this workaround. WriteSubstring() should do nothing if start=end.

(FWIW, this doesn't affect WriteSubstring(), only Create()). I think I somewhat agree -- I was a bit hesitant to take this approach, but it has the benefit of being the one that will require the least amount of future maintenance.

Would the better way to do it be to just special-case NULL buffers for all unicode writer methods?

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change has a negative cost on performance. It's not free to allocate a non-empty buffer in Create(). I wrote #121896 to fix this crash.

@vstinner
Copy link
Member

I merged my fix #121896

Thanks for your contribution @ZeroIntensity!

@vstinner vstinner closed this Jul 17, 2024
@ZeroIntensity ZeroIntensity deleted the unicodewriter-fix branch July 17, 2024 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants