Commit 6127fe58 authored by Darwin Huang's avatar Darwin Huang Committed by Commit Bot

Clipboard API: Add nullptr check to avoid DCHECK renderer crash.

Return early if utf_text.data() == nullptr. utf_text.data() can be
nullptr if the Clipboard was empty. Previously, this would trigger a
DCHECK in Blob::Create().

Tested manually using `pbcopy < /dev/null`, as per bug repro steps.
Unfortunately, Chrome's test infra doesn't seem to have a way to
simulate clearing the clipboard. Therefore, there isn't an automated
test being added here to verify this behavior.

Bug: 1071279
Change-Id: I95cdc6ed2df25394ca1ffa78d4cde96782d9a10f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2151132
Commit-Queue: Darwin Huang <huangdarwin@chromium.org>
Reviewed-by: default avatarMarijn Kruisselbrink <mek@chromium.org>
Reviewed-by: default avatarVictor Costan <pwnall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#759794}
parent 5c5a80dc
......@@ -55,6 +55,9 @@ class ClipboardTextReader final : public ClipboardReader {
Blob* ReadFromSystem() override {
String plain_text =
system_clipboard()->ReadPlainText(mojom::ClipboardBuffer::kStandard);
// |plain_text| is empty if the clipboard is empty.
if (plain_text.IsEmpty())
return nullptr;
// Encode WTF String to UTF-8, the standard text format for blobs.
StringUTF8Adaptor utf_text(plain_text);
......
......@@ -25,6 +25,7 @@ class ClipboardReader : public GarbageCollected<ClipboardReader> {
const String& mime_type);
virtual ~ClipboardReader();
// Returns nullptr if the data is empty or invalid.
virtual Blob* ReadFromSystem() = 0;
void Trace(Visitor* visitor);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment