Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 0fd61004f1b1dcb44797e0e0059910b47be12b85
https://github.com/WebKit/WebKit/commit/0fd61004f1b1dcb44797e0e0059910b47be12b85
Author: Ahmad Saleem <[email protected]>
Date: 2026-08-20 (Thu, 20 Aug 2026)
Changed paths:
M Source/WebCore/platform/graphics/IntSize.h
M Tools/TestWebKitAPI/Tests/WebCore/IntSizeTests.cpp
Log Message:
-----------
IntSize::area() and IntSize::unclampedArea() invoke undefined behavior via
std::abs(INT_MIN)
https://bugs.webkit.org/show_bug.cgi?id=322149
rdar://185369722
Reviewed by Chris Dumez.
std::abs() on INT_MIN is undefined behavior, since the result is not
representable in int. Both area() and unclampedArea() call it directly on
m_width and m_height.
INT_MIN is reachable: OffscreenCanvas exposes its dimensions as [EnforceRange]
unsigned long and narrows them to int, so new OffscreenCanvas(0x80000000, 1)
stores a width of INT_MIN, and drawing into it reaches unclampedArea() through
CanvasBase::validateArea(). unclampedArea() then returns a garbage value, and
area() crashes because Checked<unsigned, CrashOnOverflow> rejects the negative
result.
Multiply in int64_t before taking the absolute value. The product of two ints
always fits in int64_t, so std::abs() is well defined for every input, and
area() can just bounds-check that product on its way into Checked<unsigned>.
Canvas behavior is unchanged: both the old and corrected areas exceed
maxCanvasArea(), so allocation still fails.
Test: Tools/TestWebKitAPI/Tests/WebCore/IntSizeTests.cpp
* Source/WebCore/platform/graphics/IntSize.h:
(WebCore::IntSize::area const):
(WebCore::IntSize::unclampedArea const):
* Tools/TestWebKitAPI/Tests/WebCore/IntSizeTests.cpp:
(TestWebKitAPI::TEST(IntSize, UnclampedArea)):
Canonical link: https://commits.webkit.org/319574@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications