diff --git a/remoting/host/clipboard_win.cc b/remoting/host/clipboard_win.cc index 50665c3352c7e..b29dee564fcba 100644 --- a/remoting/host/clipboard_win.cc +++ b/remoting/host/clipboard_win.cc @@ -231,7 +231,11 @@ void ClipboardWin::OnClipboardUpdate() { LOG(WARNING) << "Couldn't lock clipboard data: " << GetLastError(); return; } - text.assign(text_lock.data()); + // CF_UNICODETEXT placed by other processes is not guaranteed to be + // NUL-terminated; bound the read by the HGLOBAL size and then trim at + // the first embedded NUL (matches ui/base/clipboard/clipboard_win.cc). + const size_t max_chars = text_lock.size() / sizeof(WCHAR); + text.assign(text_lock.data(), wcsnlen(text_lock.data(), max_chars)); } protocol::ClipboardEvent event;