C++11 std::array rewrite for memory safety [3/19]
Split from:
https://chromium-review.googlesource.com/c/chromium/src/+/6004959/21
Generated patch
---------------
- Tool: ./tool/clang/spanify/rewrite-multiple-platform.sh
- Platform: Linux.
- Filter: This includes 2400/4222 patches. I included the std::array
ones and excluded build errors.
Google announcement:
--------------------
https://groups.google.com/a/google.com/g/chrome-memory-safety/c/RMiO4gaVLQA/m/Yz-3NCObAgAJ
Benchmarks:
----------
See design doc and
https://chromium-review.googlesource.com/c/chromium/src/+/6004959/21
Description
-----------
The consensus during the memory safety summit was to begin rewriting
relevant C-style arrays to C++11 std::array. It can be done immediately,
offers better developer ergonomics, and fix large chunks of the
-Wunsafe-buffer-usage errors in Chrome.
To clarify, this effort is complementary to the longer plan work with
enabling -fsanitize=array-bounds, and we plan to leverage both,
especially for protecting 3p code.
[Attached] is a document detailing the rationale, benefits, and
considerations for potential compile-time and performance impacts.
[Attached]:https://docs.google.com/document/d/1z5aBDg26lHmNDjXRCysElWKx7E4PAJXqykI_k7ondJI/edit?tab=t.0#heading=h.cqgo7wvp0kzt
NO_IFTTT=No need to update base/debug/stack_trace.h
Bug: 378069401
Change-Id: I3954f5f56075e55edadf8c00ad34fb858cbaacc6
R: [email protected]
AX-Relnotes: n/a.
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6043821
Commit-Queue: Daniel Cheng <[email protected]>
Auto-Submit: Arthur Sonzogni <[email protected]>
Reviewed-by: Daniel Cheng <[email protected]>
Owners-Override: Daniel Cheng <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1394426}
diff --git a/components/crx_file/id_util_unittest.cc b/components/crx_file/id_util_unittest.cc
index c60a81e..239bf37 100644
--- a/components/crx_file/id_util_unittest.cc
+++ b/components/crx_file/id_util_unittest.cc
@@ -6,12 +6,14 @@
#include <stdint.h>
+#include <array>
+
#include "testing/gtest/include/gtest/gtest.h"
namespace crx_file::id_util {
TEST(IDUtilTest, GenerateID) {
- const uint8_t public_key_info[] = {
+ const auto public_key_info = std::to_array<uint8_t>({
0x30, 0x81, 0x9f, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x81, 0x8d, 0x00, 0x30, 0x81,
0x89, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, 0x20, 0xdc, 0x7c, 0x9b,
@@ -25,7 +27,8 @@
0x84, 0x32, 0x33, 0xf3, 0x17, 0x49, 0xbf, 0xe9, 0x96, 0xd0, 0xd6, 0x14,
0x6f, 0x13, 0x8d, 0xc5, 0xfc, 0x2c, 0x72, 0xba, 0xac, 0xea, 0x7e, 0x18,
0x53, 0x56, 0xa6, 0x83, 0xa2, 0xce, 0x93, 0x93, 0xe7, 0x1f, 0x0f, 0xe6,
- 0x0f, 0x02, 0x03, 0x01, 0x00, 0x01};
+ 0x0f, 0x02, 0x03, 0x01, 0x00, 0x01,
+ });
std::string extension_id =
GenerateId(std::string(reinterpret_cast<const char*>(&public_key_info[0]),
std::size(public_key_info)));