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

Unified Diff: ui/base/clipboard/clipboard_win.cc

Issue 2834893002: Ensure ClipboardWin::ReadHTML does not crash on embedded nulls (Closed)
Patch Set: Fix off-by-one Created 3 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/base/clipboard/clipboard_win.cc
diff --git a/ui/base/clipboard/clipboard_win.cc b/ui/base/clipboard/clipboard_win.cc
index ae892c9c0faa8b985aaeb342fb0e018fd5b852e4..cb28043e34bfdbd37fc100555071dc51c5808dad 100644
--- a/ui/base/clipboard/clipboard_win.cc
+++ b/ui/base/clipboard/clipboard_win.cc
@@ -568,8 +568,13 @@ void ClipboardWin::ReadHTML(ClipboardType type,
offsets.push_back(end_index - html_start);
markup->assign(base::UTF8ToUTF16AndAdjustOffsets(cf_html.data() + html_start,
&offsets));
- *fragment_start = base::checked_cast<uint32_t>(offsets[0]);
- *fragment_end = base::checked_cast<uint32_t>(offsets[1]);
+ // Ensure the Fragment points within the string; see https://crbug.com/607181.
+ size_t markup_end = markup->length();
+ *fragment_end =
+ base::checked_cast<uint32_t>(std::min(offsets[1], markup_end));
+ *fragment_start =
+ std::min(*fragment_end,
+ base::checked_cast<uint32_t>(std::min(offsets[0], markup_end)));
dcheng 2017/04/26 15:19:10 Nit: I think that if one were to be clever, that t
elawrence 2017/04/26 15:33:44 Yeah, I'd had it that way originally, but clang wo
}
void ClipboardWin::ReadRTF(ClipboardType type, std::string* result) const {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698