From 7e0af1d4d45b526f01677e74a56f4a951b70517d Mon Sep 17 00:00:00 2001 From: danakj Date: Thu, 11 Apr 2024 12:48:02 -0400 Subject: [PATCH] Use byte conversions over the byte swap functions base/sys_byteorder.h is going away. Instead, use the byte conversions in base::numerics to convert from a byte array in big endian to an integer. This avoids putting big endian data into integer types at all. mini_chromium was rolled and crashpad updated to work with newer mac/windows toolchains in order to support C++20 in f9cee5c147db30dc8fa1a048aabd165965b5cb60. Bug: 40284755 Change-Id: If690847b7aa54b0216e73ec297eae3d0bca2fa57 Reviewed-on: https://chromium-review.googlesource.com/c/crashpad/crashpad/+/5402184 Commit-Queue: danakj Reviewed-by: Mark Mentovai --- util/misc/uuid.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/util/misc/uuid.cc b/util/misc/uuid.cc index 15870709..3013d7b2 100644 --- a/util/misc/uuid.cc +++ b/util/misc/uuid.cc @@ -23,13 +23,15 @@ #include #include +#include #include #include +#include "base/containers/span.h" +#include "base/numerics/byte_conversions.h" #include "base/rand_util.h" #include "base/strings/stringprintf.h" #include "base/strings/utf_string_conversions.h" -#include "base/sys_byteorder.h" #include "build/build_config.h" #if BUILDFLAG(IS_APPLE) @@ -53,11 +55,15 @@ void UUID::InitializeToZero() { memset(this, 0, sizeof(*this)); } -void UUID::InitializeFromBytes(const uint8_t* bytes) { - memcpy(this, bytes, sizeof(*this)); - data_1 = base::NetToHost32(data_1); - data_2 = base::NetToHost16(data_2); - data_3 = base::NetToHost16(data_3); +void UUID::InitializeFromBytes(const uint8_t* bytes_ptr) { + // TODO(crbug.com/40284755): This span construction is unsound. The caller + // should provide a span instead of an unbounded pointer. + base::span bytes(bytes_ptr, sizeof(UUID)); + data_1 = base::numerics::U32FromBigEndian(bytes.subspan<0u, 4u>()); + data_2 = base::numerics::U16FromBigEndian(bytes.subspan<4u, 2u>()); + data_3 = base::numerics::U16FromBigEndian(bytes.subspan<6u, 2u>()); + std::ranges::copy(bytes.subspan<8u, 2u>(), data_4); + std::ranges::copy(bytes.subspan<10u, 6u>(), data_5); } bool UUID::InitializeFromString(const base::StringPiece& string) {