Fix heap-buffer-overflow in convert_utf16_to_utf8_safe#912
Merged
lemire merged 1 commit intosimdutf:masterfrom Jan 12, 2026
Merged
Fix heap-buffer-overflow in convert_utf16_to_utf8_safe#912lemire merged 1 commit intosimdutf:masterfrom
lemire merged 1 commit intosimdutf:masterfrom
Conversation
Move bounds check BEFORE write for 1-byte ASCII cases to prevent heap-buffer-overflow when output buffer is exactly full. The bug was in two locations where the code writes to the output buffer before checking if there is sufficient space (write-before-check pattern). This is inconsistent with the 2-byte, 3-byte, and 4-byte cases which correctly check before writing. Fixes: simdutf#911
Member
|
Verification of the issue at #913 |
Member
|
@OwenSanzas Can you sync with our main branch to verify the fix ? |
Collaborator
|
I tried this PR on the newly written fuzzer just merged seconds ago. It works! |
Collaborator
|
The newly added tests for this also stopped failing with this patch applied. I suggest we merge it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root Cause
The
_safefunction designed to prevent buffer overflows had a bug where it writes to the buffer BEFORE checking if there is sufficient space:Fix
Move the check before the write:
Test Plan
Fixes: #911