GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
libstdc++

libstdc++: Fix stack corruption in std::bitset stream extraction

Fixes stack corruption in `std::bitset::operator>>` by replacing `__builtin_alloca` with a stack array.

This commit resolves a stack corruption vulnerability in the stream extraction operator (operator>>) for std::bitset. The issue was caused by an incorrect argument to __builtin_alloca, which did not properly account for the size or alignment of wide characters. The fix replaces __builtin_alloca with a stack-allocated array, ensuring correct memory management and preventing stack corruption.

In Details

The operator>> for std::bitset used __builtin_alloca with an argument that did not consider _CharT's size and alignment, potentially leading to stack overflows or corruption. This commit replaces __builtin_alloca with a fixed-size array _CharT[N] for small cases or a heap allocation for larger inputs, making the extraction safer.

For Context
std::bitset
A C++ standard library class that stores a fixed-size sequence of bits.
stream extraction
The process of reading data from an input stream (e.g., std::cin, std::ifstream) into a variable, typically using the >> operator.
__builtin_alloca
A compiler intrinsic function that allocates memory on the stack. Its usage requires careful consideration of size and alignment to avoid stack corruption.
stack corruption
An error where data on the program's call stack is overwritten, potentially leading to crashes or security vulnerabilities.
Filed Under: libstdc++securitybugfix