Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(311)

Unified Diff: third_party/WebKit/Source/core/layout/LayoutBox.h

Issue 2716583002: Avoid negative content box sizes. (Closed)
Patch Set: code review Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/layout/LayoutBox.h
diff --git a/third_party/WebKit/Source/core/layout/LayoutBox.h b/third_party/WebKit/Source/core/layout/LayoutBox.h
index ca26cdbff78eeb24b3482ae0b87951d8a4fbbdd2..67e817e0b29cdefacbebf085cecfaa31323363da 100644
--- a/third_party/WebKit/Source/core/layout/LayoutBox.h
+++ b/third_party/WebKit/Source/core/layout/LayoutBox.h
@@ -491,10 +491,24 @@ class CORE_EXPORT LayoutBox : public LayoutBoxModelObject {
void updateLayerTransformAfterLayout();
DISABLE_CFI_PERF LayoutUnit contentWidth() const {
- return clientWidth() - paddingLeft() - paddingRight();
+ // We're dealing with LayoutUnit and saturated arithmetic here, so we need
+ // to guard against negative results. The value returned from clientWidth()
+ // may in itself be a victim of saturated arithmetic; e.g. if both border
+ // sides were sufficiently wide (close to LayoutUnit::max()). Here we
+ // subtract two padding values from that result, which is another source of
+ // saturated arithmetic.
+ return (clientWidth() - paddingLeft() - paddingRight())
+ .clampNegativeToZero();
}
DISABLE_CFI_PERF LayoutUnit contentHeight() const {
- return clientHeight() - paddingTop() - paddingBottom();
+ // We're dealing with LayoutUnit and saturated arithmetic here, so we need
+ // to guard against negative results. The value returned from clientHeight()
+ // may in itself be a victim of saturated arithmetic; e.g. if both border
+ // sides were sufficiently wide (close to LayoutUnit::max()). Here we
+ // subtract two padding values from that result, which is another source of
+ // saturated arithmetic.
+ return (clientHeight() - paddingTop() - paddingBottom())
+ .clampNegativeToZero();
}
LayoutSize contentSize() const {
return LayoutSize(contentWidth(), contentHeight());

Powered by Google App Engine
This is Rietveld 408576698