diff --git a/media/gpu/vaapi/test/h265_decoder.cc b/media/gpu/vaapi/test/h265_decoder.cc
index cba76a2dc1fcf..0ab459d12f17f 100644
--- a/media/gpu/vaapi/test/h265_decoder.cc
+++ b/media/gpu/vaapi/test/h265_decoder.cc
@@ -2,10 +2,7 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
+
 
 #include "media/gpu/vaapi/test/h265_decoder.h"
 
@@ -395,7 +392,8 @@ bool H265Decoder::ProcessCurrentSlice() {
   return wrapper_.SubmitSlice(
       sps, pps, slice_hdr, ref_pic_list0_, ref_pic_list1_, ref_pic_set_lt_curr_,
       ref_pic_set_st_curr_after_, ref_pic_set_st_curr_before_, curr_pic_.get(),
-      slice_hdr->nalu_data, slice_hdr->nalu_size,
+      UNSAFE_BUFFERS(base::span<const uint8_t>(slice_hdr->nalu_data.get(),
+                                            slice_hdr->nalu_size)),
       parser_.GetCurrentSubsamples());
 }
 
diff --git a/media/gpu/vaapi/test/h265_vaapi_wrapper.cc b/media/gpu/vaapi/test/h265_vaapi_wrapper.cc
index 32ce0746d96fa..bc1c79db9732b 100644
--- a/media/gpu/vaapi/test/h265_vaapi_wrapper.cc
+++ b/media/gpu/vaapi/test/h265_vaapi_wrapper.cc
@@ -2,10 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
+#include "base/containers/span.h"
+
+
+
+
 
 #include "media/gpu/vaapi/test/h265_vaapi_wrapper.h"
 
@@ -66,7 +67,6 @@ scoped_refptr<H265Picture> H265VaapiWrapper::CreateH265Picture(
   }
 
   VASurfaceAttrib attribute{};
-  memset(&attribute, 0, sizeof(attribute));
   attribute.type = VASurfaceAttribUsageHint;
   attribute.flags = VA_SURFACE_ATTRIB_SETTABLE;
   attribute.value.type = VAGenericValueTypeInteger;
