Skip to content

Fix stackalloc buffer size to use required byte count#9168

Merged
michaelstaib merged 6 commits into
ChilliCream:mainfrom
Hanskrogh:fix/utf8-stackalloc-buffer-size
Feb 20, 2026
Merged

Fix stackalloc buffer size to use required byte count#9168
michaelstaib merged 6 commits into
ChilliCream:mainfrom
Hanskrogh:fix/utf8-stackalloc-buffer-size

Conversation

@Hanskrogh
Copy link
Copy Markdown
Contributor

This PR fixes an incorrect buffer allocation in the UTF-8 encoding path where stackalloc was using value.Length instead of the computed requiredBytes.

Copilot AI review requested due to automatic review settings February 20, 2026 14:50
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR attempts to fix a buffer allocation bug in UTF-8 encoding where stackalloc was incorrectly using value.Length (character count) instead of requiredBytes (actual UTF-8 byte count). This could cause buffer overflow when encoding strings with multi-byte UTF-8 characters.

Changes:

  • Fixed stackalloc buffer size in SetStringValue(ReadOnlySpan<char>) to use requiredBytes instead of value.Length

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/HotChocolate/Core/src/Types/Text/Json/ResultElement.cs Outdated
Comment thread src/HotChocolate/Core/src/Types/Text/Json/ResultElement.cs Outdated
@michaelstaib michaelstaib changed the title fix: UTF-8 stackalloc buffer size to use required byte count Fix stackalloc buffer size to use required byte count Feb 20, 2026
michaelstaib and others added 3 commits February 20, 2026 16:06
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@michaelstaib michaelstaib merged commit 645f5db into ChilliCream:main Feb 20, 2026
3 checks passed
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.

3 participants