Continue with still even more unsafe_buffer suppressions in tests

Bug: 42271175
Change-Id: I9660b29eb5049ee2a01c12859391ec486494fb41
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/120251
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Thomas Sepez <tsepez@google.com>
diff --git a/core/fdrm/fx_crypt_unittest.cpp b/core/fdrm/fx_crypt_unittest.cpp
index 86e2aaf..6c774fe 100644
--- a/core/fdrm/fx_crypt_unittest.cpp
+++ b/core/fdrm/fx_crypt_unittest.cpp
@@ -2,11 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "core/fdrm/fx_crypt.h"
 
 #include <algorithm>
@@ -20,6 +15,7 @@
 #include "testing/utils/hash.h"
 
 using ::testing::ElementsAre;
+using ::testing::ElementsAreArray;
 
 namespace {
 
@@ -30,11 +26,10 @@
 void CheckArcFourContext(const CRYPT_rc4_context& context,
                          int32_t expected_x,
                          int32_t expected_y,
-                         const uint8_t* expected_permutation) {
+                         pdfium::span<const uint8_t> expected_permutation) {
   EXPECT_EQ(expected_x, context.x);
   EXPECT_EQ(expected_y, context.y);
-  for (int32_t i = 0; i < CRYPT_rc4_context::kPermutationLength; ++i)
-    EXPECT_EQ(expected_permutation[i], context.m[i]) << i;
+  EXPECT_THAT(context.m, ElementsAreArray(expected_permutation));
 }
 
 }  // namespace
@@ -325,19 +320,15 @@
     CRYPT_rc4_context context;
     CRYPT_ArcFourSetup(&context, {});
 
-    uint8_t data_short[std::size(kDataShort)];
-    FXSYS_memcpy(data_short, kDataShort, std::size(kDataShort));
+    std::vector<uint8_t> data_short(std::begin(kDataShort),
+                                    std::end(kDataShort));
     static const uint8_t kExpectedEncryptedDataShort[] = {
         138, 112, 236, 97,  242, 66,  52,  89,  225, 38,  88,  8,
         47,  78,  216, 24,  170, 106, 26,  199, 208, 131, 157, 242,
         55,  11,  25,  90,  66,  182, 19,  255, 210, 181, 85,  69,
         31,  240, 206, 171, 97,  62,  202, 172, 30,  252};
-    static_assert(
-        std::size(kExpectedEncryptedDataShort) == std::size(data_short),
-        "data_short mismatch");
     CRYPT_ArcFourCrypt(&context, data_short);
