Skip to content

Commit

Permalink
[cr133] Unsafe variant of String::FromUTF8 deleted
Browse files Browse the repository at this point in the history
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 <[email protected]>
Date:   Thu Nov 14 13:32:48 2024 +0000

    Spanification: Remove String::FromUTF8(const uint8_t*, size_t)

    We prefer FromUTF8(base::span<const uint8_t>).
    This CL has no behavior changes.

    Bug: 351564777
  • Loading branch information
cdesouza-chromium committed Nov 15, 2024
1 parent 407ce97 commit e9436d8
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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_t>(size)))));
DCHECK(!graphml_string.empty());

xmlFree(xml_string);
Expand Down

0 comments on commit e9436d8

Please sign in to comment.