Fix stack buffer overflow in LocalizeRadix()#26490
Open
gladiator9797 wants to merge 2 commits intoprotocolbuffers:mainfrom
Open
Fix stack buffer overflow in LocalizeRadix()#26490gladiator9797 wants to merge 2 commits intoprotocolbuffers:mainfrom
gladiator9797 wants to merge 2 commits intoprotocolbuffers:mainfrom
Conversation
LocalizeRadix() uses strcpy() to copy the remainder of the input string into an 80-byte stack buffer without bounds checking. When parsing a floating-point number longer than ~78 characters in a locale where the radix character differs from '.', the strcpy overflows the buffer. The fix replaces the fixed-size stack buffer with a dynamically sized one (stack-allocated up to 256 bytes, heap-allocated for longer strings), and uses memcpy with explicit length instead of strcpy. Reproducer: LC_ALL=de_DE.UTF-8 Parse float string "1.000...001" with >80 characters -> AddressSanitizer: stack-buffer-overflow in LocalizeRadix (strtod.c:43)
3 tasks
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
LocalizeRadix()inupb/lex/strtod.cusesstrcpy()to copy the remainder of the input string into an 80-byte stack buffer (localized[80]) without bounds checking. When parsing a floating-point number longer than ~78 characters in a locale where the radix character differs from.(e.g.,de_DE,fr_FR), thestrcpyat line 43 overflows the buffer.Fix
strcpywithmemcpyusing explicit lengthinput_lentoLocalizeRadix()to avoid recomputing string lengthReproducer
ASAN output:
Test plan