Skip to content

Fix segfault in number_to_string when locale uses comma decimal - #23

Open
GoigA wants to merge 1 commit into
aburch:masterfrom
GoigA:fix-number-to-string-decimal-comma
Open

GoigA wants to merge 1 commit into
aburch:masterfrom
GoigA:fix-number-to-string-decimal-comma

Conversation

@GoigA

@GoigA GoigA commented Sep 14, 2026

Copy link
Copy Markdown

Under locales that format floating-point numbers with a comma (such as de_DE or pt_BR), sprintf(tp, "%.*f", ...) outputs numbers like "1234,50".

In number_to_string(), it only searches for a dot via strchr(tp, '.'). When that returns NULL, the pointer subtraction (NULL - tp) underflows into a huge size_t, which makes the while (i < l) loop write thousand separators past the stack frame until triggering a SIGSEGV in memcpy.

This patch checks for both . and , when locating the decimal separator to prevent the underflow.

@GoigA GoigA changed the title Fix stack buffer overflow / SIGSEGV in number_to_string under comma-decimal locales Fix segfault in number_to_string when locale uses comma decimal Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant