Enforce unsafe_buffers in testing/image_diff/ directory.

Remove the last non-gtest testing directory.

Change-Id: I8b60035116bb6341f15cbcc0fe4992856e5db925
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/149150
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/testing/image_diff/image_diff.cpp b/testing/image_diff/image_diff.cpp
index 3e3e3d2..994d6de 100644
--- a/testing/image_diff/image_diff.cpp
+++ b/testing/image_diff/image_diff.cpp
@@ -17,6 +17,7 @@
 #include <string>
 #include <vector>
 
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/numerics/safe_conversions.h"
 #include "testing/image_diff/image_diff_png.h"
 #include "testing/utils/path_service.h"
@@ -91,8 +92,8 @@
     const size_t kBufSize = 1024;
     uint8_t buf[kBufSize];
     size_t num_read = 0;
-    while ((num_read = fread(buf, 1, kBufSize, f)) > 0) {
-      compressed.insert(compressed.end(), buf, buf + num_read);
+    while ((num_read = UNSAFE_TODO(fread(buf, 1, kBufSize, f))) > 0) {
+      compressed.insert(compressed.end(), buf, UNSAFE_TODO(buf + num_read));
     }
 
     fclose(f);
@@ -260,8 +261,8 @@
     float percent =
         CalculateDifferencePercentage(actual_image, pixels_different);
     const char* passed = percent > 0.0 ? "failed" : "passed";
-    printf("histogram diff: %01.2f%% %s (%d pixels differ)\n", percent, passed,
-           pixels_different);
+    UNSAFE_TODO(printf("histogram diff: %01.2f%% %s (%d pixels differ)\n",
+                       percent, passed, pixels_different));
   }
 
   const char* const diff_name = compare_histograms ? "exact diff" : "diff";
@@ -269,8 +270,8 @@
                                          max_pixel_per_channel_delta);
   float percent = CalculateDifferencePercentage(actual_image, pixels_different);
   const char* const passed = percent > 0.0 ? "failed" : "passed";
