Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 44592cdcc791dd1e6fb2ce283834b34ad4722013
      
https://github.com/WebKit/WebKit/commit/44592cdcc791dd1e6fb2ce283834b34ad4722013
  Author: Ahmad Saleem <[email protected]>
  Date:   2026-07-23 (Thu, 23 Jul 2026)

  Changed paths:
    M Source/WTF/wtf/text/WTFString.cpp
    M Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp

  Log Message:
  -----------
  charactersToFloat() reports success even when a value fits a double but 
overflows a float
https://bugs.webkit.org/show_bug.cgi?id=320069
rdar://182991785

Reviewed by Chris Dumez.

charactersToFloat() parses into a double and then narrows the result to
float with a plain static_cast, but the "ok" flag it reports back was set
purely from whether the double parse succeeded. A string like "1e300"
parses to a finite double, so ok was reported true, even though casting
that double to float overflows to infinity. Callers had no way to tell
the float result was bogus.

Added doubleToFloatCheckingOverflow(), which clears the out-param when
the double was finite but the narrowed float is not, and use it from
both bool*-returning overloads of charactersToFloat(). The two
parsedLength-returning overloads take no ok out-param, so there is
nothing for them to report and they are unchanged aside from dropping
the now-inaccurate FIXME.

Test: Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp

* Source/WTF/wtf/text/WTFString.cpp:
(WTF::doubleToFloatCheckingOverflow):
(WTF::charactersToFloat):
* Tools/TestWebKitAPI/Tests/WTF/WTFString.cpp:
(TestWebKitAPI::TEST(WTF, StringToFloat)):

Canonical link: https://commits.webkit.org/317828@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to