stack-buffer-overflow in decNumber#9019
Open
ChudaykinAlex wants to merge 1 commit intoFirebirdSQL:masterfrom
Open
stack-buffer-overflow in decNumber#9019ChudaykinAlex wants to merge 1 commit intoFirebirdSQL:masterfrom
ChudaykinAlex wants to merge 1 commit intoFirebirdSQL:masterfrom
Conversation
AlexPeshkoff
approved these changes
May 6, 2026
Contributor
Author
|
@AlexPeshkoff Good day. Should I write a unit test? |
Member
If you wish - please do. On the one hand result appears to be obvious, but additional test makes no harm. |
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.
Background
The QA team was running fuzz testing on the decimal floating-point arithmetic routines in the decNumber library. Three stable crash scenarios were identified, each terminating with a
stack-buffer-overflowerror (READ of size 4).Potentially on versions 3, 4, 5, and master
Affected files
lib/decBasic.cdecFloatAdd/decQuadAddlib/decCommon.cdecFinalize(fold-down path)How to reproduce
Clang
clang -g -O0 -fsanitize=address -I./lib \ lib/decContext.c lib/decNumber.c lib/decDouble.c lib/decQuad.c \ lib/decimal32.c lib/decimal64.c lib/decimal128.c lib/decPacked.c \ poc.c -o poc_runner ./poc_runner 1 # or 2, 3GCC
gcc -g -O0 -fsanitize=address -I./lib \ lib/decContext.c lib/decNumber.c lib/decDouble.c lib/decQuad.c \ lib/decimal32.c lib/decimal64.c lib/decimal128.c lib/decPacked.c \ poc.c -o poc_runner ./poc_runner 1 # or 2, 3All three cases crash consistently on the vulnerable code under ASan with both compilers.
poc.c
ASan stack traces
Case 1 — decQuadAdd
Case 2 — decDoubleReduce
Case 3 — decQuadReduce
Full
stack.txt
Changes
lib/decBasic.c— bug #1The tail-copy loop in
decFloatAddreads 4 bytes at a time, but the buffer was declared without headroom for that read. Extended by 4 bytes:lib/decCommon.c— bugs #2, #3The fold-down loop in
decFinalizeperformed a 4-byte read whens == ulsd, overflowing past the end of the caller's buffer. Split into a fast 4-byte pass (while safe) and a byte-wise tail:Verification
Clean exit with no
stack-buffer-overflowon both clang and gcc.