@@ -89,8 +89,7 @@ bool H265VaapiWrapper::SubmitFrameMetadata(
     const H265Picture::Vector& ref_pic_list,
     scoped_refptr<H265Picture> pic) {
   DCHECK(!last_slice_data_.size());
-  VAPictureParameterBufferHEVC pic_param;
-  memset(&pic_param, 0, sizeof(pic_param));
+  VAPictureParameterBufferHEVC pic_param{};
 
   int highest_tid = sps->sps_max_sub_layers_minus1;
 #define FROM_SPS_TO_PP(a) pic_param.a = sps->a
@@ -148,27 +147,31 @@ bool H265VaapiWrapper::SubmitFrameMetadata(
   FROM_PPS_TO_PP(num_tile_columns_minus1);
   FROM_PPS_TO_PP(num_tile_rows_minus1);
   if (pps->uniform_spacing_flag) {
+    base::span<uint16_t> column_width_minus1 = pic_param.column_width_minus1;
     // We need to calculate this ourselves per 6.5.1 in the spec. We subtract 1
     // as well so it matches the 'minus1' usage in the struct.
     for (int i = 0; i <= pps->num_tile_columns_minus1; ++i) {
-      pic_param.column_width_minus1[i] = (((i + 1) * sps->pic_width_in_ctbs_y) /
+      column_width_minus1[i] = (((i + 1) * sps->pic_width_in_ctbs_y) /
                                           (pps->num_tile_columns_minus1 + 1)) -
                                          ((i * sps->pic_width_in_ctbs_y) /
                                           (pps->num_tile_columns_minus1 + 1)) -
                                          1;
     }
+    base::span<uint16_t> row_height_minus1 = pic_param.row_height_minus1;
     for (int j = 0; j <= pps->num_tile_rows_minus1; ++j) {
-      pic_param.row_height_minus1[j] =
+      row_height_minus1[j] =
           (((j + 1) * sps->pic_height_in_ctbs_y) /
            (pps->num_tile_rows_minus1 + 1)) -
           ((j * sps->pic_height_in_ctbs_y) / (pps->num_tile_rows_minus1 + 1)) -
           1;
     }
   } else {
+    base::span<uint16_t> column_width_minus1 = pic_param.column_width_minus1;
     for (int i = 0; i <= pps->num_tile_columns_minus1; ++i)
-      FROM_PPS_TO_PP(column_width_minus1[i]);
+      column_width_minus1[i] = pps->column_width_minus1[i];
+    base::span<uint16_t> row_height_minus1 = pic_param.row_height_minus1;
     for (int i = 0; i <= pps->num_tile_rows_minus1; ++i)
-      FROM_PPS_TO_PP(row_height_minus1[i]);
+      row_height_minus1[i] = pps->row_height_minus1[i];
   }
   FROM_PPS_TO_PP_SPF(lists_modification_present_flag);
   FROM_SPS_TO_PP_SPF(long_term_ref_pics_present_flag);
@@ -229,8 +232,7 @@ bool H265VaapiWrapper::SubmitFrameMetadata(
   if (!sps->scaling_list_enabled_flag)
     return true;
 
-  VAIQMatrixBufferHEVC iq_matrix_buf;
-  memset(&iq_matrix_buf, 0, sizeof(iq_matrix_buf));
+  VAIQMatrixBufferHEVC iq_matrix_buf{};
 
   // We already populated the IQMatrix with default values in the parser if they
   // are not present in the stream, so just fill them all in.
@@ -265,7 +267,7 @@ bool H265VaapiWrapper::SubmitFrameMetadata(
 
   for (size_t i = 0; i < H265ScalingListData::kNumScalingListMatrices; ++i) {
     for (size_t j = 0; j < H265ScalingListData::kScalingListSizeId0Count; ++j) {
-      iq_matrix_buf.ScalingList4x4[i][j] =
+      UNSAFE_BUFFERS(iq_matrix_buf.ScalingList4x4[i][j]) =
           scaling_list.GetScalingList4x4EntryInRasterOrder(/*matrix_id=*/i,
                                                            /*raster_idx=*/j);
     }
@@ -274,7 +276,7 @@ bool H265VaapiWrapper::SubmitFrameMetadata(
   for (size_t i = 0; i < H265ScalingListData::kNumScalingListMatrices; ++i) {
     for (size_t j = 0; j < H265ScalingListData::kScalingListSizeId1To3Count;
          ++j) {
-      iq_matrix_buf.ScalingList8x8[i][j] =
+      UNSAFE_BUFFERS(iq_matrix_buf.ScalingList8x8[i][j]) =
           scaling_list.GetScalingList8x8EntryInRasterOrder(/*matrix_id=*/i,
                                                            /*raster_idx=*/j);
     }
@@ -283,7 +285,7 @@ bool H265VaapiWrapper::SubmitFrameMetadata(
   for (size_t i = 0; i < H265ScalingListData::kNumScalingListMatrices; ++i) {
     for (size_t j = 0; j < H265ScalingListData::kScalingListSizeId1To3Count;
          ++j) {
-      iq_matrix_buf.ScalingList16x16[i][j] =
+      UNSAFE_BUFFERS(iq_matrix_buf.ScalingList16x16[i][j]) =
           scaling_list.GetScalingList16x16EntryInRasterOrder(/*matrix_id=*/i,
                                                              /*raster_idx=*/j);
     }
@@ -292,19 +294,19 @@ bool H265VaapiWrapper::SubmitFrameMetadata(
   for (size_t i = 0; i < H265ScalingListData::kNumScalingListMatrices; i += 3) {
     for (size_t j = 0; j < H265ScalingListData::kScalingListSizeId1To3Count;
          ++j) {
-      iq_matrix_buf.ScalingList32x32[i / 3][j] =
+      UNSAFE_BUFFERS(iq_matrix_buf.ScalingList32x32[i / 3][j]) =
           scaling_list.GetScalingList32x32EntryInRasterOrder(/*matrix_id=*/i,
                                                              /*raster_idx=*/j);
     }
   }
 
   for (size_t i = 0; i < H265ScalingListData::kNumScalingListMatrices; ++i) {
-    iq_matrix_buf.ScalingListDC16x16[i] =
+    UNSAFE_BUFFERS(iq_matrix_buf.ScalingListDC16x16[i]) =
         scaling_list.scaling_list_dc_coef_16x16[i];
   }
 
   for (size_t i = 0; i < H265ScalingListData::kNumScalingListMatrices; i += 3) {
-    iq_matrix_buf.ScalingListDC32x32[i / 3] =
+    UNSAFE_BUFFERS(iq_matrix_buf.ScalingListDC32x32[i / 3]) =
         scaling_list.scaling_list_dc_coef_32x32[i];
   }
 
@@ -321,15 +323,14 @@ bool H265VaapiWrapper::SubmitSlice(
     const H265Picture::Vector& ref_pic_set_st_curr_after,
     const H265Picture::Vector& ref_pic_set_st_curr_before,
     scoped_refptr<H265Picture> pic,
-    const uint8_t* data,
-    size_t size,
+    base::span<const uint8_t> data,
     const std::vector<SubsampleEntry>& subsamples) {
   if (!SubmitPriorSliceDataIfPresent(false)) {
     LOG(ERROR) << "Failure submitting prior slice data";
     return false;
   }
 
-  memset(&slice_param_, 0, sizeof(slice_param_));
+  slice_param_ = {};
 
   slice_param_.slice_data_size = slice_hdr->nalu_size;
   slice_param_.slice_data_flag = VA_SLICE_DATA_FLAG_ALL;
@@ -365,7 +366,7 @@ bool H265VaapiWrapper::SubmitSlice(
         LOG(ERROR) << "Error, slice reference picture is not in reference list";
         return false;
       }
-      slice_param_.RefPicList[0][i] = idx;
+      UNSAFE_BUFFERS(slice_param_.RefPicList[0][i]) = idx;
     }
   }
   for (size_t i = 0; i < ref_pic_list1_size; ++i) {
@@ -375,7 +376,7 @@ bool H265VaapiWrapper::SubmitSlice(
         LOG(ERROR) << "Error, slice reference picture is not in reference list";
         return false;
       }
-      slice_param_.RefPicList[1][i] = idx;
+      UNSAFE_BUFFERS(slice_param_.RefPicList[1][i]) = idx;
     }
   }
 
@@ -408,33 +409,33 @@ bool H265VaapiWrapper::SubmitSlice(
   SHDR_TO_SP2(pred_weight_table.delta_chroma_log2_weight_denom,
               delta_chroma_log2_weight_denom);
   for (int i = 0; i < kMaxRefIdxActive; ++i) {
-    SHDR_TO_SP2(pred_weight_table.delta_luma_weight_l0[i],
-                delta_luma_weight_l0[i]);
-    SHDR_TO_SP2(pred_weight_table.luma_offset_l0[i], luma_offset_l0[i]);
+    UNSAFE_BUFFERS(SHDR_TO_SP2(pred_weight_table.delta_luma_weight_l0[i],
+                delta_luma_weight_l0[i]));
+    UNSAFE_BUFFERS(SHDR_TO_SP2(pred_weight_table.luma_offset_l0[i], luma_offset_l0[i]));
     if (slice_hdr->IsBSlice()) {
-      SHDR_TO_SP2(pred_weight_table.delta_luma_weight_l1[i],
-                  delta_luma_weight_l1[i]);
-      SHDR_TO_SP2(pred_weight_table.luma_offset_l1[i], luma_offset_l1[i]);
+      UNSAFE_BUFFERS(SHDR_TO_SP2(pred_weight_table.delta_luma_weight_l1[i],
+                  delta_luma_weight_l1[i]));
+      UNSAFE_BUFFERS(SHDR_TO_SP2(pred_weight_table.luma_offset_l1[i], luma_offset_l1[i]));
     }
     for (int j = 0; j < 2; ++j) {
-      SHDR_TO_SP2(pred_weight_table.delta_chroma_weight_l0[i][j],
-                  delta_chroma_weight_l0[i][j]);
+      UNSAFE_BUFFERS(SHDR_TO_SP2(pred_weight_table.delta_chroma_weight_l0[i][j],
+                  delta_chroma_weight_l0[i][j]));
       int chroma_weight_l0 =
           (1 << slice_hdr->pred_weight_table.chroma_log2_weight_denom) +
           slice_hdr->pred_weight_table.delta_chroma_weight_l0[i][j];
-      slice_param_.ChromaOffsetL0[i][j] =
+      UNSAFE_BUFFERS(slice_param_.ChromaOffsetL0[i][j]) =
           Clip3(-sps->wp_offset_half_range_c, sps->wp_offset_half_range_c - 1,
                 (sps->wp_offset_half_range_c +
                  slice_hdr->pred_weight_table.delta_chroma_offset_l0[i][j] -
                  ((sps->wp_offset_half_range_c * chroma_weight_l0) >>
                   slice_hdr->pred_weight_table.chroma_log2_weight_denom)));
       if (slice_hdr->IsBSlice()) {
-        SHDR_TO_SP2(pred_weight_table.delta_chroma_weight_l1[i][j],
-                    delta_chroma_weight_l1[i][j]);
+        UNSAFE_BUFFERS(SHDR_TO_SP2(pred_weight_table.delta_chroma_weight_l1[i][j],
+                    delta_chroma_weight_l1[i][j]));
         int chroma_weight_l1 =
             (1 << slice_hdr->pred_weight_table.chroma_log2_weight_denom) +
             slice_hdr->pred_weight_table.delta_chroma_weight_l1[i][j];
-        slice_param_.ChromaOffsetL1[i][j] =
+        UNSAFE_BUFFERS(slice_param_.ChromaOffsetL1[i][j]) =
             Clip3(-sps->wp_offset_half_range_c, sps->wp_offset_half_range_c - 1,
                   (sps->wp_offset_half_range_c +
                    slice_hdr->pred_weight_table.delta_chroma_offset_l1[i][j] -
@@ -451,7 +452,7 @@ bool H265VaapiWrapper::SubmitSlice(
       slice_hdr->header_emulation_prevention_bytes;
 #endif  // BUILDFLAG(IS_CHROMEOS)
 
-  last_slice_data_.assign(data, data + size);
+  last_slice_data_.assign(data.begin(), data.end());
   return true;
 }
 
@@ -500,7 +501,7 @@ void H265VaapiWrapper::FillVAPicture(VAPictureHEVC* va_pic,
 
 void H265VaapiWrapper::FillVARefFramesFromRefList(
     const H265Picture::Vector& ref_pic_list,
-    VAPictureHEVC* va_pics) {
+    base::span<VAPictureHEVC>va_pics) {
   ref_pic_list_pocs_.clear();
   for (auto& it : ref_pic_list) {
     if (!it->IsUnused()) {
diff --git a/media/gpu/vaapi/test/h265_vaapi_wrapper.h b/media/gpu/vaapi/test/h265_vaapi_wrapper.h
index bcf3b45677181..2db5c1d7d6d47 100644
--- a/media/gpu/vaapi/test/h265_vaapi_wrapper.h
+++ b/media/gpu/vaapi/test/h265_vaapi_wrapper.h
@@ -5,6 +5,7 @@
 #ifndef MEDIA_GPU_VAAPI_TEST_H265_VAAPI_WRAPPER_H_
 #define MEDIA_GPU_VAAPI_TEST_H265_VAAPI_WRAPPER_H_
 
+#include "base/containers/span.h"
 #include "base/memory/raw_ptr.h"
 #include "base/memory/raw_ref.h"
 #include "media/gpu/vaapi/test/h265_dpb.h"
@@ -43,8 +44,7 @@ class H265VaapiWrapper {
                    const H265Picture::Vector& ref_pic_set_st_curr_after,
                    const H265Picture::Vector& ref_pic_set_st_curr_before,
                    scoped_refptr<H265Picture> pic,
-                   const uint8_t* data,
-                   size_t size,
+                   base::span<const uint8_t> data,
                    const std::vector<SubsampleEntry>& subsamples);
   bool SubmitDecode(scoped_refptr<H265Picture> pic);
   // Reset any current state that may be cached in the accelerator, dropping
@@ -55,7 +55,7 @@ class H265VaapiWrapper {
  private:
   void FillVAPicture(VAPictureHEVC* va_pic, scoped_refptr<H265Picture> pic);
   void FillVARefFramesFromRefList(const H265Picture::Vector& ref_pic_list,
-                                  VAPictureHEVC* va_pics);
+                                  base::span<VAPictureHEVC>va_pics);
 
   // Returns |kInvalidRefPicIndex| if it cannot find a picture.
   int GetRefPicIndex(int poc);
diff --git a/remoting/protocol/connection_unittest.cc b/remoting/protocol/connection_unittest.cc
index d4c027732e89f..16521bf5a03a6 100644
--- a/remoting/protocol/connection_unittest.cc
+++ b/remoting/protocol/connection_unittest.cc
@@ -2,15 +2,15 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
+#include "base/containers/span.h"
+
+
 
 #include <memory>
 #include <numbers>
 #include <utility>
 
+#include <algorithm>
 #include "base/functional/bind.h"
 #include "base/memory/ptr_util.h"
 #include "base/memory/raw_ptr.h"
@@ -99,8 +99,10 @@ class TestScreenCapturer : public DesktopCapturer {
     // Return black 100x100 frame.
     std::unique_ptr<webrtc::DesktopFrame> frame(
         new webrtc::BasicDesktopFrame(webrtc::DesktopSize(100, 100)));
-    memset(frame->data(), frame_index_,
-           frame->stride() * frame->size().height());
+    auto frame_span = UNSAFE_BUFFERS(base::span<uint8_t>(
+        frame->data(),
+        static_cast<size_t>(frame->stride() * frame->size().height())));
+    std::ranges::fill(frame_span, frame_index_);
     frame_index_++;
     frame->mutable_updated_region()->SetRect(
         webrtc::DesktopRect::MakeSize(frame->size()));
@@ -217,7 +219,11 @@ class FakeAudioPlayer : public AudioStub {
   }
 
   void Verify() {
-    const int16_t* data = reinterpret_cast<const int16_t*>(data_.data());
+    // SAFETY: data_ is populated with int16_t samples from the audio packet.
+    // The size is guaranteed to be a multiple of sizeof(int16_t).
+    base::span<const int16_t> data = UNSAFE_BUFFERS(base::span(
+        reinterpret_cast<const int16_t*>(data_.data()),
+        data_.size() / sizeof(int16_t)));
     int num_samples = data_.size() / kAudioChannels / sizeof(int16_t);
 
     // Skip the first 200 ms as these samples are more likely to be affected by
