From e9436d8c30e601d3d1baec40f6c9620f93ff89a0 Mon Sep 17 00:00:00 2001 From: Claudio DeSouza Date: Fri, 15 Nov 2024 14:32:11 +0000 Subject: [PATCH] [cr133] Unsafe variant of `String::FromUTF8` deleted The was only one caller for it. Unfortunately we will have to rely on an unsafe buffer read for this case, because we are retrieving this buffer from libxml. Chromium change: https://chromium.googlesource.com/chromium/src/+/f179e94443e0ba171f9b3be9c9a49ebf8e52c9a5 commit f179e94443e0ba171f9b3be9c9a49ebf8e52c9a5 Author: Kent Tamura Date: Thu Nov 14 13:32:48 2024 +0000 Spanification: Remove String::FromUTF8(const uint8_t*, size_t) We prefer FromUTF8(base::span). This CL has no behavior changes. Bug: 351564777 --- .../blink/renderer/core/brave_page_graph/page_graph.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/third_party/blink/renderer/core/brave_page_graph/page_graph.cc b/third_party/blink/renderer/core/brave_page_graph/page_graph.cc index 4c3b46f896bf..e859700e7b09 100644 --- a/third_party/blink/renderer/core/brave_page_graph/page_graph.cc +++ b/third_party/blink/renderer/core/brave_page_graph/page_graph.cc @@ -1181,7 +1181,11 @@ String PageGraph::ToGraphML() const { xmlChar* xml_string; int size; xmlDocDumpMemoryEnc(graphml_doc, &xml_string, &size, "UTF-8"); - auto graphml_string = String::FromUTF8(xml_string, size); + // SAFETY: unfortunately xmlDocDumpMemoryEnc is a C api that + // manages the buffer internally, so we have to rely on it for the + // pointer/size pair. + auto graphml_string = String::FromUTF8(base::as_bytes(UNSAFE_BUFFERS( + base::span(xml_string, base::checked_cast(size))))); DCHECK(!graphml_string.empty()); xmlFree(xml_string);