-  printf("%s: %01.2f%% %s (%d pixels differ)\n", diff_name, percent, passed,
-         pixels_different);
+  UNSAFE_TODO(printf("%s: %01.2f%% %s (%d pixels differ)\n", diff_name, percent,
+                     passed, pixels_different));
 
   if (percent > 0.0) {
     // failure: The WebKit version also writes the difference image to
@@ -391,7 +392,7 @@
 
   size_t size = png_encoding.size();
   char* ptr = reinterpret_cast<char*>(&png_encoding.front());
-  if (fwrite(ptr, 1, size, f) != size) {
+  if (UNSAFE_TODO(fwrite(ptr, 1, size, f)) != size) {
     return kStatusError;
   }
 
@@ -409,35 +410,36 @@
   std::string diff_filename;
 
   // Strip the path from the first arg
-  const char* last_separator = strrchr(argv[0], PATH_SEPARATOR);
-  std::string binary_name = last_separator ? last_separator + 1 : argv[0];
+  const char* last_separator = UNSAFE_TODO(strrchr(argv[0], PATH_SEPARATOR));
+  std::string binary_name =
+      last_separator ? UNSAFE_TODO(last_separator + 1) : argv[0];
 
   int i;
   for (i = 1; i < argc; ++i) {
-    const char* arg = argv[i];
-    if (strstr(arg, "--") != arg) {
+    const char* arg = UNSAFE_TODO(argv[i]);
+    if (UNSAFE_TODO(strstr(arg, "--")) != arg) {
       break;
     }
-    if (strcmp(arg, "--histogram") == 0) {
+    if (UNSAFE_TODO(strcmp(arg, "--histogram")) == 0) {
       histograms = true;
-    } else if (strcmp(arg, "--diff") == 0) {
+    } else if (UNSAFE_TODO(strcmp(arg, "--diff")) == 0) {
       produce_diff_image = true;
-    } else if (strcmp(arg, "--subtract") == 0) {
+    } else if (UNSAFE_TODO(strcmp(arg, "--subtract")) == 0) {
       produce_image_subtraction = true;
-    } else if (strcmp(arg, "--reverse-byte-order") == 0) {
+    } else if (UNSAFE_TODO(strcmp(arg, "--reverse-byte-order")) == 0) {
       reverse_byte_order = true;
-    } else if (strcmp(arg, "--fuzzy") == 0) {
+    } else if (UNSAFE_TODO(strcmp(arg, "--fuzzy")) == 0) {
       max_pixel_per_channel_delta = 1;
     }
   }
   if (i < argc) {
-    filename1 = argv[i++];
+    filename1 = UNSAFE_TODO(argv[i++]);
   }
   if (i < argc) {
-    filename2 = argv[i++];
+    filename2 = UNSAFE_TODO(argv[i++]);
   }
   if (i < argc) {
-    diff_filename = argv[i++];
+    diff_filename = UNSAFE_TODO(argv[i++]);
   }
 
   if (produce_diff_image || produce_image_subtraction) {
diff --git a/testing/image_diff/image_diff_png_libpng.cpp b/testing/image_diff/image_diff_png_libpng.cpp
index bb147a6..f77bc06 100644
--- a/testing/image_diff/image_diff_png_libpng.cpp
+++ b/testing/image_diff/image_diff_png_libpng.cpp
@@ -18,6 +18,7 @@
 #include <vector>
 
 #include "core/fxcrt/check_op.h"
+#include "core/fxcrt/compiler_specific.h"
 #include "core/fxcrt/fx_memcpy_wrappers.h"
 #include "core/fxcrt/notreached.h"
 
@@ -72,12 +73,14 @@
                                uint8_t* output,
                                bool* is_opaque) {
   for (int x = 0; x < pixel_width; x++) {
-    const uint8_t* pixel_in = &input[x * 4];
-    uint8_t* pixel_out = &output[x * 4];
-    pixel_out[0] = pixel_in[2];
-    pixel_out[1] = pixel_in[1];
-    pixel_out[2] = pixel_in[0];
-    pixel_out[3] = pixel_in[3];
+    UNSAFE_TODO({
+      const uint8_t* pixel_in = &input[x * 4];
+      uint8_t* pixel_out = &output[x * 4];
+      pixel_out[0] = pixel_in[2];
+      pixel_out[1] = pixel_in[1];
+      pixel_out[2] = pixel_in[0];
+      pixel_out[3] = pixel_in[3];
+    });
   }
 }
 
@@ -86,11 +89,13 @@
                      uint8_t* rgb,
                      bool* is_opaque) {
   for (int x = 0; x < pixel_width; x++) {
-    const uint8_t* pixel_in = &bgr[x * 3];
-    uint8_t* pixel_out = &rgb[x * 3];
-    pixel_out[0] = pixel_in[2];
-    pixel_out[1] = pixel_in[1];
-    pixel_out[2] = pixel_in[0];
+    UNSAFE_TODO({
+      const uint8_t* pixel_in = &bgr[x * 3];
+      uint8_t* pixel_out = &rgb[x * 3];
+      pixel_out[0] = pixel_in[2];
+      pixel_out[1] = pixel_in[1];
+      pixel_out[2] = pixel_in[0];
+    });
   }
 }
 
@@ -101,9 +106,9 @@
   const uint8_t* pixel_in = rgba;
   uint8_t* pixel_out = rgb;
   for (int x = 0; x < pixel_width; x++) {
-    FXSYS_memcpy(pixel_out, pixel_in, 3);
-    pixel_in += 4;
-    pixel_out += 3;
+    UNSAFE_TODO(FXSYS_memcpy(pixel_out, pixel_in, 3));
+    UNSAFE_TODO(pixel_in += 4);
+    UNSAFE_TODO(pixel_out += 3);
   }
 }
 
@@ -157,10 +162,12 @@
   const uint8_t* pixel_in = rgb;
   uint8_t* pixel_out = rgba;
   for (int x = 0; x < pixel_width; x++) {
-    FXSYS_memcpy(pixel_out, pixel_in, 3);
-    pixel_out[3] = 0xff;
-    pixel_in += 3;
-    pixel_out += 4;
+    UNSAFE_TODO({
+      FXSYS_memcpy(pixel_out, pixel_in, 3);
+      pixel_out[3] = 0xff;
+      pixel_in += 3;
+      pixel_out += 4;
+    });
   }
 }
 
@@ -169,12 +176,14 @@
                       uint8_t* bgra,
                       bool* is_opaque) {
   for (int x = 0; x < pixel_width; x++) {
-    const uint8_t* pixel_in = &rgb[x * 3];
-    uint8_t* pixel_out = &bgra[x * 4];
-    pixel_out[0] = pixel_in[2];
-    pixel_out[1] = pixel_in[1];
-    pixel_out[2] = pixel_in[0];
-    pixel_out[3] = 0xff;
+    UNSAFE_TODO({
+      const uint8_t* pixel_in = &rgb[x * 3];
+      uint8_t* pixel_out = &bgra[x * 4];
+      pixel_out[0] = pixel_in[2];
+      pixel_out[1] = pixel_in[1];
+      pixel_out[2] = pixel_in[0];
+      pixel_out[3] = 0xff;
+    });
   }
 }
 
