From e125569f87e451277b47e4abe1107ab37f8836ed Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 26 Jul 2018 18:38:17 +0900 Subject: [PATCH] fix: check string encoding before creating value (#13815) --- brightray/browser/inspectable_web_contents_impl.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/brightray/browser/inspectable_web_contents_impl.cc b/brightray/browser/inspectable_web_contents_impl.cc index 2f682b021a..426df497c6 100644 --- a/brightray/browser/inspectable_web_contents_impl.cc +++ b/brightray/browser/inspectable_web_contents_impl.cc @@ -167,14 +167,18 @@ int ResponseWriter::Initialize(const net::CompletionCallback& callback) { int ResponseWriter::Write(net::IOBuffer* buffer, int num_bytes, const net::CompletionCallback& callback) { - auto* id = new base::Value(stream_id_); - base::Value* chunk = new base::Value(std::string(buffer->data(), num_bytes)); + std::string chunk = std::string(buffer->data(), num_bytes); + if (!base::IsStringUTF8(chunk)) + return num_bytes; + + base::Value* id = new base::Value(stream_id_); + base::Value* chunk_value = new base::Value(chunk); content::BrowserThread::PostTask( content::BrowserThread::UI, FROM_HERE, base::BindOnce(&InspectableWebContentsImpl::CallClientFunction, bindings_, "DevToolsAPI.streamWrite", base::Owned(id), - base::Owned(chunk), nullptr)); + base::Owned(chunk_value), nullptr)); return num_bytes; }