-    for (size_t i = 0; i < std::size(data_short); ++i)
-      EXPECT_EQ(kExpectedEncryptedDataShort[i], data_short[i]) << i;
+    EXPECT_THAT(data_short, ElementsAreArray(kExpectedEncryptedDataShort));
 
     static const uint8_t kPermutation[CRYPT_rc4_context::kPermutationLength] = {
         0,   198, 10,  37,  253, 192, 171, 183, 99,  8,   144, 103, 208, 191,
@@ -365,8 +356,7 @@
     CRYPT_rc4_context context;
     CRYPT_ArcFourSetup(&context, {});
 
-    uint8_t data_long[std::size(kDataLong)];
-    FXSYS_memcpy(data_long, kDataLong, std::size(kDataLong));
+    std::vector<uint8_t> data_long(std::begin(kDataLong), std::end(kDataLong));
     static const uint8_t kExpectedEncryptedDataLong[] = {
         138, 112, 236, 97,  242, 66,  52,  89,  225, 38,  88,  8,   47,  78,
         216, 24,  170, 106, 26,  199, 208, 131, 157, 242, 55,  11,  25,  90,
@@ -388,12 +378,8 @@
         208, 161, 105, 226, 164, 114, 80,  137, 58,  107, 109, 42,  110, 100,
         202, 170, 224, 89,  28,  5,   138, 19,  253, 105, 220, 105, 24,  187,
         109, 89,  205, 89,  202};
-    static_assert(std::size(kExpectedEncryptedDataLong) == std::size(data_long),
-                  "data_long mismatch");
-    static_assert(std::size(data_long) > 256, "too short");
     CRYPT_ArcFourCrypt(&context, data_long);
-    for (size_t i = 0; i < std::size(data_long); ++i)
-      EXPECT_EQ(kExpectedEncryptedDataLong[i], data_long[i]) << i;
+    EXPECT_THAT(data_long, ElementsAreArray(kExpectedEncryptedDataLong));
 
     static const uint8_t kPermutation[CRYPT_rc4_context::kPermutationLength] = {
         172, 59,  196, 72,  101, 21,  215, 210, 212, 52,  243, 73,  47,  213,
@@ -422,19 +408,15 @@
     ByteStringView foobar = "foobar";
     CRYPT_ArcFourSetup(&context, foobar.unsigned_span());
 
-    uint8_t data_short[std::size(kDataShort)];
-    FXSYS_memcpy(data_short, kDataShort, std::size(kDataShort));
+    std::vector<uint8_t> data_short(std::begin(kDataShort),
+                                    std::end(kDataShort));
     static const uint8_t kExpectedEncryptedDataShort[] = {
         59,  193, 117, 206, 167, 54,  218, 7,   229, 214, 188, 55,
         90,  205, 196, 25,  36,  114, 199, 218, 161, 107, 122, 119,
         106, 167, 44,  175, 240, 123, 192, 102, 174, 167, 105, 187,
         202, 70,  121, 81,  17,  30,  5,   138, 116, 166};
-    static_assert(
-        std::size(kExpectedEncryptedDataShort) == std::size(data_short),
-        "data_short mismatch");
     CRYPT_ArcFourCrypt(&context, data_short);
-    for (size_t i = 0; i < std::size(data_short); ++i)
-      EXPECT_EQ(kExpectedEncryptedDataShort[i], data_short[i]) << i;
+    EXPECT_THAT(data_short, ElementsAreArray(kExpectedEncryptedDataShort));
 
     static const uint8_t kPermutation[CRYPT_rc4_context::kPermutationLength] = {
         102, 41,  45,  82,  124, 141, 237, 38,  6,   64,  90,  140, 254, 96,
@@ -463,8 +445,7 @@
     ByteStringView foobar = "foobar";
     CRYPT_ArcFourSetup(&context, foobar.unsigned_span());
 
-    uint8_t data_long[std::size(kDataLong)];
-    FXSYS_memcpy(data_long, kDataLong, std::size(kDataLong));
+    std::vector<uint8_t> data_long(std::begin(kDataLong), std::end(kDataLong));
     static const uint8_t kExpectedEncryptedDataLong[] = {
         59,  193, 117, 206, 167, 54,  218, 7,   229, 214, 188, 55,  90,  205,
         196, 25,  36,  114, 199, 218, 161, 107, 122, 119, 106, 167, 44,  175,
@@ -486,12 +467,9 @@
         22,  110, 43,  56,  94,  127, 48,  96,  47,  172, 3,   31,  130, 249,
         243, 73,  206, 89,  9,   93,  156, 167, 205, 166, 75,  227, 36,  34,
         81,  124, 195, 246, 152};
-    static_assert(std::size(kExpectedEncryptedDataLong) == std::size(data_long),
-                  "data_long mismatch");
-    static_assert(std::size(data_long) > 256, "too short");
+    static_assert(std::size(kDataLong) > 256, "too short");
     CRYPT_ArcFourCrypt(&context, data_long);
-    for (size_t i = 0; i < std::size(data_long); ++i)
-      EXPECT_EQ(kExpectedEncryptedDataLong[i], data_long[i]) << i;
+    EXPECT_THAT(data_long, ElementsAreArray(kExpectedEncryptedDataLong));
 
     static const uint8_t kPermutation[CRYPT_rc4_context::kPermutationLength] = {
         188, 12,  81,  130, 228, 58,  124, 218, 72,  210, 50,  70,  166, 38,
diff --git a/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp b/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp
index e91c19b..4bbaafb 100644
--- a/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp
+++ b/core/fpdfapi/page/cpdf_pageobjectholder_unittest.cpp
@@ -2,16 +2,12 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "core/fpdfapi/page/cpdf_pageobjectholder.h"
 
 #include <math.h>
 
 #include <algorithm>
+#include <array>
 #include <limits>
 #include <vector>
 
@@ -60,7 +56,7 @@
   EXPECT_EQ(72u, graphics_map.size());
 
   // clang-format off
-  const int expected[72] = {
+  std::array<const int, 72> expected = {
       71, 35, 65, 29, 59, 23, 53, 17, 47, 11, 41, 5,
       70, 34, 64, 28, 58, 22, 52, 16, 46, 10, 40, 4,
       69, 33, 63, 27, 57, 21, 51, 15, 45, 9,  39, 3,
diff --git a/core/fxcodec/basic/a85_unittest.cpp b/core/fxcodec/basic/a85_unittest.cpp
index 70b7322..b4e1152 100644
--- a/core/fxcodec/basic/a85_unittest.cpp
+++ b/core/fxcodec/basic/a85_unittest.cpp
@@ -2,13 +2,9 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include <stdint.h>
 
+#include <array>
 #include <iterator>
 #include <limits>
 #include <memory>
@@ -94,7 +90,7 @@
 // Make sure we get returns in the expected locations.
 TEST(fxcodec, A85LineBreaks) {
   // Make sure really big values don't break.
-  uint8_t src_buf[131] = {0};
+  std::array<uint8_t, 131> src_buf = {};
   // 1 full line + most of a line of normal symbols.
   for (int k = 0; k < 116; k += 4) {
     src_buf[k] = 1;
diff --git a/core/fxcodec/basic/rle_unittest.cpp b/core/fxcodec/basic/rle_unittest.cpp
index 3866682..b37a713 100644
--- a/core/fxcodec/basic/rle_unittest.cpp
+++ b/core/fxcodec/basic/rle_unittest.cpp
@@ -2,13 +2,9 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include <stdint.h>
 
+#include <array>
 #include <limits>
 #include <memory>
 
@@ -66,14 +62,14 @@
 TEST(fxcodec, RLEFullLengthInputs) {
   {
     // Case 1: Match, match
-    const uint8_t src_buf_1[260] = {1};
+    std::array<uint8_t, 260> src_buf_1 = {{1}};
     DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_1);
     DataAndBytesConsumed result = RunLengthDecode(dest_buf);
     EXPECT_THAT(result.data, ElementsAreArray(src_buf_1));
   }
   {
     // Case 2: Match, non-match
-    uint8_t src_buf_2[260] = {2};
+    std::array<uint8_t, 260> src_buf_2 = {{2}};
     for (uint16_t i = 128; i < 260; i++)
       src_buf_2[i] = static_cast<uint8_t>(i - 125);
     DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_2);
@@ -82,7 +78,7 @@
   }
   {
     // Case 3: Non-match, match
-    uint8_t src_buf_3[260] = {};
+    std::array<uint8_t, 260> src_buf_3 = {};
     for (uint8_t i = 0; i < 128; i++)
       src_buf_3[i] = i;
     DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_3);
@@ -91,7 +87,7 @@
   }
   {
     // Case 4: Non-match, non-match
-    uint8_t src_buf_4[260];
+    std::array<uint8_t, 260> src_buf_4;
     for (uint16_t i = 0; i < 260; i++)
       src_buf_4[i] = static_cast<uint8_t>(i);
     DataVector<uint8_t> dest_buf = BasicModule::RunLengthEncode(src_buf_4);
diff --git a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
index 8ef9743..243a469 100644
--- a/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
+++ b/core/fxcodec/gif/cfx_gifcontext_unittest.cpp
@@ -2,11 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "core/fxcodec/gif/cfx_gifcontext.h"
 
 #include <stdint.h>
@@ -14,6 +9,7 @@
 #include <utility>
 
 #include "core/fxcodec/cfx_codec_memory.h"
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/span_util.h"
 #include "testing/gtest/include/gtest/gtest.h"
@@ -73,13 +69,13 @@
 
   context.SetTestInputBuffer(src_buffer);
   EXPECT_TRUE(context.ReadAllOrNone(dest_span.first(sizeof(src_buffer))));
-  for (size_t i = 0; i < sizeof(src_buffer); i++)
-    EXPECT_EQ(src_buffer[i], dest_buffer[i]);
-
+  for (size_t i = 0; i < sizeof(src_buffer); i++) {
+    UNSAFE_TODO(EXPECT_EQ(src_buffer[i], dest_buffer[i]));
+  }
   context.SetTestInputBuffer(src_buffer);
   for (size_t i = 0; i < sizeof(src_buffer); i++) {
     EXPECT_TRUE(context.ReadAllOrNone(dest_span.first(1u)));
-    EXPECT_EQ(src_buffer[i], dest_buffer[0]);
+    UNSAFE_TODO(EXPECT_EQ(src_buffer[i], dest_buffer[0]));
   }
 }
 
diff --git a/core/fxcodec/gif/lzw_decompressor_unittest.cpp b/core/fxcodec/gif/lzw_decompressor_unittest.cpp
index 35aadb4..f54e8b1 100644
--- a/core/fxcodec/gif/lzw_decompressor_unittest.cpp
+++ b/core/fxcodec/gif/lzw_decompressor_unittest.cpp
@@ -2,11 +2,6 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "core/fxcodec/gif/lzw_decompressor.h"
 
 #include <stdint.h>
@@ -14,11 +9,14 @@
 
 #include <iterator>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/data_vector.h"
 #include "core/fxcrt/stl_util.h"
 #include "testing/gmock/include/gmock/gmock.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
+using ::testing::Each;
+using ::testing::ElementsAre;
 using ::testing::ElementsAreArray;
 
 TEST(LZWDecompressor, CreateBadParams) {
@@ -42,9 +40,7 @@
     fxcrt::Fill(dest_buf, 0xff);
     EXPECT_EQ(0u, decompressor->ExtractDataForTest(
                       pdfium::make_span(dest_buf).first(0u)));
-    for (size_t i = 0; i < std::size(dest_buf); ++i) {
-      EXPECT_EQ(static_cast<uint8_t>(-1), dest_buf[i]);
-    }
+    EXPECT_THAT(dest_buf, Each(static_cast<uint8_t>(-1)));
     EXPECT_EQ(10u, *(decompressor->DecompressedNextForTest()));
     for (size_t i = 0; i < *(decompressor->DecompressedNextForTest()); ++i) {
       EXPECT_EQ(i, (*decompressed)[i]);
@@ -62,11 +58,11 @@
                       pdfium::make_span(dest_buf).first(5u)));
     size_t i = 0;
     for (; i < 5; ++i) {
-      EXPECT_EQ(9 - i, dest_buf[i]);
+      EXPECT_EQ(9 - i, UNSAFE_TODO(dest_buf[i]));
     }
-    for (; i < std::size(dest_buf); ++i) {
-      EXPECT_EQ(static_cast<uint8_t>(-1), dest_buf[i]);
-    }
+    EXPECT_THAT(pdfium::span(dest_buf).first(5), ElementsAre(9, 8, 7, 6, 5));
+    EXPECT_THAT(pdfium::span(dest_buf).subspan(5),
+                Each(static_cast<uint8_t>(-1)));
     EXPECT_EQ(5u, *(decompressor->DecompressedNextForTest()));
     for (i = 0; i < *(decompressor->DecompressedNextForTest()); ++i) {
       EXPECT_EQ(i, (*decompressed)[i]);
@@ -81,13 +77,10 @@
     uint8_t dest_buf[20];
     fxcrt::Fill(dest_buf, 0xff);
     EXPECT_EQ(10u, decompressor->ExtractDataForTest(dest_buf));
-    size_t i = 0;
-    for (; i < 10; ++i) {
-      EXPECT_EQ(9 - i, dest_buf[i]);
-    }
-    for (; i < std::size(dest_buf); ++i) {
-      EXPECT_EQ(static_cast<uint8_t>(-1), dest_buf[i]);
-    }
+    EXPECT_THAT(pdfium::span(dest_buf).first(10),
+                ElementsAre(9, 8, 7, 6, 5, 4, 3, 2, 1, 0));
+    EXPECT_THAT(pdfium::span(dest_buf).subspan(10),
+                Each(static_cast<uint8_t>(-1)));
     EXPECT_EQ(0u, *(decompressor->DecompressedNextForTest()));
   }
 }
@@ -104,17 +97,17 @@
 
   decompressor->SetSource(pdfium::span<uint8_t>());
   EXPECT_EQ(LZWDecompressor::Status::kError,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
 
   decompressor->SetSource(image_data);
   EXPECT_EQ(LZWDecompressor::Status::kError,
-            decompressor->Decode(nullptr, &output_size));
+            UNSAFE_TODO(decompressor->Decode(nullptr, &output_size)));
   EXPECT_EQ(LZWDecompressor::Status::kError,
-            decompressor->Decode(output_data, nullptr));
+            UNSAFE_TODO(decompressor->Decode(output_data, nullptr)));
 
   output_size = 0;
   EXPECT_EQ(LZWDecompressor::Status::kInsufficientDestSize,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
 }
 
 TEST(LZWDecompressor, Decode1x1SingleColour) {
@@ -130,7 +123,7 @@
 
   decompressor->SetSource(image_data);
   EXPECT_EQ(LZWDecompressor::Status::kSuccess,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
 
   EXPECT_EQ(std::size(output_data), output_size);
   EXPECT_TRUE(0 == memcmp(expected_data, output_data, sizeof(expected_data)));
@@ -159,7 +152,7 @@
 
   decompressor->SetSource(kImageData);
   EXPECT_EQ(LZWDecompressor::Status::kSuccess,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
 
   EXPECT_EQ(std::size(output_data), output_size);
   EXPECT_TRUE(0 == memcmp(kExpectedData, output_data, sizeof(kExpectedData)));
@@ -189,7 +182,7 @@
 
   decompressor->SetSource(kImageData);
   EXPECT_EQ(LZWDecompressor::Status::kSuccess,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
 
   EXPECT_EQ(std::size(output_data), output_size);
   EXPECT_TRUE(0 == memcmp(kExpectedData, output_data, sizeof(kExpectedData)));
@@ -207,14 +200,14 @@
   fxcrt::Fill(output_data, 0xff);
   uint32_t output_size = std::size(output_data);
   EXPECT_EQ(LZWDecompressor::Status::kInsufficientDestSize,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
   EXPECT_EQ(std::size(kExpectedScanline), output_size);
   EXPECT_THAT(output_data, ElementsAreArray(kExpectedScanline));
 
   fxcrt::Fill(output_data, 0xff);
   output_size = std::size(output_data);
   EXPECT_EQ(LZWDecompressor::Status::kSuccess,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
   EXPECT_EQ(std::size(kExpectedScanline), output_size);
   EXPECT_THAT(output_data, ElementsAreArray(kExpectedScanline));
 }
@@ -236,5 +229,5 @@
 
   decompressor->SetSource(kImageData);
   EXPECT_EQ(LZWDecompressor::Status::kError,
-            decompressor->Decode(output_data, &output_size));
+            UNSAFE_TODO(decompressor->Decode(output_data, &output_size)));
 }
diff --git a/core/fxcodec/jbig2/JBig2_Image_unittest.cpp b/core/fxcodec/jbig2/JBig2_Image_unittest.cpp
index d66da92..06436a5 100644
--- a/core/fxcodec/jbig2/JBig2_Image_unittest.cpp
+++ b/core/fxcodec/jbig2/JBig2_Image_unittest.cpp
@@ -2,17 +2,13 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 // TODO(tsepez) this requires a lot more testing.
 
 #include "core/fxcodec/jbig2/JBig2_Image.h"
 
 #include <stdint.h>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "testing/gtest/include/gtest/gtest.h"
 
 namespace {
@@ -62,14 +58,14 @@
   EXPECT_EQ(0, img.GetPixel(0, 0));
   EXPECT_EQ(0, img.GetLine(0)[0]);
   EXPECT_EQ(0, img.GetPixel(kWidthPixels - 1, kHeightLines - 1));
-  EXPECT_EQ(0, img.GetLine(kHeightLines - 1)[kWidthBytes - 1]);
+  EXPECT_EQ(0, UNSAFE_TODO(img.GetLine(kHeightLines - 1)[kWidthBytes - 1]));
 
   img.SetPixel(0, 0, true);
   img.SetPixel(kWidthPixels - 1, kHeightLines - 1, true);
   EXPECT_EQ(1, img.GetPixel(0, 0));
   EXPECT_EQ(1, img.GetPixel(kWidthPixels - 1, kHeightLines - 1));
   EXPECT_EQ(0x80, img.GetLine(0)[0]);
-  EXPECT_EQ(0x01, img.GetLine(kHeightLines - 1)[kWidthBytes - 1]);
+  EXPECT_EQ(0x01, UNSAFE_TODO(img.GetLine(kHeightLines - 1)[kWidthBytes - 1]));
 
   // Out-of-bounds SetPixel() is silent no-op.
   img.SetPixel(-1, 1, true);
diff --git a/core/fxge/dib/cfx_dibitmap_unittest.cpp b/core/fxge/dib/cfx_dibitmap_unittest.cpp
index 4674198..c859324 100644
--- a/core/fxge/dib/cfx_dibitmap_unittest.cpp
+++ b/core/fxge/dib/cfx_dibitmap_unittest.cpp
@@ -2,15 +2,11 @@
 // Use of this source code is governed by a BSD-style license that can be
 // found in the LICENSE file.
 
-#if defined(UNSAFE_BUFFERS_BUILD)
-// TODO(crbug.com/pdfium/2154): resolve buffer safety issues.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "core/fxge/dib/cfx_dibitmap.h"
 
 #include <stdint.h>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/fx_coordinates.h"
 #include "core/fxcrt/span.h"
 #include "core/fxge/dib/fx_dib.h"
@@ -126,10 +122,9 @@
 TEST(CFX_DIBitmap, UnPreMultiply_FromCleared) {
   auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
   ASSERT_TRUE(bitmap->Create(1, 1, FXDIB_Format::kArgb));
-  FXARGB_SetDIB(bitmap->GetWritableBuffer().data(), 0x7f'7f'7f'7f);
+  UNSAFE_TODO(FXARGB_SetDIB(bitmap->GetWritableBuffer().data(), 0x7f'7f'7f'7f));
 
   bitmap->UnPreMultiply();
-
   EXPECT_THAT(bitmap->GetBuffer(), ElementsAre(0xff, 0xff, 0xff, 0x7f));
 }
 
@@ -137,10 +132,9 @@
   auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
   ASSERT_TRUE(bitmap->Create(1, 1, FXDIB_Format::kArgb));
   bitmap->ForcePreMultiply();
-  FXARGB_SetDIB(bitmap->GetWritableBuffer().data(), 0x7f'7f'7f'7f);
+  UNSAFE_TODO(FXARGB_SetDIB(bitmap->GetWritableBuffer().data(), 0x7f'7f'7f'7f));
 
   bitmap->UnPreMultiply();
-
   EXPECT_THAT(bitmap->GetBuffer(), ElementsAre(0xff, 0xff, 0xff, 0x7f));
 }
 
@@ -148,10 +142,9 @@
   auto bitmap = pdfium::MakeRetain<CFX_DIBitmap>();
   ASSERT_TRUE(bitmap->Create(1, 1, FXDIB_Format::kArgb));
   bitmap->UnPreMultiply();
-  FXARGB_SetDIB(bitmap->GetWritableBuffer().data(), 0x7f'ff'ff'ff);
+  UNSAFE_TODO(FXARGB_SetDIB(bitmap->GetWritableBuffer().data(), 0x7f'ff'ff'ff));
 
   bitmap->UnPreMultiply();
-
   EXPECT_THAT(bitmap->GetBuffer(), ElementsAre(0xff, 0xff, 0xff, 0x7f));
 }
 #endif  // defined(PDF_USE_SKIA)