diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 20:28:17 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-04-19 20:28:17 +0000 |
commit | 6c9d9b18c4cf4112d2b6f113ab7b19b35e083743 (patch) | |
tree | 64419d6ecccbd607e431a9ee0b6d22444ad88585 /gfx/canvas_win.cc | |
parent | 03a61e3d6731a54293958f2583d33d063e798af2 (diff) | |
download | chromium_src-6c9d9b18c4cf4112d2b6f113ab7b19b35e083743.zip chromium_src-6c9d9b18c4cf4112d2b6f113ab7b19b35e083743.tar.gz chromium_src-6c9d9b18c4cf4112d2b6f113ab7b19b35e083743.tar.bz2 |
Clamp the maximum amount of text we'll draw to 32K characters, since higher values have been found to trigger bugs in DrawText().
BUG=41978
TEST=Visit "http://jssh.skypher.com/4.4/Main.html?command%3Dalert(new%20Array(0xffff).join("A"))&execute" (no quotes). Message box should have text in it.
Review URL: http://codereview.chromium.org/1660011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@44944 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'gfx/canvas_win.cc')
-rw-r--r-- | gfx/canvas_win.cc | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/gfx/canvas_win.cc b/gfx/canvas_win.cc index be9756a..afee919 100644 --- a/gfx/canvas_win.cc +++ b/gfx/canvas_win.cc @@ -142,7 +142,7 @@ void Canvas::SizeStringInt(const std::wstring& text, // Clamp the max amount of text we'll measure to 2K. When the string is // actually drawn, it will be clipped to whatever size box is provided, and // the time to do that doesn't depend on the length being clipped off. - const int kMaxStringLength = 2048; + const int kMaxStringLength = 2048 - 1; // So the trailing \0 fits in 2K. std::wstring clamped_string(text.substr(0, kMaxStringLength)); if (*width == 0) { @@ -179,6 +179,13 @@ void Canvas::DrawStringInt(const std::wstring& text, HFONT font, if (!IntersectsClipRectInt(x, y, w, h)) return; + // Clamp the max amount of text we'll draw to 32K. There seem to be bugs in + // DrawText() if you e.g. ask it to character-break a no-whitespace string of + // length > 43680 (for which it draws nothing), and since we clamped to 2K in + // SizeStringInt() we're unlikely to be able to display this much anyway. + const int kMaxStringLength = 32768 - 1; // So the trailing \0 fits in 32K. + std::wstring clamped_string(text.substr(0, kMaxStringLength)); + RECT text_bounds = { x, y, x + w, y + h }; HDC dc = beginPlatformPaint(); SetBkMode(dc, TRANSPARENT); @@ -187,8 +194,8 @@ void Canvas::DrawStringInt(const std::wstring& text, HFONT font, SkColorGetB(color)); SetTextColor(dc, brush_color); - int f = ComputeFormatFlags(flags, text); - DoDrawText(dc, text, &text_bounds, f); + int f = ComputeFormatFlags(flags, clamped_string); + DoDrawText(dc, clamped_string, &text_bounds, f); endPlatformPaint(); // Restore the old font. This way we don't have to worry if the caller |