diff --git a/base/tools_sanity_unittest.cc b/base/tools_sanity_unittest.cc index 8a6e00aa712..1c83aa55027 100644 --- a/base/tools_sanity_unittest.cc +++ b/base/tools_sanity_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "testing/gtest/include/gtest/gtest.h" namespace base { diff --git a/browser/brave_ads/device_id/device_id_impl_linux.cc b/browser/brave_ads/device_id/device_id_impl_linux.cc index 36336080f2d..c4f937eb042 100644 --- a/browser/brave_ads/device_id/device_id_impl_linux.cc +++ b/browser/brave_ads/device_id/device_id_impl_linux.cc @@ -113,8 +113,8 @@ class MacAddressProcessor { } constexpr size_t kMacLength = 6u; - auto mac_address_bytes = - base::as_bytes(base::make_span(ifinfo.ifr_hwaddr.sa_data, kMacLength)); + auto mac_address_bytes = base::as_bytes( + UNSAFE_TODO(base::make_span(ifinfo.ifr_hwaddr.sa_data, kMacLength))); if (!is_valid_mac_address_callback_.Run(mac_address_bytes)) { return keep_going; } @@ -137,7 +137,7 @@ class MacAddressProcessor { const char* const prefixes[], size_t prefixes_count) { for (size_t i = 0; i < prefixes_count; i++) { - if (strncmp(prefixes[i], name, strlen(prefixes[i])) == 0) { + if (UNSAFE_TODO(strncmp(prefixes[i], name, strlen(prefixes[i]))) == 0) { return true; } } diff --git a/browser/brave_ads/device_id/device_id_impl_mac.cc b/browser/brave_ads/device_id/device_id_impl_mac.cc index 4b3577faecd..58d859bd9be 100644 --- a/browser/brave_ads/device_id/device_id_impl_mac.cc +++ b/browser/brave_ads/device_id/device_id_impl_mac.cc @@ -58,7 +58,7 @@ std::string FindBSDNameOfSystemDisk() { std::string root_bsd_name; for (int i = 0; i < count; i++) { - const struct statfs& volume = mounted_volumes[i]; + const struct statfs& volume = UNSAFE_TODO(mounted_volumes[i]); if (std::string(volume.f_mntonname) == kRootDirectory) { root_bsd_name = std::string(volume.f_mntfromname); break; @@ -138,9 +138,9 @@ class MacAddressProcessor { return keep_going; } - auto mac_address_bytes = base::as_bytes(base::make_span( + auto mac_address_bytes = base::as_bytes(UNSAFE_TODO(base::make_span( CFDataGetBytePtr(mac_address_data.get()), - base::checked_cast(CFDataGetLength(mac_address_data.get())))); + base::checked_cast(CFDataGetLength(mac_address_data.get()))))); if (!is_valid_mac_address_callback_.Run(mac_address_bytes)) { return keep_going; } diff --git a/browser/brave_ads/device_id/device_id_impl_win.cc b/browser/brave_ads/device_id/device_id_impl_win.cc index bba7b3aab66..e495fe8d21b 100644 --- a/browser/brave_ads/device_id/device_id_impl_win.cc +++ b/browser/brave_ads/device_id/device_id_impl_win.cc @@ -165,7 +165,7 @@ std::string GetMacAddressFromGetIfTable2( MacAddressProcessor processor(std::move(is_valid_mac_address_callback)); for (size_t i = 0; i < if_table->NumEntries; i++) { - processor.ProcessInterfaceRow(&(if_table->Table[i])); + processor.ProcessInterfaceRow(&UNSAFE_TODO((if_table->Table[i]))); } if (if_table != NULL) { diff --git a/browser/brave_shields/ad_block_service_browsertest.cc b/browser/brave_shields/ad_block_service_browsertest.cc index 49b63d48e35..c16b1b10c5a 100644 --- a/browser/brave_shields/ad_block_service_browsertest.cc +++ b/browser/brave_shields/ad_block_service_browsertest.cc @@ -208,7 +208,7 @@ base::FilePath AdBlockServiceTest::MakeFileInTempDir( base::File::FLAG_WRITE | base::File::FLAG_READ); EXPECT_TRUE(list_file.IsValid()); - list_file.Write(0, contents.c_str(), contents.size()); + UNSAFE_TODO(list_file.Write(0, contents.c_str(), contents.size())); list_file.Close(); temp_dirs_.push_back(std::move(dir)); diff --git a/browser/brave_stats/brave_stats_updater_browsertest.cc b/browser/brave_stats/brave_stats_updater_browsertest.cc index a72db3412cb..4b39c0df8a1 100644 --- a/browser/brave_stats/brave_stats_updater_browsertest.cc +++ b/browser/brave_stats/brave_stats_updater_browsertest.cc @@ -162,7 +162,8 @@ IN_PROC_BROWSER_TEST_F(BraveStatsUpdaterBrowserTest, WaitForStandardStatsUpdatedCallback(); // We get //1/usage/brave-core here, so ignore the first slash. - EXPECT_STREQ(GetUpdateURL().path().c_str() + 1, "/1/usage/brave-core"); + EXPECT_STREQ(UNSAFE_TODO(GetUpdateURL().path().c_str() + 1), + "/1/usage/brave-core"); // First check preference should now be true EXPECT_TRUE(g_browser_process->local_state()->GetBoolean(kFirstCheckMade)); diff --git a/browser/default_protocol_handler_utils_win.cc b/browser/default_protocol_handler_utils_win.cc index d7c173336ce..5202792c7a6 100644 --- a/browser/default_protocol_handler_utils_win.cc +++ b/browser/default_protocol_handler_utils_win.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/browser/default_protocol_handler_utils_win.h" #include diff --git a/browser/ephemeral_storage/ephemeral_storage_qa_browsertest.cc b/browser/ephemeral_storage/ephemeral_storage_qa_browsertest.cc index 7af788a7fe4..fcd10dfcfa3 100644 --- a/browser/ephemeral_storage/ephemeral_storage_qa_browsertest.cc +++ b/browser/ephemeral_storage/ephemeral_storage_qa_browsertest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "base/feature_list.h" #include "base/memory/raw_ptr.h" #include "base/path_service.h" diff --git a/browser/farbling/brave_screen_farbling_browsertest.cc b/browser/farbling/brave_screen_farbling_browsertest.cc index 45f2a853646..11313c1a122 100644 --- a/browser/farbling/brave_screen_farbling_browsertest.cc +++ b/browser/farbling/brave_screen_farbling_browsertest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include #include "base/files/file_path.h" diff --git a/browser/net/brave_site_hacks_network_delegate_helper_browsertest.cc b/browser/net/brave_site_hacks_network_delegate_helper_browsertest.cc index 8b10a73dc76..867709d75c5 100644 --- a/browser/net/brave_site_hacks_network_delegate_helper_browsertest.cc +++ b/browser/net/brave_site_hacks_network_delegate_helper_browsertest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include #include "base/base64url.h" diff --git a/browser/permissions/permission_manager_browsertest.cc b/browser/permissions/permission_manager_browsertest.cc index bfb6c85fed3..845e67268f3 100644 --- a/browser/permissions/permission_manager_browsertest.cc +++ b/browser/permissions/permission_manager_browsertest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "base/command_line.h" #include "base/feature_list.h" #include "base/functional/bind.h" diff --git a/browser/ui/views/brave_ads/color_util.cc b/browser/ui/views/brave_ads/color_util.cc index 2bf0fdba16a..f88d4a6a4a4 100644 --- a/browser/ui/views/brave_ads/color_util.cc +++ b/browser/ui/views/brave_ads/color_util.cc @@ -5,6 +5,7 @@ #include "brave/browser/ui/views/brave_ads/color_util.h" +#include "base/compiler_specific.h" #include "base/strings/string_number_conversions.h" namespace brave_ads { @@ -28,7 +29,7 @@ bool RgbStringToSkColor(std::string_view rgb, SkColor* color) { &component)) { return false; } - components[i] = component; + UNSAFE_TODO(components[i] = component); } *color = SkColorSetRGB(components[0], components[1], components[2]); diff --git a/browser/ui/views/infobars/web_discovery_infobar_content_view.cc b/browser/ui/views/infobars/web_discovery_infobar_content_view.cc index eb02b64d3d3..4edc4afeb24 100644 --- a/browser/ui/views/infobars/web_discovery_infobar_content_view.cc +++ b/browser/ui/views/infobars/web_discovery_infobar_content_view.cc @@ -128,7 +128,8 @@ class OkButton : public views::LabelButton { ui::NativeTheme::GetInstanceForNativeUi()->ShouldUseDarkColors(); SetBackground(CreateBackgroundFromPainter( views::Painter::CreateRoundRectWith1PxBorderPainter( - kBgColor[theme][GetVisualState()], SK_ColorTRANSPARENT, 100))); + UNSAFE_TODO(kBgColor[theme][GetVisualState()]), SK_ColorTRANSPARENT, + 100))); } void OnThemeChanged() override { diff --git a/browser/ui/webui/ai_chat/ai_chat_ui.cc b/browser/ui/webui/ai_chat/ai_chat_ui.cc index cbf0ea8adc4..47c3d0914b8 100644 --- a/browser/ui/webui/ai_chat/ai_chat_ui.cc +++ b/browser/ui/webui/ai_chat/ai_chat_ui.cc @@ -69,7 +69,7 @@ AIChatUI::AIChatUI(content::WebUI* web_ui) webui::SetupWebUIDataSource( untrusted_source, - base::make_span(kAiChatUiGenerated, kAiChatUiGeneratedSize), + UNSAFE_TODO(base::make_span(kAiChatUiGenerated, kAiChatUiGeneratedSize)), IDR_CHAT_UI_HTML); untrusted_source->AddResourcePath("styles.css", IDR_CHAT_UI_CSS); diff --git a/browser/ui/webui/brave_rewards/rewards_page_data_source.cc b/browser/ui/webui/brave_rewards/rewards_page_data_source.cc index 05222ed77d3..fa7bc39344a 100644 --- a/browser/ui/webui/brave_rewards/rewards_page_data_source.cc +++ b/browser/ui/webui/brave_rewards/rewards_page_data_source.cc @@ -294,7 +294,9 @@ void CreateAndAddRewardsPageDataSource(content::WebUI& web_ui, auto* source = content::WebUIDataSource::CreateAndAdd(browser_context, host); webui::SetupWebUIDataSource( - source, base::make_span(kRewardsPageGenerated, kRewardsPageGeneratedSize), + source, + UNSAFE_TODO( + base::make_span(kRewardsPageGenerated, kRewardsPageGeneratedSize)), IDR_NEW_BRAVE_REWARDS_PAGE_HTML); // Adaptive captcha challenges are displayed in an iframe on the Rewards diff --git a/browser/ui/webui/brave_rewards/rewards_panel_ui.cc b/browser/ui/webui/brave_rewards/rewards_panel_ui.cc index a5e7b249fb2..2864b97f50a 100644 --- a/browser/ui/webui/brave_rewards/rewards_panel_ui.cc +++ b/browser/ui/webui/brave_rewards/rewards_panel_ui.cc @@ -170,10 +170,11 @@ RewardsPanelUI::RewardsPanelUI(content::WebUI* web_ui) web_ui->GetWebContents()->GetBrowserContext(), kBraveRewardsPanelHost); source->AddLocalizedStrings(kStrings); - webui::SetupWebUIDataSource(source, - base::make_span(kBraveRewardsPanelGenerated, - kBraveRewardsPanelGeneratedSize), - IDR_BRAVE_REWARDS_PANEL_HTML); + webui::SetupWebUIDataSource( + source, + UNSAFE_TODO(base::make_span(kBraveRewardsPanelGenerated, + kBraveRewardsPanelGeneratedSize)), + IDR_BRAVE_REWARDS_PANEL_HTML); // Adaptive captcha challenges are displayed in an iframe on the Rewards // panel. In order to display these challenges we need to specify in CSP that diff --git a/browser/ui/webui/brave_rewards/tip_panel_ui.cc b/browser/ui/webui/brave_rewards/tip_panel_ui.cc index f2fc2acf2ca..6ee1b98f9e5 100644 --- a/browser/ui/webui/brave_rewards/tip_panel_ui.cc +++ b/browser/ui/webui/brave_rewards/tip_panel_ui.cc @@ -80,7 +80,8 @@ TipPanelUI::TipPanelUI(content::WebUI* web_ui) source->AddLocalizedStrings(kStrings); webui::SetupWebUIDataSource( - source, base::make_span(kTipPanelGenerated, kTipPanelGeneratedSize), + source, + UNSAFE_TODO(base::make_span(kTipPanelGenerated, kTipPanelGeneratedSize)), IDR_TIP_PANEL_HTML); source->OverrideContentSecurityPolicy( diff --git a/browser/ui/webui/brave_settings_ui.cc b/browser/ui/webui/brave_settings_ui.cc index 0822aaa1b20..d12c29315c4 100644 --- a/browser/ui/webui/brave_settings_ui.cc +++ b/browser/ui/webui/brave_settings_ui.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/browser/ui/webui/brave_settings_ui.h" #include diff --git a/browser/ui/webui/brave_shields/cookie_list_opt_in_ui.cc b/browser/ui/webui/brave_shields/cookie_list_opt_in_ui.cc index 44d4ee19bf6..14400f0d76f 100644 --- a/browser/ui/webui/brave_shields/cookie_list_opt_in_ui.cc +++ b/browser/ui/webui/brave_shields/cookie_list_opt_in_ui.cc @@ -49,7 +49,8 @@ CookieListOptInUI::CookieListOptInUI(content::WebUI* web_ui) webui::SetupWebUIDataSource( source, - base::make_span(kCookieListOptInGenerated, kCookieListOptInGeneratedSize), + UNSAFE_TODO(base::make_span(kCookieListOptInGenerated, + kCookieListOptInGeneratedSize)), IDR_COOKIE_LIST_OPT_IN_HTML); content::URLDataSource::Add( diff --git a/browser/ui/webui/brave_shields/shields_panel_ui.cc b/browser/ui/webui/brave_shields/shields_panel_ui.cc index 7d7ef35bed0..b5da5d6e7db 100644 --- a/browser/ui/webui/brave_shields/shields_panel_ui.cc +++ b/browser/ui/webui/brave_shields/shields_panel_ui.cc @@ -70,10 +70,11 @@ ShieldsPanelUI::ShieldsPanelUI(content::WebUI* web_ui) profile_, std::make_unique( profile_, chrome::FaviconUrlFormat::kFavicon2)); - webui::SetupWebUIDataSource(source, - base::make_span(kBraveShieldsPanelGenerated, - kBraveShieldsPanelGeneratedSize), - IDR_SHIELDS_PANEL_HTML); + webui::SetupWebUIDataSource( + source, + UNSAFE_TODO(base::make_span(kBraveShieldsPanelGenerated, + kBraveShieldsPanelGeneratedSize)), + IDR_SHIELDS_PANEL_HTML); } ShieldsPanelUI::~ShieldsPanelUI() = default; diff --git a/browser/ui/webui/brave_vpn/vpn_panel_ui.cc b/browser/ui/webui/brave_vpn/vpn_panel_ui.cc index 5ec97f7ada6..cd1f6c1ed8f 100644 --- a/browser/ui/webui/brave_vpn/vpn_panel_ui.cc +++ b/browser/ui/webui/brave_vpn/vpn_panel_ui.cc @@ -43,7 +43,8 @@ VPNPanelUI::VPNPanelUI(content::WebUI* web_ui) brave_vpn::AddLocalizedStrings(source); webui::SetupWebUIDataSource( source, - base::make_span(kBraveVpnPanelGenerated, kBraveVpnPanelGeneratedSize), + UNSAFE_TODO(base::make_span(kBraveVpnPanelGenerated, + kBraveVpnPanelGeneratedSize)), IDR_VPN_PANEL_HTML); source->OverrideContentSecurityPolicy( diff --git a/browser/ui/webui/brave_wallet/android/android_wallet_page_ui.cc b/browser/ui/webui/brave_wallet/android/android_wallet_page_ui.cc index 292d2cc4216..825010e2516 100644 --- a/browser/ui/webui/brave_wallet/android/android_wallet_page_ui.cc +++ b/browser/ui/webui/brave_wallet/android/android_wallet_page_ui.cc @@ -52,10 +52,11 @@ AndroidWalletPageUI::AndroidWalletPageUI(content::WebUI* web_ui, // Add required resources. if (url.host() == kWalletPageHost) { - webui::SetupWebUIDataSource(source, - base::make_span(kBraveWalletPageGenerated, - kBraveWalletPageGeneratedSize), - IDR_WALLET_PAGE_HTML); + webui::SetupWebUIDataSource( + source, + UNSAFE_TODO(base::make_span(kBraveWalletPageGenerated, + kBraveWalletPageGeneratedSize)), + IDR_WALLET_PAGE_HTML); } else { NOTREACHED_IN_MIGRATION() << "Failed to find page resources for:" << url.path(); diff --git a/browser/ui/webui/brave_wallet/ledger/ledger_ui.cc b/browser/ui/webui/brave_wallet/ledger/ledger_ui.cc index 2c05d6640a8..d5f245d96bf 100644 --- a/browser/ui/webui/brave_wallet/ledger/ledger_ui.cc +++ b/browser/ui/webui/brave_wallet/ledger/ledger_ui.cc @@ -21,8 +21,8 @@ UntrustedLedgerUI::UntrustedLedgerUI(content::WebUI* web_ui) auto* untrusted_source = content::WebUIDataSource::CreateAndAdd( web_ui->GetWebContents()->GetBrowserContext(), kUntrustedLedgerURL); untrusted_source->SetDefaultResource(IDR_BRAVE_WALLET_LEDGER_BRIDGE_HTML); - untrusted_source->AddResourcePaths( - base::make_span(kLedgerBridgeGenerated, kLedgerBridgeGeneratedSize)); + untrusted_source->AddResourcePaths(UNSAFE_TODO( + base::make_span(kLedgerBridgeGenerated, kLedgerBridgeGeneratedSize))); untrusted_source->AddFrameAncestor(GURL(kBraveUIWalletPageURL)); untrusted_source->AddFrameAncestor(GURL(kBraveUIWalletPanelURL)); untrusted_source->OverrideContentSecurityPolicy( diff --git a/browser/ui/webui/brave_wallet/line_chart/line_chart_ui.cc b/browser/ui/webui/brave_wallet/line_chart/line_chart_ui.cc index 61f4d6e781d..792941c73b3 100644 --- a/browser/ui/webui/brave_wallet/line_chart/line_chart_ui.cc +++ b/browser/ui/webui/brave_wallet/line_chart/line_chart_ui.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/browser/ui/webui/brave_wallet/line_chart/line_chart_ui.h" #include diff --git a/browser/ui/webui/brave_wallet/market/market_ui.cc b/browser/ui/webui/brave_wallet/market/market_ui.cc index 301eccc7428..3e7c588da4b 100644 --- a/browser/ui/webui/brave_wallet/market/market_ui.cc +++ b/browser/ui/webui/brave_wallet/market/market_ui.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/browser/ui/webui/brave_wallet/market/market_ui.h" #include diff --git a/browser/ui/webui/brave_wallet/nft/nft_ui.cc b/browser/ui/webui/brave_wallet/nft/nft_ui.cc index dd575c33263..ee357c0fe83 100644 --- a/browser/ui/webui/brave_wallet/nft/nft_ui.cc +++ b/browser/ui/webui/brave_wallet/nft/nft_ui.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/browser/ui/webui/brave_wallet/nft/nft_ui.h" #include diff --git a/browser/ui/webui/brave_wallet/trezor/trezor_ui.cc b/browser/ui/webui/brave_wallet/trezor/trezor_ui.cc index 7bc843a5310..9e97e7c2a3b 100644 --- a/browser/ui/webui/brave_wallet/trezor/trezor_ui.cc +++ b/browser/ui/webui/brave_wallet/trezor/trezor_ui.cc @@ -25,8 +25,8 @@ UntrustedTrezorUI::UntrustedTrezorUI(content::WebUI* web_ui) auto* untrusted_source = content::WebUIDataSource::CreateAndAdd( web_ui->GetWebContents()->GetBrowserContext(), kUntrustedTrezorURL); untrusted_source->SetDefaultResource(IDR_BRAVE_WALLET_TREZOR_BRIDGE_HTML); - untrusted_source->AddResourcePaths( - base::make_span(kTrezorBridgeGenerated, kTrezorBridgeGeneratedSize)); + untrusted_source->AddResourcePaths(UNSAFE_TODO( + base::make_span(kTrezorBridgeGenerated, kTrezorBridgeGeneratedSize))); untrusted_source->AddFrameAncestor(GURL(kBraveUIWalletPageURL)); untrusted_source->AddFrameAncestor(GURL(kBraveUIWalletPanelURL)); untrusted_source->OverrideContentSecurityPolicy( diff --git a/browser/ui/webui/brave_wallet/wallet_page_ui.cc b/browser/ui/webui/brave_wallet/wallet_page_ui.cc index 29109f9a294..f69bd17d30a 100644 --- a/browser/ui/webui/brave_wallet/wallet_page_ui.cc +++ b/browser/ui/webui/brave_wallet/wallet_page_ui.cc @@ -65,7 +65,8 @@ WalletPageUI::WalletPageUI(content::WebUI* web_ui) NavigationBarDataProvider::Initialize(source, profile); webui::SetupWebUIDataSource( source, - base::make_span(kBraveWalletPageGenerated, kBraveWalletPageGeneratedSize), + UNSAFE_TODO(base::make_span(kBraveWalletPageGenerated, + kBraveWalletPageGeneratedSize)), IDR_WALLET_PAGE_HTML); source->AddString("braveWalletLedgerBridgeUrl", kUntrustedLedgerURL); source->OverrideContentSecurityPolicy( diff --git a/browser/ui/webui/brave_wallet/wallet_panel_ui.cc b/browser/ui/webui/brave_wallet/wallet_panel_ui.cc index 95cd4ba81fb..2116b243aa4 100644 --- a/browser/ui/webui/brave_wallet/wallet_panel_ui.cc +++ b/browser/ui/webui/brave_wallet/wallet_panel_ui.cc @@ -66,10 +66,11 @@ WalletPanelUI::WalletPanelUI(content::WebUI* web_ui) plural_string_handler->AddLocalizedString( "braveWalletPendingTransactions", IDS_BRAVE_WALLET_PENDING_TRANSACTIONS); web_ui->AddMessageHandler(std::move(plural_string_handler)); - webui::SetupWebUIDataSource(source, - base::make_span(kBraveWalletPanelGenerated, - kBraveWalletPanelGeneratedSize), - IDR_WALLET_PANEL_HTML); + webui::SetupWebUIDataSource( + source, + UNSAFE_TODO(base::make_span(kBraveWalletPanelGenerated, + kBraveWalletPanelGeneratedSize)), + IDR_WALLET_PANEL_HTML); source->AddString("braveWalletLedgerBridgeUrl", kUntrustedLedgerURL); source->OverrideContentSecurityPolicy( network::mojom::CSPDirectiveName::FrameSrc, diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index 8b4e86831fe..46c1dba7c8e 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/browser/ui/webui/brave_webui_source.h" #include diff --git a/build/commands/lib/updateUnsafeBuffersPaths.js b/build/commands/lib/updateUnsafeBuffersPaths.js index ade9f6e258d..584852c9678 100644 --- a/build/commands/lib/updateUnsafeBuffersPaths.js +++ b/build/commands/lib/updateUnsafeBuffersPaths.js @@ -32,7 +32,12 @@ async function updateUnsafeBuffersPaths() { ...repoContent.split('\n'), '# Appended path correction for redirect_cc by update_patches.', '# File patched by brave/build/commands/lib/updateUnsafeBuffersPaths.js.', - '-brave/' + '-brave/third_party/bip39wally-core-native/', + '-brave/third_party/argon2/', + '-brave/third_party/ethash/', + '-brave/third_party/bitcoin-core/', + '-brave/third_party/rapidjson/', + '-brave/vendor/bat-native-tweetnacl/' ]; updatedPathLines = bufferPathLines.filter( diff --git a/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc b/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc index 475214b00d9..ba26baf5514 100644 --- a/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc +++ b/chromium_src/chrome/browser/extensions/component_extensions_allowlist/allowlist.cc @@ -31,8 +31,9 @@ namespace extensions { }; for (size_t i = 0; i < std::size(kAllowed); ++i) { - if (extension_id == kAllowed[i]) + if (extension_id == UNSAFE_TODO(kAllowed[i])) { return true; + } } return IsComponentExtensionAllowlisted_ChromiumImpl(extension_id); diff --git a/chromium_src/chrome/browser/profiles/profile_avatar_icon_util.cc b/chromium_src/chrome/browser/profiles/profile_avatar_icon_util.cc index eadb3b1e88e..f037417e7c0 100644 --- a/chromium_src/chrome/browser/profiles/profile_avatar_icon_util.cc +++ b/chromium_src/chrome/browser/profiles/profile_avatar_icon_util.cc @@ -3,6 +3,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at https://mozilla.org/MPL/2.0/. +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "base/values.h" diff --git a/chromium_src/chrome/browser/ui/tabs/recent_tabs_sub_menu_model_unittest.cc b/chromium_src/chrome/browser/ui/tabs/recent_tabs_sub_menu_model_unittest.cc index 83779f09090..fbd27a2f3b9 100644 --- a/chromium_src/chrome/browser/ui/tabs/recent_tabs_sub_menu_model_unittest.cc +++ b/chromium_src/chrome/browser/ui/tabs/recent_tabs_sub_menu_model_unittest.cc @@ -69,7 +69,8 @@ void RecentTabsSubMenuModelTest::VerifyModel( item_data.enabled = false; } - ::VerifyModel(model, base::make_span(v_data.begin(), v_data.size())); + ::VerifyModel(model, + UNSAFE_TODO(base::make_span(v_data.begin(), v_data.size()))); } void RecentTabsSubMenuModelTest::VerifyModel(const ui::MenuModel* model, diff --git a/chromium_src/chrome/browser/ui/views/accelerator_table.cc b/chromium_src/chrome/browser/ui/views/accelerator_table.cc index 1a750ec64bd..8b6e086acd2 100644 --- a/chromium_src/chrome/browser/ui/views/accelerator_table.cc +++ b/chromium_src/chrome/browser/ui/views/accelerator_table.cc @@ -40,9 +40,9 @@ std::vector GetAcceleratorList() { std::vector accelerator_list( GetAcceleratorList_ChromiumImpl()); - accelerator_list.insert( + UNSAFE_TODO(accelerator_list.insert( accelerator_list.end(), kBraveAcceleratorMap, - kBraveAcceleratorMap + std::size(kBraveAcceleratorMap)); + kBraveAcceleratorMap + std::size(kBraveAcceleratorMap))); return accelerator_list; } diff --git a/chromium_src/chrome/install_static/brave_install_modes_unittest.cc b/chromium_src/chrome/install_static/brave_install_modes_unittest.cc index 4fdba2d8d5e..21fbf600caa 100644 --- a/chromium_src/chrome/install_static/brave_install_modes_unittest.cc +++ b/chromium_src/chrome/install_static/brave_install_modes_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "chrome/install_static/install_modes.h" #include // NOLINT diff --git a/chromium_src/chrome/install_static/brave_install_util_unittest.cc b/chromium_src/chrome/install_static/brave_install_util_unittest.cc index cac3a16d638..170390f1ac4 100644 --- a/chromium_src/chrome/install_static/brave_install_util_unittest.cc +++ b/chromium_src/chrome/install_static/brave_install_util_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include #include diff --git a/chromium_src/chrome/installer/mini_installer/mini_installer.cc b/chromium_src/chrome/installer/mini_installer/mini_installer.cc index d9b44948a2b..af9aaa02091 100644 --- a/chromium_src/chrome/installer/mini_installer/mini_installer.cc +++ b/chromium_src/chrome/installer/mini_installer/mini_installer.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "build/branding_buildflags.h" #define BRAVE_RUN_SETUP \ diff --git a/chromium_src/chrome/installer/setup/uninstall.cc b/chromium_src/chrome/installer/setup/uninstall.cc index 6afde77ed31..69f242f010f 100644 --- a/chromium_src/chrome/installer/setup/uninstall.cc +++ b/chromium_src/chrome/installer/setup/uninstall.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "base/files/file_path.h" #include "base/files/file_util.h" #include "base/logging.h" diff --git a/chromium_src/components/search_engines/search_engine_utils.cc b/chromium_src/components/search_engines/search_engine_utils.cc index 9222546bcb7..04b23f5456e 100644 --- a/chromium_src/components/search_engines/search_engine_utils.cc +++ b/chromium_src/components/search_engines/search_engine_utils.cc @@ -5,6 +5,7 @@ #include "components/search_engines/search_engine_utils.h" +#include "base/compiler_specific.h" #include "brave/components/search_engines/brave_prepopulated_engines.h" #define GetEngineType GetEngineType_ChromiumImpl @@ -24,7 +25,7 @@ SearchEngineType GetEngineType(const GURL& url) { return engine->type; } for (size_t j = 0; j < engine->alternate_urls_size; ++j) { - if (SameDomain(url, GURL(engine->alternate_urls[j]))) { + if (SameDomain(url, UNSAFE_TODO(GURL(engine->alternate_urls[j])))) { return engine->type; } } diff --git a/chromium_src/net/socket/socks5_client_socket.cc b/chromium_src/net/socket/socks5_client_socket.cc index 12a276d85ff..3d56489e4ae 100644 --- a/chromium_src/net/socket/socks5_client_socket.cc +++ b/chromium_src/net/socket/socks5_client_socket.cc @@ -10,6 +10,7 @@ #include #include +#include "base/compiler_specific.h" #include "net/base/io_buffer.h" #include "net/socket/socks5_client_socket.h" @@ -112,9 +113,9 @@ int SOCKS5ClientSocketAuth::Authenticate( DCHECK_EQ(OK, rv); DCHECK_LT(0u, buffer_left_); iobuf_ = base::MakeRefCounted(buffer_left_); - memcpy(iobuf_->data(), - &buffer_.data()[buffer_.size() - buffer_left_], - buffer_left_); + UNSAFE_TODO(memcpy(iobuf_->data(), + &buffer_.data()[buffer_.size() - buffer_left_], + buffer_left_)); next_state_ = STATE_WRITE_COMPLETE; net_log.BeginEvent(NetLogEventType::SOCKS5_AUTH_WRITE); rv = transport_socket_->Write(iobuf_.get(), buffer_left_, callback, diff --git a/chromium_src/sandbox/win/src/interceptors_64.cc b/chromium_src/sandbox/win/src/interceptors_64.cc index 6a6be07e1ea..a173d9fbd8e 100644 --- a/chromium_src/sandbox/win/src/interceptors_64.cc +++ b/chromium_src/sandbox/win/src/interceptors_64.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "src/sandbox/win/src/interceptors_64.cc" #include "brave/sandbox/win/src/module_file_name_interception.h" diff --git a/chromium_src/third_party/blink/renderer/modules/mediastream/media_devices.cc b/chromium_src/third_party/blink/renderer/modules/mediastream/media_devices.cc index 8e29d571543..b23fd579806 100644 --- a/chromium_src/third_party/blink/renderer/modules/mediastream/media_devices.cc +++ b/chromium_src/third_party/blink/renderer/modules/mediastream/media_devices.cc @@ -3,6 +3,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#include "base/compiler_specific.h" #include "brave/third_party/blink/renderer/core/farbling/brave_session_cache.h" #include "third_party/blink/renderer/modules/mediastream/media_device_info.h" @@ -26,7 +27,7 @@ void FarbleMediaDevices(ExecutionContext* context, FarblingPRNG prng = BraveSessionCache::From(*context).MakePseudoRandomGenerator(); MediaDeviceInfoVector::iterator it_begin = media_devices->begin(); - std::shuffle(++it_begin, media_devices->end(), prng); + UNSAFE_TODO(std::shuffle(++it_begin, media_devices->end(), prng)); } } // namespace brave diff --git a/chromium_src/third_party/blink/renderer/modules/speech/speech_synthesis.cc b/chromium_src/third_party/blink/renderer/modules/speech/speech_synthesis.cc index 737f3f45204..a0b0beeef4c 100644 --- a/chromium_src/third_party/blink/renderer/modules/speech/speech_synthesis.cc +++ b/chromium_src/third_party/blink/renderer/modules/speech/speech_synthesis.cc @@ -5,6 +5,7 @@ #include "third_party/blink/renderer/modules/speech/speech_synthesis.h" +#include "base/compiler_specific.h" #include "brave/third_party/blink/renderer/brave_farbling_constants.h" #include "brave/third_party/blink/renderer/core/farbling/brave_session_cache.h" #include "third_party/blink/public/platform/web_content_settings_client.h" @@ -46,7 +47,8 @@ void SpeechSynthesis::OnSetVoiceList( "Wilson", "Alva", "Harley", "Beauregard", "Cleveland", "Cecil", "Reuben", "Sylvester", "Jasper"}; const int kFakeNamesCount = std::size(kFakeNames); - fake_voice->name = WTF::String(kFakeNames[prng() % kFakeNamesCount]); + fake_voice->name = + UNSAFE_TODO(WTF::String(kFakeNames[prng() % kFakeNamesCount])); } } voice_list_.push_back( diff --git a/components/ai_chat/core/browser/local_models_updater.cc b/components/ai_chat/core/browser/local_models_updater.cc index 838161e90c1..7c1cd229d0a 100644 --- a/components/ai_chat/core/browser/local_models_updater.cc +++ b/components/ai_chat/core/browser/local_models_updater.cc @@ -112,7 +112,7 @@ base::FilePath LocalModelsComponentInstallerPolicy::GetRelativeInstallDir() void LocalModelsComponentInstallerPolicy::GetHash( std::vector* hash) const { hash->assign(kPublicKeySHA256, - kPublicKeySHA256 + std::size(kPublicKeySHA256)); + UNSAFE_TODO(kPublicKeySHA256 + std::size(kPublicKeySHA256))); } std::string LocalModelsComponentInstallerPolicy::GetName() const { diff --git a/components/ai_chat/core/browser/text_embedder_unittest.cc b/components/ai_chat/core/browser/text_embedder_unittest.cc index 9c6966f5f15..35d2c9e301d 100644 --- a/components/ai_chat/core/browser/text_embedder_unittest.cc +++ b/components/ai_chat/core/browser/text_embedder_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/ai_chat/core/browser/text_embedder.h" #include "base/files/file_path.h" diff --git a/components/ai_chat/renderer/page_content_extractor.cc b/components/ai_chat/renderer/page_content_extractor.cc index 10ca0b0f9bc..9444d32cef2 100644 --- a/components/ai_chat/renderer/page_content_extractor.cc +++ b/components/ai_chat/renderer/page_content_extractor.cc @@ -3,6 +3,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at https://mozilla.org/MPL/2.0/. +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/ai_chat/renderer/page_content_extractor.h" #include diff --git a/components/ai_chat/renderer/page_text_distilling.cc b/components/ai_chat/renderer/page_text_distilling.cc index 90a4e8240af..738ff5162e1 100644 --- a/components/ai_chat/renderer/page_text_distilling.cc +++ b/components/ai_chat/renderer/page_text_distilling.cc @@ -174,7 +174,7 @@ void DistillPageText( }; render_frame->GetWebFrame()->RequestExecuteScript( - isolated_world_id, base::make_span(&source, 1u), + isolated_world_id, UNSAFE_TODO(base::make_span(&source, 1u)), blink::mojom::UserActivationOption::kDoNotActivate, blink::mojom::EvaluationTiming::kAsynchronous, blink::mojom::LoadEventBlockingOption::kDoNotBlock, diff --git a/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc b/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc index 7190fe9e4a3..9443d664c0c 100644 --- a/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc +++ b/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_ads/core/internal/account/utility/redeem_confirmation/reward/redeem_reward_confirmation.h" #include diff --git a/components/brave_ads/core/internal/common/calendar/calendar_util.h b/components/brave_ads/core/internal/common/calendar/calendar_util.h index 877d5561b9b..d7d2fb310d5 100644 --- a/components/brave_ads/core/internal/common/calendar/calendar_util.h +++ b/components/brave_ads/core/internal/common/calendar/calendar_util.h @@ -7,6 +7,7 @@ #define BRAVE_COMPONENTS_BRAVE_ADS_CORE_INTERNAL_COMMON_CALENDAR_CALENDAR_UTIL_H_ #include "base/check.h" +#include "base/compiler_specific.h" namespace base { class Time; @@ -29,7 +30,7 @@ constexpr int DaysInMonth(const int year, const int month) noexcept { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 // non leap year. }; - int days_in_month = kDaysInMonth[month - 1]; + int days_in_month = UNSAFE_TODO(kDaysInMonth[month - 1]); if (month == /*february*/ 2 && IsLeapYear(year)) { // In a leap year, February gets an extra day, because even the shortest // month deserves a little extra time to shine! diff --git a/components/brave_ads/core/internal/common/calendar/calendar_util_unittest.cc b/components/brave_ads/core/internal/common/calendar/calendar_util_unittest.cc index fd715d8dfe9..387cd1fcba7 100644 --- a/components/brave_ads/core/internal/common/calendar/calendar_util_unittest.cc +++ b/components/brave_ads/core/internal/common/calendar/calendar_util_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_ads/core/internal/common/calendar/calendar_util.h" #include "base/time/time.h" // IWYU pragma: keep diff --git a/components/brave_ads/core/internal/common/crypto/crypto_util_unittest.cc b/components/brave_ads/core/internal/common/crypto/crypto_util_unittest.cc index d3d11f1db01..7c8b8a3ef12 100644 --- a/components/brave_ads/core/internal/common/crypto/crypto_util_unittest.cc +++ b/components/brave_ads/core/internal/common/crypto/crypto_util_unittest.cc @@ -101,8 +101,8 @@ TEST(BraveAdsCryptoUtilTest, EncryptAndDecrypt) { const KeyPairInfo key_pair = GenerateBoxKeyPair(); const KeyPairInfo ephemeral_key_pair = GenerateBoxKeyPair(); const std::vector nonce = GenerateRandomNonce(); - const std::vector plaintext(kMessage, - kMessage + std::size(kMessage)); + const std::vector plaintext( + kMessage, UNSAFE_TODO(kMessage + std::size(kMessage))); // Act const std::vector ciphertext = Encrypt( diff --git a/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.cc b/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.cc index b480570e6c6..178bfc99b96 100644 --- a/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.cc +++ b/components/brave_ads/core/internal/creatives/inline_content_ads/creative_inline_content_ad_test_util.cc @@ -22,7 +22,7 @@ CreativeInlineContentAdList BuildCreativeInlineContentAds(const int count) { for (int i = 0; i < count; ++i) { CreativeInlineContentAdInfo creative_ad = BuildCreativeInlineContentAd( /*should_generate_random_uuids=*/true); - creative_ad.segment = kSegments[i % std::size(kSegments)]; + creative_ad.segment = UNSAFE_TODO(kSegments[i % std::size(kSegments)]); creative_ads.push_back(creative_ad); } diff --git a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.cc b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.cc index 5aa04c1646e..239e1543f66 100644 --- a/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.cc +++ b/components/brave_ads/core/internal/creatives/new_tab_page_ads/creative_new_tab_page_ad_test_util.cc @@ -24,7 +24,7 @@ CreativeNewTabPageAdList BuildCreativeNewTabPageAds(const int count) { for (int i = 0; i < count; ++i) { CreativeNewTabPageAdInfo creative_ad = BuildCreativeNewTabPageAd(/*should_generate_random_uuids=*/true); - creative_ad.segment = kSegments[i % std::size(kSegments)]; + creative_ad.segment = UNSAFE_TODO(kSegments[i % std::size(kSegments)]); creative_ads.push_back(creative_ad); } diff --git a/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_test_util.cc b/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_test_util.cc index a636f9764b0..98e524195ec 100644 --- a/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_test_util.cc +++ b/components/brave_ads/core/internal/creatives/notification_ads/creative_notification_ad_test_util.cc @@ -21,7 +21,7 @@ CreativeNotificationAdList BuildCreativeNotificationAds(const int count) { for (int i = 0; i < count; ++i) { CreativeNotificationAdInfo creative_ad = BuildCreativeNotificationAd( /*should_generate_random_uuids=*/true); - creative_ad.segment = kSegments[i % std::size(kSegments)]; + creative_ad.segment = UNSAFE_TODO(kSegments[i % std::size(kSegments)]); creative_ads.push_back(creative_ad); } diff --git a/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_test_util.cc b/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_test_util.cc index 6028f0649d8..26d3a3cc22a 100644 --- a/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_test_util.cc +++ b/components/brave_ads/core/internal/creatives/promoted_content_ads/creative_promoted_content_ad_test_util.cc @@ -20,7 +20,7 @@ CreativePromotedContentAdList BuildCreativePromotedContentAds(const int count) { for (int i = 0; i < count; ++i) { CreativePromotedContentAdInfo creative_ad = BuildCreativePromotedContentAd( /*should_generate_random_uuids=*/true); - creative_ad.segment = kSegments[i % std::size(kSegments)]; + creative_ad.segment = UNSAFE_TODO(kSegments[i % std::size(kSegments)]); creative_ads.push_back(creative_ad); } diff --git a/components/brave_news/browser/feed_v2_builder.cc b/components/brave_news/browser/feed_v2_builder.cc index b417e98261d..29ad7f1092e 100644 --- a/components/brave_news/browser/feed_v2_builder.cc +++ b/components/brave_news/browser/feed_v2_builder.cc @@ -3,6 +3,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at https://mozilla.org/MPL/2.0/. +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_news/browser/feed_v2_builder.h" #include diff --git a/components/brave_news/browser/initialization_promise.cc b/components/brave_news/browser/initialization_promise.cc index dc82aa6924c..84964ecd8f8 100644 --- a/components/brave_news/browser/initialization_promise.cc +++ b/components/brave_news/browser/initialization_promise.cc @@ -94,9 +94,10 @@ void InitializationPromise::OnGotLocale(const std::string& locale) { // Determine how long we should wait based on the number of times we've // retried. - int retry_delay = no_retry_delay_for_testing_ - ? 0 - : kBackoffs[std::min(attempts_, kNumBackoffs - 1)]; + int retry_delay = + no_retry_delay_for_testing_ + ? 0 + : UNSAFE_TODO(kBackoffs[std::min(attempts_, kNumBackoffs - 1)]); base::SequencedTaskRunner::GetCurrentDefault()->PostDelayedTask( FROM_HERE, base::BindOnce(&InitializationPromise::Initialize, diff --git a/components/brave_private_cdn/private_cdn_helper_unittest.cc b/components/brave_private_cdn/private_cdn_helper_unittest.cc index f366f1a17f7..62b857b09e2 100644 --- a/components/brave_private_cdn/private_cdn_helper_unittest.cc +++ b/components/brave_private_cdn/private_cdn_helper_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include #include diff --git a/components/brave_rewards/browser/diagnostic_log.cc b/components/brave_rewards/browser/diagnostic_log.cc index 42d705d0671..ac5117a6f8c 100644 --- a/components/brave_rewards/browser/diagnostic_log.cc +++ b/components/brave_rewards/browser/diagnostic_log.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_rewards/browser/diagnostic_log.h" #include diff --git a/components/brave_rewards/browser/rewards_service_impl.cc b/components/brave_rewards/browser/rewards_service_impl.cc index dcecb0d53ae..3ed81f9c185 100644 --- a/components/brave_rewards/browser/rewards_service_impl.cc +++ b/components/brave_rewards/browser/rewards_service_impl.cc @@ -210,7 +210,7 @@ std::string GetPrefPath(const std::string& name) { std::vector GetISOCountries() { std::vector countries; for (const char* const* country_pointer = icu::Locale::getISOCountries(); - *country_pointer; ++country_pointer) { + *country_pointer; UNSAFE_TODO(++country_pointer)) { countries.emplace_back(*country_pointer); } return countries; diff --git a/components/brave_rewards/core/publisher/prefix_iterator.h b/components/brave_rewards/core/publisher/prefix_iterator.h index 33a06c56c50..89721675f77 100644 --- a/components/brave_rewards/core/publisher/prefix_iterator.h +++ b/components/brave_rewards/core/publisher/prefix_iterator.h @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #ifndef BRAVE_COMPONENTS_BRAVE_REWARDS_CORE_PUBLISHER_PREFIX_ITERATOR_H_ #define BRAVE_COMPONENTS_BRAVE_REWARDS_CORE_PUBLISHER_PREFIX_ITERATOR_H_ diff --git a/components/brave_shields/content/browser/brave_shields_p3a.cc b/components/brave_shields/content/browser/brave_shields_p3a.cc index 8f6970e20a2..96736a915e2 100644 --- a/components/brave_shields/content/browser/brave_shields_p3a.cc +++ b/components/brave_shields/content/browser/brave_shields_p3a.cc @@ -3,6 +3,12 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this file, // You can obtain one at https://mozilla.org/MPL/2.0/. +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_shields/content/browser/brave_shields_p3a.h" #include diff --git a/components/brave_shields/core/browser/ad_block_component_installer.cc b/components/brave_shields/core/browser/ad_block_component_installer.cc index e8981151294..0a2cb2d40f5 100644 --- a/components/brave_shields/core/browser/ad_block_component_installer.cc +++ b/components/brave_shields/core/browser/ad_block_component_installer.cc @@ -119,7 +119,7 @@ base::FilePath AdBlockComponentInstallerPolicy::GetRelativeInstallDir() const { void AdBlockComponentInstallerPolicy::GetHash( std::vector* hash) const { - hash->assign(component_hash_, component_hash_ + kHashSize); + hash->assign(component_hash_, UNSAFE_TODO(component_hash_ + kHashSize)); } std::string AdBlockComponentInstallerPolicy::GetName() const { diff --git a/components/brave_sync/time_limited_words.cc b/components/brave_sync/time_limited_words.cc index 4191927b316..5a11fc325f4 100644 --- a/components/brave_sync/time_limited_words.cc +++ b/components/brave_sync/time_limited_words.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_sync/time_limited_words.h" #include diff --git a/components/brave_vpn/browser/connection/ikev2/win/ras_utils.cc b/components/brave_vpn/browser/connection/ikev2/win/ras_utils.cc index d563566e5cd..76e6efcaa4c 100644 --- a/components/brave_vpn/browser/connection/ikev2/win/ras_utils.cc +++ b/components/brave_vpn/browser/connection/ikev2/win/ras_utils.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_vpn/browser/connection/ikev2/win/ras_utils.h" #include diff --git a/components/brave_vpn/common/wireguard/wireguard_utils.cc b/components/brave_vpn/common/wireguard/wireguard_utils.cc index 472b11dd79f..0f95bb246d6 100644 --- a/components/brave_vpn/common/wireguard/wireguard_utils.cc +++ b/components/brave_vpn/common/wireguard/wireguard_utils.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_vpn/common/wireguard/wireguard_utils.h" #include diff --git a/components/brave_wallet/browser/bitcoin/bitcoin_discover_account_task.cc b/components/brave_wallet/browser/bitcoin/bitcoin_discover_account_task.cc index cef61739126..00a22f12042 100644 --- a/components/brave_wallet/browser/bitcoin/bitcoin_discover_account_task.cc +++ b/components/brave_wallet/browser/bitcoin/bitcoin_discover_account_task.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/bitcoin/bitcoin_discover_account_task.h" #include diff --git a/components/brave_wallet/browser/ens_resolver_task.cc b/components/brave_wallet/browser/ens_resolver_task.cc index 2bcb47e5b29..90db35f0592 100644 --- a/components/brave_wallet/browser/ens_resolver_task.cc +++ b/components/brave_wallet/browser/ens_resolver_task.cc @@ -9,6 +9,7 @@ #include #include +#include "base/compiler_specific.h" #include "base/containers/contains.h" #include "base/functional/callback_helpers.h" #include "base/json/json_reader.h" @@ -543,8 +544,8 @@ void EnsResolverTask::OnFetchOffchainDone(APIRequestResult api_request_result) { offchain_lookup_attemps_left_--; DCHECK_GE(offchain_lookup_attemps_left_, 0); DCHECK_EQ(offchain_lookup_data_->callback_function.size(), 4u); - eth_abi::Span4 callback_selector( - offchain_lookup_data_->callback_function.begin(), 4u); + UNSAFE_TODO(eth_abi::Span4 callback_selector( + offchain_lookup_data_->callback_function.begin(), 4u)); offchain_callback_call_ = eth_abi::TupleEncoder() .AddBytes(*bytes_result) diff --git a/components/brave_wallet/browser/eth_abi_decoder.cc b/components/brave_wallet/browser/eth_abi_decoder.cc index 04ae106d2df..af9041a3630 100644 --- a/components/brave_wallet/browser/eth_abi_decoder.cc +++ b/components/brave_wallet/browser/eth_abi_decoder.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/eth_abi_decoder.h" #include diff --git a/components/brave_wallet/browser/eth_gas_utils.cc b/components/brave_wallet/browser/eth_gas_utils.cc index 0e1b9344acf..ad9e7fdbfdc 100644 --- a/components/brave_wallet/browser/eth_gas_utils.cc +++ b/components/brave_wallet/browser/eth_gas_utils.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/eth_gas_utils.h" #include diff --git a/components/brave_wallet/browser/ethereum_keyring_unittest.cc b/components/brave_wallet/browser/ethereum_keyring_unittest.cc index b96e1f22fda..808dee64c81 100644 --- a/components/brave_wallet/browser/ethereum_keyring_unittest.cc +++ b/components/brave_wallet/browser/ethereum_keyring_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/ethereum_keyring.h" #include diff --git a/components/brave_wallet/browser/internal/hd_key.cc b/components/brave_wallet/browser/internal/hd_key.cc index b7b7b65e624..80890bfcf77 100644 --- a/components/brave_wallet/browser/internal/hd_key.cc +++ b/components/brave_wallet/browser/internal/hd_key.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/internal/hd_key.h" #include diff --git a/components/brave_wallet/browser/meld_integration_response_parser_unittest.cc b/components/brave_wallet/browser/meld_integration_response_parser_unittest.cc index e86c7806b53..f32683eaf29 100644 --- a/components/brave_wallet/browser/meld_integration_response_parser_unittest.cc +++ b/components/brave_wallet/browser/meld_integration_response_parser_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/meld_integration_response_parser.h" #include diff --git a/components/brave_wallet/browser/permission_utils_unittest.cc b/components/brave_wallet/browser/permission_utils_unittest.cc index aa82cd3407f..482aee69d4a 100644 --- a/components/brave_wallet/browser/permission_utils_unittest.cc +++ b/components/brave_wallet/browser/permission_utils_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/permission_utils.h" #include diff --git a/components/brave_wallet/browser/rlp_encode_unittest.cc b/components/brave_wallet/browser/rlp_encode_unittest.cc index 596123e297d..e11bc655408 100644 --- a/components/brave_wallet/browser/rlp_encode_unittest.cc +++ b/components/brave_wallet/browser/rlp_encode_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include #include #include diff --git a/components/brave_wallet/browser/solana_instruction_builder.cc b/components/brave_wallet/browser/solana_instruction_builder.cc index c1ccd50fb4b..72aad492afc 100644 --- a/components/brave_wallet/browser/solana_instruction_builder.cc +++ b/components/brave_wallet/browser/solana_instruction_builder.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/browser/solana_instruction_builder.h" #include diff --git a/components/brave_wallet/browser/wallet_data_files_installer.cc b/components/brave_wallet/browser/wallet_data_files_installer.cc index e844f190cf8..64b13e5e1df 100644 --- a/components/brave_wallet/browser/wallet_data_files_installer.cc +++ b/components/brave_wallet/browser/wallet_data_files_installer.cc @@ -11,6 +11,7 @@ #include #include +#include "base/compiler_specific.h" #include "base/functional/bind.h" #include "base/logging.h" #include "base/values.h" @@ -120,8 +121,9 @@ base::FilePath WalletDataFilesInstallerPolicy::GetRelativeInstallDir() const { } void WalletDataFilesInstallerPolicy::GetHash(std::vector* hash) const { - hash->assign(kWalletDataFilesSha2Hash, - kWalletDataFilesSha2Hash + std::size(kWalletDataFilesSha2Hash)); + UNSAFE_TODO(hash->assign( + kWalletDataFilesSha2Hash, + kWalletDataFilesSha2Hash + std::size(kWalletDataFilesSha2Hash))); } std::string WalletDataFilesInstallerPolicy::GetName() const { diff --git a/components/brave_wallet/common/btc_like_serializer_stream.cc b/components/brave_wallet/common/btc_like_serializer_stream.cc index 1f0ec319380..003e8f60bef 100644 --- a/components/brave_wallet/common/btc_like_serializer_stream.cc +++ b/components/brave_wallet/common/btc_like_serializer_stream.cc @@ -5,13 +5,15 @@ #include "brave/components/brave_wallet/common/btc_like_serializer_stream.h" +#include "base/compiler_specific.h" #include "base/containers/span.h" #include "base/numerics/byte_conversions.h" namespace brave_wallet { void BtcLikeSerializerStream::Push8AsLE(uint8_t i) { - base::span data_to_insert(reinterpret_cast(&i), sizeof(i)); + UNSAFE_TODO(base::span data_to_insert(reinterpret_cast(&i), + sizeof(i))); PushBytes(data_to_insert); } diff --git a/components/brave_wallet/common/eth_abi_utils.cc b/components/brave_wallet/common/eth_abi_utils.cc index aac66a3bce4..88bfcaba36f 100644 --- a/components/brave_wallet/common/eth_abi_utils.cc +++ b/components/brave_wallet/common/eth_abi_utils.cc @@ -67,7 +67,7 @@ std::optional ToSpan32(Span data) { return std::nullopt; } - return Span32(data.data(), kRowLength); + return UNSAFE_TODO(Span32(data.data(), kRowLength)); } Span ExtractRows(Span data, size_t row, size_t row_count) { diff --git a/components/brave_wallet/common/eth_abi_utils_unittest.cc b/components/brave_wallet/common/eth_abi_utils_unittest.cc index 63a92ae492a..a255e74f467 100644 --- a/components/brave_wallet/common/eth_abi_utils_unittest.cc +++ b/components/brave_wallet/common/eth_abi_utils_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/common/eth_abi_utils.h" #include diff --git a/components/brave_wallet/common/eth_address.cc b/components/brave_wallet/common/eth_address.cc index cce66173d39..5eaa17a4172 100644 --- a/components/brave_wallet/common/eth_address.cc +++ b/components/brave_wallet/common/eth_address.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/common/eth_address.h" #include diff --git a/components/brave_wallet/common/eth_request_helper.cc b/components/brave_wallet/common/eth_request_helper.cc index 936d14f3698..be5aee69515 100644 --- a/components/brave_wallet/common/eth_request_helper.cc +++ b/components/brave_wallet/common/eth_request_helper.cc @@ -11,6 +11,7 @@ #include #include "base/base64.h" +#include "base/compiler_specific.h" #include "base/json/json_reader.h" #include "base/json/json_writer.h" #include "base/ranges/algorithm.h" @@ -402,8 +403,8 @@ bool ParseEthDecryptParams(const std::string& json, } // IsValidHexString guarantees at least 2 bytes and starts with 0x - if (!base::HexStringToString(untrusted_hex_json_str->data() + 2, - &untrusted_json)) { + if (!UNSAFE_TODO(base::HexStringToString(untrusted_hex_json_str->data() + 2, + &untrusted_json))) { return false; } diff --git a/components/brave_wallet/common/eth_sign_typed_data_helper.cc b/components/brave_wallet/common/eth_sign_typed_data_helper.cc index 5dc1b45f447..3cfb8a1405c 100644 --- a/components/brave_wallet/common/eth_sign_typed_data_helper.cc +++ b/components/brave_wallet/common/eth_sign_typed_data_helper.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/brave_wallet/common/eth_sign_typed_data_helper.h" #include diff --git a/components/brave_wallet/common/hash_utils.cc b/components/brave_wallet/common/hash_utils.cc index 48a17a778ab..f66a178c0cc 100644 --- a/components/brave_wallet/common/hash_utils.cc +++ b/components/brave_wallet/common/hash_utils.cc @@ -9,6 +9,7 @@ #include #include "base/check.h" +#include "base/compiler_specific.h" #include "base/containers/adapters.h" #include "base/containers/span.h" #include "base/ranges/algorithm.h" @@ -39,7 +40,7 @@ std::string KeccakHash(const std::string& input, bool to_hex) { std::vector KeccakHash(const std::vector& input) { auto hash = ethash_keccak256(input.data(), input.size()); - return std::vector(hash.bytes, hash.bytes + 32); + return UNSAFE_TODO(std::vector(hash.bytes, hash.bytes + 32)); } eth_abi::Bytes32 KeccakHashBytes32(base::span input) { diff --git a/components/brave_wallet/common/hex_utils.cc b/components/brave_wallet/common/hex_utils.cc index d13c219048f..4d74d2ae0fe 100644 --- a/components/brave_wallet/common/hex_utils.cc +++ b/components/brave_wallet/common/hex_utils.cc @@ -8,6 +8,7 @@ #include #include +#include "base/compiler_specific.h" #include "base/strings/string_number_conversions.h" #include "base/strings/string_util.h" #include "base/strings/stringprintf.h" @@ -156,7 +157,7 @@ std::string Uint256ValueToHex(uint256_t input) { static constexpr char kHexChars[] = "0123456789abcdef"; while (input) { uint8_t i = static_cast(input & static_cast(0x0F)); - result.insert(result.begin(), kHexChars[i]); + UNSAFE_TODO(result.insert(result.begin(), kHexChars[i])); input >>= 4; } if (result.empty()) { diff --git a/components/brave_wallet/renderer/js_solana_provider.cc b/components/brave_wallet/renderer/js_solana_provider.cc index 804146ae461..3f7854d8198 100644 --- a/components/brave_wallet/renderer/js_solana_provider.cc +++ b/components/brave_wallet/renderer/js_solana_provider.cc @@ -115,7 +115,7 @@ bool JSSolanaProvider::V8ConverterStrategy::FromV8ArrayBuffer( if (gin::ConvertFromV8(isolate, value.As(), &view)) { data = reinterpret_cast(view.bytes()); data_length = view.num_bytes(); - bytes.assign(data, data + data_length); + UNSAFE_TODO(bytes.assign(data, data + data_length)); } if (!bytes.size()) { return false; diff --git a/components/ntp_background_images/browser/ntp_background_images_component_installer.cc b/components/ntp_background_images/browser/ntp_background_images_component_installer.cc index 3e8c90d3418..63680f74e0b 100644 --- a/components/ntp_background_images/browser/ntp_background_images_component_installer.cc +++ b/components/ntp_background_images/browser/ntp_background_images_component_installer.cc @@ -132,7 +132,7 @@ base::FilePath NTPBackgroundImagesComponentInstallerPolicy:: void NTPBackgroundImagesComponentInstallerPolicy::GetHash( std::vector* hash) const { - hash->assign(component_hash_, component_hash_ + kHashSize); + hash->assign(component_hash_, UNSAFE_TODO(component_hash_ + kHashSize)); } std::string NTPBackgroundImagesComponentInstallerPolicy::GetName() const { diff --git a/components/omnibox/browser/brave_search_provider_unittest.cc b/components/omnibox/browser/brave_search_provider_unittest.cc index 4a9440372f5..b30f4cb5fea 100644 --- a/components/omnibox/browser/brave_search_provider_unittest.cc +++ b/components/omnibox/browser/brave_search_provider_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/omnibox/browser/brave_search_provider.h" #include diff --git a/components/omnibox/browser/search_suggestions/query_check_utils.cc b/components/omnibox/browser/search_suggestions/query_check_utils.cc index 3f6caeb9b7e..cbee7f6092d 100644 --- a/components/omnibox/browser/search_suggestions/query_check_utils.cc +++ b/components/omnibox/browser/search_suggestions/query_check_utils.cc @@ -9,6 +9,7 @@ #include #include +#include "base/compiler_specific.h" #include "base/no_destructor.h" #include "base/notreached.h" #include "base/strings/strcat.h" @@ -45,7 +46,7 @@ double GetHashProb(const std::string& query) { const auto b = query[i + 1]; const auto pos1 = GetPosForHashChars(a); const auto pos2 = GetPosForHashChars(b); - log_prob += kProbHashLogM[pos1][pos2]; + log_prob += UNSAFE_TODO(kProbHashLogM[pos1][pos2]); trans_c += 1; } diff --git a/components/p3a/nitro_utils/attestation.cc b/components/p3a/nitro_utils/attestation.cc index b172ed6eda2..1e52fe2a0c2 100644 --- a/components/p3a/nitro_utils/attestation.cc +++ b/components/p3a/nitro_utils/attestation.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/p3a/nitro_utils/attestation.h" #include diff --git a/components/p3a/nitro_utils/cose.cc b/components/p3a/nitro_utils/cose.cc index d420289e3fa..e95127f4f47 100644 --- a/components/p3a/nitro_utils/cose.cc +++ b/components/p3a/nitro_utils/cose.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/p3a/nitro_utils/cose.h" #include diff --git a/components/permissions/permissions_client_unittest.cc b/components/permissions/permissions_client_unittest.cc index 8359db75a17..53e4b77ef8a 100644 --- a/components/permissions/permissions_client_unittest.cc +++ b/components/permissions/permissions_client_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "components/permissions/permissions_client.h" #include "components/content_settings/core/common/content_settings_types.h" #include "testing/gtest/include/gtest/gtest.h" diff --git a/components/playlist/browser/media_detector_component_installer.cc b/components/playlist/browser/media_detector_component_installer.cc index af1c3e367e5..a6156b8ffb2 100644 --- a/components/playlist/browser/media_detector_component_installer.cc +++ b/components/playlist/browser/media_detector_component_installer.cc @@ -125,7 +125,7 @@ base::FilePath MediaDetectorComponentInstallerPolicy::GetRelativeInstallDir() void MediaDetectorComponentInstallerPolicy::GetHash( std::vector* hash) const { - hash->assign(component_hash_, component_hash_ + kHashSize); + hash->assign(component_hash_, UNSAFE_TODO(component_hash_ + kHashSize)); } std::string MediaDetectorComponentInstallerPolicy::GetName() const { diff --git a/components/playlist/browser/playlist_thumbnail_downloader.cc b/components/playlist/browser/playlist_thumbnail_downloader.cc index 9ba87c50fe3..ec211445cef 100644 --- a/components/playlist/browser/playlist_thumbnail_downloader.cc +++ b/components/playlist/browser/playlist_thumbnail_downloader.cc @@ -202,8 +202,8 @@ void PlaylistThumbnailDownloader::WriteToFile( auto write_to_file = base::BindOnce( [](base::FilePath path, scoped_refptr image) { - if (!base::WriteFile(path, base::span(image->front(), - image->size()))) { + if (!base::WriteFile(path, UNSAFE_TODO(base::span( + image->front(), image->size())))) { DVLOG(2) << "Failed to write image to file " << path; return base::FilePath(); } diff --git a/components/psst/browser/core/psst_component_installer.cc b/components/psst/browser/core/psst_component_installer.cc index 69f799c3a21..ccb35e06e67 100644 --- a/components/psst/browser/core/psst_component_installer.cc +++ b/components/psst/browser/core/psst_component_installer.cc @@ -130,7 +130,7 @@ base::FilePath PsstComponentInstallerPolicy::GetRelativeInstallDir() const { } void PsstComponentInstallerPolicy::GetHash(std::vector* hash) const { - hash->assign(component_hash_, component_hash_ + kHashSize); + hash->assign(component_hash_, UNSAFE_TODO(component_hash_ + kHashSize)); } std::string PsstComponentInstallerPolicy::GetName() const { diff --git a/components/script_injector/renderer/script_injector_render_frame_observer.cc b/components/script_injector/renderer/script_injector_render_frame_observer.cc index 4b72aabc775..2107e0e5484 100644 --- a/components/script_injector/renderer/script_injector_render_frame_observer.cc +++ b/components/script_injector/renderer/script_injector_render_frame_observer.cc @@ -59,8 +59,8 @@ void ScriptInjectorRenderFrameObserver::RequestAsyncExecuteScript( auto want_result = CheckIfWantResult(callback); render_frame()->GetWebFrame()->RequestExecuteScript( - world_id, base::make_span(&web_script_source, 1u), user_activation, - blink::mojom::EvaluationTiming::kAsynchronous, + world_id, UNSAFE_TODO(base::make_span(&web_script_source, 1u)), + user_activation, blink::mojom::EvaluationTiming::kAsynchronous, blink::mojom::LoadEventBlockingOption::kDoNotBlock, base::BindOnce( [](RequestAsyncExecuteScriptCallback callback, diff --git a/components/sync/service/brave_sync_service_impl_unittest.cc b/components/sync/service/brave_sync_service_impl_unittest.cc index 44cdba9a739..c0819c5c172 100644 --- a/components/sync/service/brave_sync_service_impl_unittest.cc +++ b/components/sync/service/brave_sync_service_impl_unittest.cc @@ -489,7 +489,7 @@ TEST_F(BraveSyncServiceImplTest, OnAccountDeleted_FailureAndRetry) { &on_account_deleted_invoked), sync_protocol_error); - EXPECT_EQ(on_account_deleted_invoked, was_callback_invoked[i]); + EXPECT_EQ(on_account_deleted_invoked, UNSAFE_TODO(was_callback_invoked[i])); } OSCryptMocker::TearDown(); diff --git a/components/tor/tor_control.cc b/components/tor/tor_control.cc index 7e7377b48b5..1cdb2892c73 100644 --- a/components/tor/tor_control.cc +++ b/components/tor/tor_control.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/tor/tor_control.h" #include diff --git a/components/tor/tor_control_unittest.cc b/components/tor/tor_control_unittest.cc index 46cf5c37c43..68ff55c6f85 100644 --- a/components/tor/tor_control_unittest.cc +++ b/components/tor/tor_control_unittest.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/tor/tor_control.h" #include diff --git a/components/tor/tor_file_watcher.cc b/components/tor/tor_file_watcher.cc index e7892b0144a..42196a5a85c 100644 --- a/components/tor/tor_file_watcher.cc +++ b/components/tor/tor_file_watcher.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/components/tor/tor_file_watcher.h" #include diff --git a/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc b/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc index e46a7e43380..6a80f242031 100644 --- a/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc +++ b/ios/browser/api/bookmarks/exporter/bookmark_html_writer.cc @@ -274,7 +274,8 @@ class Writer : public base::RefCountedThreadSafe { bool Write(const std::string& text) { if (!text.length()) return true; - size_t wrote = file_->WriteAtCurrentPos(text.c_str(), text.length()); + size_t wrote = + UNSAFE_TODO(file_->WriteAtCurrentPos(text.c_str(), text.length())); bool result = (wrote == text.length()); if (!result) { PLOG(ERROR) << "Could not write text to " << path_; diff --git a/ios/browser/api/bookmarks/importer/brave_bookmarks_importer.mm b/ios/browser/api/bookmarks/importer/brave_bookmarks_importer.mm index 4b1bdaf0a6d..c4e0fb4b4a4 100644 --- a/ios/browser/api/bookmarks/importer/brave_bookmarks_importer.mm +++ b/ios/browser/api/bookmarks/importer/brave_bookmarks_importer.mm @@ -217,7 +217,7 @@ // Filter out the URLs with unsupported schemes. const char* const kInvalidSchemes[] = {"wyciwyg", "place", "about", "chrome"}; for (size_t i = 0; i < std::size(kInvalidSchemes); ++i) { - if (url.SchemeIs(kInvalidSchemes[i])) { + if (UNSAFE_TODO(url.SchemeIs(kInvalidSchemes[i]))) { return false; } } diff --git a/ios/browser/api/bookmarks/importer/favicon_reencode.mm b/ios/browser/api/bookmarks/importer/favicon_reencode.mm index 0ae7452801e..5a12b0604e3 100644 --- a/ios/browser/api/bookmarks/importer/favicon_reencode.mm +++ b/ios/browser/api/bookmarks/importer/favicon_reencode.mm @@ -4,9 +4,12 @@ * You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "brave/ios/browser/api/bookmarks/importer/favicon_reencode.h" + #import #import +#import "base/compiler_specific.h" + namespace gfx { //FROM: ui/gfx/geometry/size.h const int kFaviconSize = 16; @@ -59,7 +62,8 @@ bool ReencodeFavicon(const unsigned char* src_data, } const unsigned char *png_bytes = static_cast([ios_png_data bytes]); - png_data->insert(png_data->begin(), png_bytes, png_bytes + [ios_png_data length]); + png_data->insert(png_data->begin(), + UNSAFE_TODO(png_bytes, png_bytes + [ios_png_data length])); return true; } diff --git a/ios/browser/api/certificate/brave_certificate.mm b/ios/browser/api/certificate/brave_certificate.mm index 6804d8da250..4eb315708e0 100644 --- a/ios/browser/api/certificate/brave_certificate.mm +++ b/ios/browser/api/certificate/brave_certificate.mm @@ -54,9 +54,9 @@ SecCertificateCopyKey(certificate)); bssl::UniquePtr cert_buffer( - net::x509_util::CreateCryptoBuffer(base::make_span( + net::x509_util::CreateCryptoBuffer(UNSAFE_TODO(base::make_span( CFDataGetBytePtr(cert_data_.get()), - base::checked_cast(CFDataGetLength(cert_data_.get()))))); + base::checked_cast(CFDataGetLength(cert_data_.get())))))); if (!cert_buffer) { return nullptr; diff --git a/ios/browser/api/net/certificate_utility.mm b/ios/browser/api/net/certificate_utility.mm index 5cae6a92452..480fae35cf2 100644 --- a/ios/browser/api/net/certificate_utility.mm +++ b/ios/browser/api/net/certificate_utility.mm @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #import "brave/ios/browser/api/net/certificate_utility.h" #include diff --git a/ios/browser/api/storekit_receipt/storekit_receipt.mm b/ios/browser/api/storekit_receipt/storekit_receipt.mm index 8703550193a..deecc07a865 100644 --- a/ios/browser/api/storekit_receipt/storekit_receipt.mm +++ b/ios/browser/api/storekit_receipt/storekit_receipt.mm @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/ios/browser/api/storekit_receipt/storekit_receipt.h" #include diff --git a/ios/browser/ui/webui/brave_webui_source.mm b/ios/browser/ui/webui/brave_webui_source.mm index 43a8bc2d4ab..85c6b6a454d 100644 --- a/ios/browser/ui/webui/brave_webui_source.mm +++ b/ios/browser/ui/webui/brave_webui_source.mm @@ -41,7 +41,8 @@ web::WebUIIOSDataSource* CreateWebUIDataSource( source); source->UseStringsJs(); - source->AddResourcePaths(base::make_span(resource_map, resource_map_size)); + source->AddResourcePaths( + UNSAFE_TODO(base::make_span(resource_map, resource_map_size))); source->SetDefaultResource(html_resource_id); CustomizeWebUIHTMLSource(web_ui, name, source); return source; diff --git a/ios/browser/ui/webui/skus/skus_internals_ui.mm b/ios/browser/ui/webui/skus/skus_internals_ui.mm index 08f82d40893..b6b2c47e934 100644 --- a/ios/browser/ui/webui/skus/skus_internals_ui.mm +++ b/ios/browser/ui/webui/skus/skus_internals_ui.mm @@ -51,7 +51,8 @@ web::WebUIIOSDataSource* CreateAndAddWebUIDataSource( source->UseStringsJs(); // Add required resources. - source->AddResourcePaths(base::make_span(resource_map, resource_map_size)); + source->AddResourcePaths( + UNSAFE_TODO(base::make_span(resource_map, resource_map_size))); source->SetDefaultResource(html_resource_id); return source; } diff --git a/net/http/partitioned_host_state_map.cc b/net/http/partitioned_host_state_map.cc index 8da7e9d6bc9..cfe50457f06 100644 --- a/net/http/partitioned_host_state_map.cc +++ b/net/http/partitioned_host_state_map.cc @@ -8,6 +8,7 @@ #include #include +#include "base/compiler_specific.h" #include "base/ranges/algorithm.h" #include "crypto/sha2.h" #include "net/base/network_isolation_key.h" @@ -61,7 +62,7 @@ PartitionedHostStateMapBase::GetKeyWithPartitionHash( base::span PartitionedHostStateMapBase::GetHalfKey( const HashedHost& k) { - return base::make_span(k.data(), std::size(k) / 2); + return UNSAFE_TODO(base::make_span(k.data(), std::size(k) / 2)); } } // namespace net diff --git a/sandbox/win/src/module_file_name_interception.cc b/sandbox/win/src/module_file_name_interception.cc index 0631fa3df8a..bdca4d59c98 100644 --- a/sandbox/win/src/module_file_name_interception.cc +++ b/sandbox/win/src/module_file_name_interception.cc @@ -3,6 +3,12 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(https://github.com/brave/brave-browser/issues/41661): Remove this and +// convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/sandbox/win/src/module_file_name_interception.h" #include diff --git a/third_party/blink/renderer/brave_font_whitelist.cc b/third_party/blink/renderer/brave_font_whitelist.cc index 4792f600e16..131d4b65a7b 100644 --- a/third_party/blink/renderer/brave_font_whitelist.cc +++ b/third_party/blink/renderer/brave_font_whitelist.cc @@ -3,6 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(crbug.com/ABC): Remove this and convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/third_party/blink/renderer/brave_font_whitelist.h" #include diff --git a/third_party/blink/renderer/core/brave_page_graph/requests/tracked_request.cc b/third_party/blink/renderer/core/brave_page_graph/requests/tracked_request.cc index 8e6c50a7d44..8a9eaf6d858 100644 --- a/third_party/blink/renderer/core/brave_page_graph/requests/tracked_request.cc +++ b/third_party/blink/renderer/core/brave_page_graph/requests/tracked_request.cc @@ -157,9 +157,7 @@ void TrackedRequest::UpdateResponseBodyHash(base::span data) { if (!data.data()) { return; } - base::span uint8_span( - reinterpret_cast(data.data()), data.size()); - CHECK(body_digestor_.Update(uint8_span)); + CHECK(body_digestor_.Update(base::as_byte_span(data))); } void TrackedRequest::FinishResponseBodyHash() { diff --git a/third_party/blink/renderer/core/farbling/brave_session_cache.cc b/third_party/blink/renderer/core/farbling/brave_session_cache.cc index f42f44dcce9..62695f70fdf 100644 --- a/third_party/blink/renderer/core/farbling/brave_session_cache.cc +++ b/third_party/blink/renderer/core/farbling/brave_session_cache.cc @@ -3,6 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at http://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(crbug.com/ABC): Remove this and convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/third_party/blink/renderer/core/farbling/brave_session_cache.h" #include diff --git a/third_party/blink/renderer/platform/brave_audio_farbling_helper.cc b/third_party/blink/renderer/platform/brave_audio_farbling_helper.cc index 87fa66907d8..6dd12c5bc3a 100644 --- a/third_party/blink/renderer/platform/brave_audio_farbling_helper.cc +++ b/third_party/blink/renderer/platform/brave_audio_farbling_helper.cc @@ -3,6 +3,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this file, * You can obtain one at https://mozilla.org/MPL/2.0/. */ +#ifdef UNSAFE_BUFFERS_BUILD +// TODO(crbug.com/ABC): Remove this and convert code to safer constructs. +#pragma allow_unsafe_buffers +#endif + #include "brave/third_party/blink/renderer/platform/brave_audio_farbling_helper.h" #include