Put uint8_t vectors into the Data partition in fpdfapi/

Change-Id: I7766980506d67c51794d919756e790f02d2adc76
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/68350
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index fd4a2ad..1039270 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -236,7 +236,7 @@
 
   RetainPtr<CPDF_ColorSpace> m_pAlterCS;
   RetainPtr<CPDF_IccProfile> m_pProfile;
-  mutable std::vector<uint8_t> m_pCache;
+  mutable std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_pCache;
   std::vector<float> m_pRanges;
 };
 
@@ -1023,8 +1023,10 @@
   }
 
   if (m_pCache.empty()) {
-    m_pCache = pdfium::Vector2D<uint8_t>(nMaxColors, 3);
-    auto temp_src = pdfium::Vector2D<uint8_t>(nMaxColors, nComponents);
+    m_pCache =
+        pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(nMaxColors, 3);
+    auto temp_src = pdfium::Vector2D<uint8_t, FxAllocAllocator<uint8_t>>(
+        nMaxColors, nComponents);
     size_t src_index = 0;
     for (int i = 0; i < nMaxColors; i++) {
       uint32_t color = i;
diff --git a/core/fpdfapi/page/cpdf_dib.h b/core/fpdfapi/page/cpdf_dib.h
index 91a8305..f2f92c9 100644
--- a/core/fpdfapi/page/cpdf_dib.h
+++ b/core/fpdfapi/page/cpdf_dib.h
@@ -83,7 +83,7 @@
 
     int width;
     int height;
-    std::vector<uint8_t> data;
+    std::vector<uint8_t, FxAllocAllocator<uint8_t>> data;
   };
 
   LoadState StartLoadMask();
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index 3861e45..1ed8f7e 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -131,7 +131,7 @@
     return;
 
   uint32_t dwEstimateSize = std::min(size, 8192U);
-  std::vector<uint8_t> data(dwEstimateSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> data(dwEstimateSize);
   if (!pFile->ReadBlockAtOffset(data.data(), 0, dwEstimateSize))
     return;
 
@@ -153,7 +153,7 @@
   if (!size)
     return;
 
-  std::vector<uint8_t> data(size);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> data(size);
   if (!pFile->ReadBlockAtOffset(data.data(), 0, size))
     return;
 
diff --git a/core/fpdfapi/page/cpdf_transferfunc.cpp b/core/fpdfapi/page/cpdf_transferfunc.cpp
index 9e3092b..ead57c7 100644
--- a/core/fpdfapi/page/cpdf_transferfunc.cpp
+++ b/core/fpdfapi/page/cpdf_transferfunc.cpp
@@ -12,11 +12,12 @@
 #include "core/fpdfapi/parser/cpdf_document.h"
 #include "core/fxge/dib/cfx_dibbase.h"
 
-CPDF_TransferFunc::CPDF_TransferFunc(CPDF_Document* pDoc,
-                                     bool bIdentify,
-                                     std::vector<uint8_t> samples_r,
-                                     std::vector<uint8_t> samples_g,
-                                     std::vector<uint8_t> samples_b)
+CPDF_TransferFunc::CPDF_TransferFunc(
+    CPDF_Document* pDoc,
+    bool bIdentify,
+    std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_r,
+    std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_g,
+    std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_b)
     : m_pPDFDoc(pDoc),
       m_bIdentity(bIdentify),
       m_SamplesR(std::move(samples_r)),
diff --git a/core/fpdfapi/page/cpdf_transferfunc.h b/core/fpdfapi/page/cpdf_transferfunc.h
index b2d997e..1bc159d 100644
--- a/core/fpdfapi/page/cpdf_transferfunc.h
+++ b/core/fpdfapi/page/cpdf_transferfunc.h
@@ -9,6 +9,7 @@
 
 #include <vector>
 
+#include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/observed_ptr.h"
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/unowned_ptr.h"
@@ -40,16 +41,16 @@
  private:
   CPDF_TransferFunc(CPDF_Document* pDoc,
                     bool bIdentify,
-                    std::vector<uint8_t> samples_r,
-                    std::vector<uint8_t> samples_g,
-                    std::vector<uint8_t> samples_b);
+                    std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_r,
+                    std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_g,
+                    std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_b);
   ~CPDF_TransferFunc() override;
 
   UnownedPtr<CPDF_Document> const m_pPDFDoc;
   const bool m_bIdentity;
-  const std::vector<uint8_t> m_SamplesR;
-  const std::vector<uint8_t> m_SamplesG;
-  const std::vector<uint8_t> m_SamplesB;
+  const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesR;
+  const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesG;
+  const std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_SamplesB;
 };
 
 #endif  // CORE_FPDFAPI_PAGE_CPDF_TRANSFERFUNC_H_
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.cpp b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
index f985616..7eb42e0 100644
--- a/core/fpdfapi/page/cpdf_transferfuncdib.cpp
+++ b/core/fpdfapi/page/cpdf_transferfuncdib.cpp
@@ -46,7 +46,7 @@
 
 void CPDF_TransferFuncDIB::TranslateScanline(
     const uint8_t* src_buf,
-    std::vector<uint8_t>* dest_buf) const {
+    std::vector<uint8_t, FxAllocAllocator<uint8_t>>* dest_buf) const {
   bool bSkip = false;
   switch (m_pSrc->GetFormat()) {
     case FXDIB_1bppRgb: {
diff --git a/core/fpdfapi/page/cpdf_transferfuncdib.h b/core/fpdfapi/page/cpdf_transferfuncdib.h
index c30718a..a0fec72 100644
--- a/core/fpdfapi/page/cpdf_transferfuncdib.h
+++ b/core/fpdfapi/page/cpdf_transferfuncdib.h
@@ -20,8 +20,9 @@
   template <typename T, typename... Args>
   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
 
-  void TranslateScanline(const uint8_t* src_buf,
-                         std::vector<uint8_t>* dest_buf) const;
+  void TranslateScanline(
+      const uint8_t* src_buf,
+      std::vector<uint8_t, FxAllocAllocator<uint8_t>>* dest_buf) const;
   void TranslateDownSamples(uint8_t* dest_buf,
                             const uint8_t* src_buf,
                             int pixels,
@@ -45,7 +46,7 @@
   FXDIB_Format GetDestFormat() const;
 
   RetainPtr<CFX_DIBBase> const m_pSrc;
-  mutable std::vector<uint8_t> m_Scanline;
+  mutable std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_Scanline;
   RetainPtr<CPDF_TransferFunc> const m_pTransferFunc;
   const pdfium::span<const uint8_t> m_RampR;
   const pdfium::span<const uint8_t> m_RampG;
diff --git a/core/fpdfapi/parser/cpdf_encryptor.cpp b/core/fpdfapi/parser/cpdf_encryptor.cpp
index 706d668..d7932f1 100644
--- a/core/fpdfapi/parser/cpdf_encryptor.cpp
+++ b/core/fpdfapi/parser/cpdf_encryptor.cpp
@@ -13,12 +13,12 @@
   ASSERT(m_pHandler);
 }
 
-std::vector<uint8_t> CPDF_Encryptor::Encrypt(
+std::vector<uint8_t, FxAllocAllocator<uint8_t>> CPDF_Encryptor::Encrypt(
     pdfium::span<const uint8_t> src_data) const {
   if (src_data.empty())
-    return std::vector<uint8_t>();
+    return std::vector<uint8_t, FxAllocAllocator<uint8_t>>();
 
-  std::vector<uint8_t> result;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> result;
   uint32_t buf_size = m_pHandler->EncryptGetSize(src_data);
   result.resize(buf_size);
   m_pHandler->EncryptContent(m_ObjNum, 0, src_data, result.data(),
diff --git a/core/fpdfapi/parser/cpdf_encryptor.h b/core/fpdfapi/parser/cpdf_encryptor.h
index cea737a..d23af8a 100644
--- a/core/fpdfapi/parser/cpdf_encryptor.h
+++ b/core/fpdfapi/parser/cpdf_encryptor.h
@@ -11,6 +11,7 @@
 
 #include <vector>
 
+#include "core/fxcrt/fx_memory_wrappers.h"
 #include "core/fxcrt/unowned_ptr.h"
 #include "third_party/base/span.h"
 
@@ -21,7 +22,8 @@
   CPDF_Encryptor(CPDF_CryptoHandler* pHandler, int objnum);
   ~CPDF_Encryptor();
 
-  std::vector<uint8_t> Encrypt(pdfium::span<const uint8_t> src_data) const;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> Encrypt(
+      pdfium::span<const uint8_t> src_data) const;
 
  private:
   UnownedPtr<CPDF_CryptoHandler> const m_pHandler;
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 08fdfeb..ab261d9 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -805,7 +805,7 @@
 }
 
 TEST(PDFStreamTest, SetData) {
-  std::vector<uint8_t> data(100);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> data(100);
   auto stream = pdfium::MakeRetain<CPDF_Stream>();
   stream->InitStream(data, pdfium::MakeRetain<CPDF_Dictionary>());
   EXPECT_EQ(static_cast<int>(data.size()),
@@ -816,7 +816,7 @@
   stream->GetDict()->SetNewFor<CPDF_String>(pdfium::stream::kDecodeParms,
                                             L"SomeParams");
 
-  std::vector<uint8_t> new_data(data.size() * 2);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> new_data(data.size() * 2);
   stream->SetData(new_data);
 
   // The "Length" field should be updated for new data size.
@@ -831,7 +831,7 @@
 }
 
 TEST(PDFStreamTest, SetDataAndRemoveFilter) {
-  std::vector<uint8_t> data(100);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> data(100);
   auto stream = pdfium::MakeRetain<CPDF_Stream>();
   stream->InitStream(data, pdfium::MakeRetain<CPDF_Dictionary>());
   EXPECT_EQ(static_cast<int>(data.size()),
@@ -842,7 +842,7 @@
   stream->GetDict()->SetNewFor<CPDF_String>(pdfium::stream::kDecodeParms,
                                             L"SomeParams");
 
-  std::vector<uint8_t> new_data(data.size() * 2);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> new_data(data.size() * 2);
   stream->SetDataAndRemoveFilter(new_data);
   // The "Length" field should be updated for new data size.
   EXPECT_EQ(static_cast<int>(new_data.size()),
diff --git a/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp b/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp
index 38b4bf9..d3d019c 100644
--- a/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_read_validator_unittest.cpp
@@ -65,12 +65,12 @@
 }  // namespace
 
 TEST(CPDF_ReadValidatorTest, UnavailableData) {
-  std::vector<uint8_t> test_data(kTestDataSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> test_data(kTestDataSize);
   auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
   MockFileAvail file_avail;
   auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
 
-  std::vector<uint8_t> read_buffer(100);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> read_buffer(100);
   EXPECT_FALSE(validator->ReadBlockAtOffset(read_buffer.data(), 5000,
                                             read_buffer.size()));
 
@@ -88,7 +88,7 @@
 }
 
 TEST(CPDF_ReadValidatorTest, UnavailableDataWithHints) {
-  std::vector<uint8_t> test_data(kTestDataSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> test_data(kTestDataSize);
   auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
   MockFileAvail file_avail;
   auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
@@ -96,7 +96,7 @@
   MockDownloadHints hints;
   validator->SetDownloadHints(&hints);
 
-  std::vector<uint8_t> read_buffer(100);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> read_buffer(100);
 
   EXPECT_FALSE(validator->ReadBlockAtOffset(read_buffer.data(), 5000,
                                             read_buffer.size()));
@@ -135,7 +135,7 @@
   auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, nullptr);
 
   static const uint32_t kBufferSize = 3 * 1000;
-  std::vector<uint8_t> buffer(kBufferSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> buffer(kBufferSize);
 
   EXPECT_FALSE(validator->ReadBlockAtOffset(buffer.data(), 5000, 100));
   EXPECT_TRUE(validator->read_error());
@@ -143,12 +143,12 @@
 }
 
 TEST(CPDF_ReadValidatorTest, IntOverflow) {
-  std::vector<uint8_t> test_data(kTestDataSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> test_data(kTestDataSize);
   auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
   MockFileAvail file_avail;
   auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
 
-  std::vector<uint8_t> read_buffer(100);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> read_buffer(100);
 
   // If we have int overflow, this is equal reading after file end. This is not
   // read_error, and in this case we have not unavailable data. It is just error
@@ -161,7 +161,7 @@
 }
 
 TEST(CPDF_ReadValidatorTest, Session) {
-  std::vector<uint8_t> test_data(kTestDataSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> test_data(kTestDataSize);
 
   auto file = pdfium::MakeRetain<InvalidSeekableReadStream>(kTestDataSize);
   MockFileAvail file_avail;
@@ -199,7 +199,7 @@
 }
 
 TEST(CPDF_ReadValidatorTest, SessionReset) {
-  std::vector<uint8_t> test_data(kTestDataSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> test_data(kTestDataSize);
 
   auto file = pdfium::MakeRetain<InvalidSeekableReadStream>(kTestDataSize);
   MockFileAvail file_avail;
@@ -241,7 +241,7 @@
 }
 
 TEST(CPDF_ReadValidatorTest, CheckDataRangeAndRequestIfUnavailable) {
-  std::vector<uint8_t> test_data(kTestDataSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> test_data(kTestDataSize);
   auto file = pdfium::MakeRetain<CFX_ReadOnlyMemoryStream>(test_data);
   MockFileAvail file_avail;
   auto validator = pdfium::MakeRetain<CPDF_ReadValidator>(file, &file_avail);
@@ -266,7 +266,7 @@
   EXPECT_FALSE(validator->read_error());
   EXPECT_FALSE(validator->has_unavailable_data());
 
-  std::vector<uint8_t> read_buffer(100);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> read_buffer(100);
   EXPECT_TRUE(validator->ReadBlockAtOffset(read_buffer.data(), 5000,
                                            read_buffer.size()));
   // No new request on already available data.
diff --git a/core/fpdfapi/parser/cpdf_security_handler.cpp b/core/fpdfapi/parser/cpdf_security_handler.cpp
index 126fc6b..477717f 100644
--- a/core/fpdfapi/parser/cpdf_security_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_security_handler.cpp
@@ -118,13 +118,13 @@
   uint8_t digest[32];
   CRYPT_SHA256Finish(&sha, digest);
 
-  std::vector<uint8_t> buf;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> buf;
   uint8_t* input = digest;
   uint8_t* key = input;
   uint8_t* iv = input + 16;
   uint8_t* E = nullptr;
   int iBufLen = 0;
-  std::vector<uint8_t> interDigest;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> interDigest;
   int i = 0;
   int iBlockSize = 32;
   CRYPT_aes_context aes = {};
@@ -136,7 +136,7 @@
     iBufLen = iRoundSize * 64;
     buf.resize(iBufLen);
     E = buf.data();
-    std::vector<uint8_t> content;
+    std::vector<uint8_t, FxAllocAllocator<uint8_t>> content;
     for (int j = 0; j < 64; ++j) {
       content.insert(std::end(content), password.raw_str(),
                      password.raw_str() + password.GetLength());
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp
index 8237338..3c452d7 100644
--- a/core/fpdfapi/parser/cpdf_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -183,7 +183,7 @@
   const bool is_metadata = IsMetaDataStreamDictionary(GetDict());
   CPDF_FlateEncoder encoder(this, !is_metadata);
 
-  std::vector<uint8_t> encrypted_data;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> encrypted_data;
   pdfium::span<const uint8_t> data = encoder.GetSpan();
 
   if (encryptor && !is_metadata) {
diff --git a/core/fpdfapi/parser/cpdf_string.cpp b/core/fpdfapi/parser/cpdf_string.cpp
index 7058169..192948d9 100644
--- a/core/fpdfapi/parser/cpdf_string.cpp
+++ b/core/fpdfapi/parser/cpdf_string.cpp
@@ -69,7 +69,7 @@
 
 bool CPDF_String::WriteTo(IFX_ArchiveStream* archive,
                           const CPDF_Encryptor* encryptor) const {
-  std::vector<uint8_t> encrypted_data;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> encrypted_data;
   pdfium::span<const uint8_t> data = m_String.raw_span();
   if (encryptor) {
     encrypted_data = encryptor->Encrypt(data);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.h b/core/fpdfapi/parser/cpdf_syntax_parser.h
index d36aedf..d0b8a31 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.h
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.h
@@ -109,7 +109,7 @@
   const FX_FILESIZE m_FileLen;
   FX_FILESIZE m_Pos = 0;
   WeakPtr<ByteStringPool> m_pPool;
-  std::vector<uint8_t> m_pFileBuf;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_pFileBuf;
   FX_FILESIZE m_BufOffset = 0;
   uint32_t m_WordSize = 0;
   uint8_t m_WordBuffer[257];
diff --git a/core/fpdfapi/render/cpdf_docrenderdata.cpp b/core/fpdfapi/render/cpdf_docrenderdata.cpp
index ba702b7e..69af157 100644
--- a/core/fpdfapi/render/cpdf_docrenderdata.cpp
+++ b/core/fpdfapi/render/cpdf_docrenderdata.cpp
@@ -84,9 +84,12 @@
   memset(output, 0, sizeof(output));
 
   bool bIdentity = true;
-  std::vector<uint8_t> samples_r(CPDF_TransferFunc::kChannelSampleSize);
-  std::vector<uint8_t> samples_g(CPDF_TransferFunc::kChannelSampleSize);
-  std::vector<uint8_t> samples_b(CPDF_TransferFunc::kChannelSampleSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_r(
+      CPDF_TransferFunc::kChannelSampleSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_g(
+      CPDF_TransferFunc::kChannelSampleSize);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> samples_b(
+      CPDF_TransferFunc::kChannelSampleSize);
   std::array<pdfium::span<uint8_t>, 3> samples = {samples_r, samples_g,
                                                   samples_b};
   for (size_t v = 0; v < CPDF_TransferFunc::kChannelSampleSize; ++v) {
diff --git a/core/fpdfapi/render/cpdf_renderstatus.cpp b/core/fpdfapi/render/cpdf_renderstatus.cpp
index 79d31b9..17af93b 100644
--- a/core/fpdfapi/render/cpdf_renderstatus.cpp
+++ b/core/fpdfapi/render/cpdf_renderstatus.cpp
@@ -1645,7 +1645,7 @@
   int dest_pitch = pMask->GetPitch();
   uint8_t* src_buf = bitmap->GetBuffer();
   int src_pitch = bitmap->GetPitch();
-  std::vector<uint8_t> transfers(256);
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> transfers(256);
   if (pFunc) {
     std::vector<float> results(pFunc->CountOutputs());
     for (size_t i = 0; i < transfers.size(); ++i) {