@@ -303,11 +312,13 @@
   uint8_t* base = nullptr;
   base = &state->output->front();
 
-  uint8_t* dest = &base[state->width * state->output_channels * row_num];
+  uint8_t* dest =
+      UNSAFE_TODO(&base[state->width * state->output_channels * row_num]);
   if (state->row_converter) {
     state->row_converter(new_row, state->width, dest, &state->is_opaque);
   } else {
-    FXSYS_memcpy(dest, new_row, state->width * state->output_channels);
+    UNSAFE_TODO(
+        FXSYS_memcpy(dest, new_row, state->width * state->output_channels));
   }
 }
 
@@ -414,7 +425,7 @@
   PngEncoderState* state = static_cast<PngEncoderState*>(png_get_io_ptr(png));
   size_t old_size = state->out->size();
   state->out->resize(old_size + size);
-  FXSYS_memcpy(&(*state->out)[old_size], data, size);
+  UNSAFE_TODO(FXSYS_memcpy(&(*state->out)[old_size], data, size));
 }
 
 void FakeFlushCallback(png_structp png) {
@@ -427,11 +438,13 @@
                       uint8_t* rgb,
                       bool* is_opaque) {
   for (int x = 0; x < pixel_width; x++) {
-    const uint8_t* pixel_in = &bgra[x * 4];
-    uint8_t* pixel_out = &rgb[x * 3];
-    pixel_out[0] = pixel_in[2];
-    pixel_out[1] = pixel_in[1];
-    pixel_out[2] = pixel_in[0];
+    UNSAFE_TODO({
+      const uint8_t* pixel_in = &bgra[x * 4];
+      uint8_t* pixel_out = &rgb[x * 3];
+      pixel_out[0] = pixel_in[2];
+      pixel_out[1] = pixel_in[1];
+      pixel_out[2] = pixel_in[0];
+    });
   }
 }
 
@@ -441,7 +454,7 @@
 #if BUILDFLAG(IS_WIN)
   return _strdup(str);
 #else
-  return ::strdup(str);
+  return UNSAFE_TODO(::strdup(str));
 #endif
 }
 
@@ -456,8 +469,8 @@
 
   ~CommentWriter() {
     for (size_t i = 0; i < comments_.size(); ++i) {
-      free(png_text_[i].key);
-      free(png_text_[i].text);
+      free(UNSAFE_TODO(png_text_[i]).key);
+      free(UNSAFE_TODO(png_text_[i]).text);
     }
     delete[] png_text_;
   }
@@ -470,18 +483,18 @@
 
  private:
   void AddComment(size_t pos, const Comment& comment) {
-    png_text_[pos].compression = PNG_TEXT_COMPRESSION_NONE;
+    UNSAFE_TODO(png_text_[pos]).compression = PNG_TEXT_COMPRESSION_NONE;
     // A PNG comment's key can only be 79 characters long.
     if (comment.key.size() > 79) {
       return;
     }
-    png_text_[pos].key = strdup(comment.key.substr(0, 78).c_str());
-    png_text_[pos].text = strdup(comment.text.c_str());
-    png_text_[pos].text_length = comment.text.size();
+    UNSAFE_TODO(png_text_[pos]).key = strdup(comment.key.substr(0, 78).c_str());
+    UNSAFE_TODO(png_text_[pos]).text = strdup(comment.text.c_str());
+    UNSAFE_TODO(png_text_[pos]).text_length = comment.text.size();
 #ifdef PNG_iTXt_SUPPORTED
-    png_text_[pos].itxt_length = 0;
-    png_text_[pos].lang = 0;
-    png_text_[pos].lang_key = 0;
+    UNSAFE_TODO(png_text_[pos]).itxt_length = 0;
+    UNSAFE_TODO(png_text_[pos]).lang = 0;
+    UNSAFE_TODO(png_text_[pos]).lang_key = 0;
 #endif
   }
 
diff --git a/unsafe_buffers_paths.txt b/unsafe_buffers_paths.txt
index 4ffa5cc..ffd68fe 100644
--- a/unsafe_buffers_paths.txt
+++ b/unsafe_buffers_paths.txt
@@ -13,7 +13,6 @@
 -skia/
 -testing/gmock/
 -testing/gtest/
--testing/image_diff/
 -third_party/
 -tools/
 -v8/