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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2345633007: Don't overflow in LayoutText::width() on a huge length. (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 } 1568 }
1569 1569
1570 m_containsReversedText |= !s->isLeftToRightDirection(); 1570 m_containsReversedText |= !s->isLeftToRightDirection();
1571 } 1571 }
1572 1572
1573 float LayoutText::width(unsigned from, unsigned len, LayoutUnit xPos, TextDirect ion textDirection, bool firstLine, HashSet<const SimpleFontData*>* fallbackFonts , FloatRect* glyphBounds) const 1573 float LayoutText::width(unsigned from, unsigned len, LayoutUnit xPos, TextDirect ion textDirection, bool firstLine, HashSet<const SimpleFontData*>* fallbackFonts , FloatRect* glyphBounds) const
1574 { 1574 {
1575 if (from >= textLength()) 1575 if (from >= textLength())
1576 return 0; 1576 return 0;
1577 1577
1578 if (from + len > textLength()) 1578 if (len > textLength() || from + len > textLength())
1579 len = textLength() - from; 1579 len = textLength() - from;
1580 1580
1581 return width(from, len, style(firstLine)->font(), xPos, textDirection, fallb ackFonts, glyphBounds); 1581 return width(from, len, style(firstLine)->font(), xPos, textDirection, fallb ackFonts, glyphBounds);
1582 } 1582 }
1583 1583
1584 float LayoutText::width(unsigned from, unsigned len, const Font& f, LayoutUnit x Pos, TextDirection textDirection, HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* glyphBounds) const 1584 float LayoutText::width(unsigned from, unsigned len, const Font& f, LayoutUnit x Pos, TextDirection textDirection, HashSet<const SimpleFontData*>* fallbackFonts, FloatRect* glyphBounds) const
1585 { 1585 {
1586 ASSERT(from + len <= textLength()); 1586 ASSERT(from + len <= textLength());
1587 if (!textLength()) 1587 if (!textLength())
1588 return 0; 1588 return 0;
1589 1589
1590 // TODO(wkorman): Incorporate constraints around |from| and |len| in the pre ceding variant of width() here.
wkorman 2016/09/17 00:17:22 Seeking feedback on this. AFAICT this method varia
eae 2016/09/17 08:35:51 The other method calls this one with style(firstLi
wkorman 2016/09/17 21:16:42 That's true, but this method is exposed and can be
1591
1590 float w; 1592 float w;
1591 if (&f == &style()->font()) { 1593 if (&f == &style()->font()) {
1592 if (!style()->preserveNewline() && !from && len == textLength()) { 1594 if (!style()->preserveNewline() && !from && len == textLength()) {
1593 if (fallbackFonts) { 1595 if (fallbackFonts) {
1594 ASSERT(glyphBounds); 1596 ASSERT(glyphBounds);
1595 if (preferredLogicalWidthsDirty() || !m_knownToHaveNoOverflowAnd NoFallbackFonts) 1597 if (preferredLogicalWidthsDirty() || !m_knownToHaveNoOverflowAnd NoFallbackFonts)
1596 const_cast<LayoutText*>(this)->computePreferredLogicalWidths (0, *fallbackFonts, *glyphBounds); 1598 const_cast<LayoutText*>(this)->computePreferredLogicalWidths (0, *fallbackFonts, *glyphBounds);
1597 else 1599 else
1598 *glyphBounds = FloatRect(0, -f.getFontMetrics().floatAscent( ), m_maxWidth, f.getFontMetrics().floatHeight()); 1600 *glyphBounds = FloatRect(0, -f.getFontMetrics().floatAscent( ), m_maxWidth, f.getFontMetrics().floatHeight());
1599 w = m_maxWidth; 1601 w = m_maxWidth;
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1809 LayoutRect rect = 1811 LayoutRect rect =
1810 LayoutRect(IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox. height())); 1812 LayoutRect(IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox. height()));
1811 LayoutBlock* block = containingBlock(); 1813 LayoutBlock* block = containingBlock();
1812 if (block && hasTextBoxes()) 1814 if (block && hasTextBoxes())
1813 block->adjustChildDebugRect(rect); 1815 block->adjustChildDebugRect(rect);
1814 1816
1815 return rect; 1817 return rect;
1816 } 1818 }
1817 1819
1818 } // namespace blink 1820 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/BUILD.gn ('k') | third_party/WebKit/Source/core/layout/LayoutTextTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698