libstdc++: Fix std::from_chars to not read past end of input [PR127666]
Corrects std::from_chars to prevent out-of-bounds reads from the input buffer.
The std::from_chars function for floating-point conversions has been fixed to avoid reading past the end of the input character sequence. This resolves potential out-of-bounds reads, improving the safety and correctness of string-to-float conversions. A new test case has been added to verify this fix.
In Details
This commit addresses a correctness issue in std::from_chars for floating-point types, specifically related to how it handles the end of the input buffer. The implementation previously had logic that could lead to reading past the provided buffer boundary under certain conditions, constituting an out-of-bounds read. The fix modifies the parsing logic to strictly adhere to the input buffer limits, preventing these erroneous reads. A new test case specifically targets this vulnerability.
- std::from_chars
- A C++17 function that performs locale-independent conversions between character sequences and arithmetic types. It offers high performance and avoids locale-related overhead.
- out-of-bounds read
- An attempt to access memory at an address that is outside the allocated bounds of a buffer or array, which can lead to undefined behavior, crashes, or security vulnerabilities.
- floating-point conversion
- The process of converting a sequence of characters (representing a number) into a floating-point data type (e.g., float, double).