Use pdfium::span with CPDF_IccProfile and friends.

Change-Id: I88d3e86a1dad75ef9c6bfb3401af6606479031a7
Reviewed-on: https://pdfium-review.googlesource.com/36634
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Henrique Nakashima <hnakashima@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_docpagedata.cpp b/core/fpdfapi/page/cpdf_docpagedata.cpp
index 49d44b3..6744e0f 100644
--- a/core/fpdfapi/page/cpdf_docpagedata.cpp
+++ b/core/fpdfapi/page/cpdf_docpagedata.cpp
@@ -442,8 +442,8 @@
     if (it_copied_stream != m_IccProfileMap.end())
       return it_copied_stream->second;
   }
-  auto pProfile = pdfium::MakeRetain<CPDF_IccProfile>(
-      pProfileStream, pAccessor->GetData(), pAccessor->GetSize());
+  auto pProfile =
+      pdfium::MakeRetain<CPDF_IccProfile>(pProfileStream, pAccessor->GetSpan());
   m_IccProfileMap[pProfileStream] = pProfile;
   m_HashProfileMap[bsDigest] = pProfileStream;
   return pProfile;
diff --git a/core/fpdfapi/page/cpdf_iccprofile.cpp b/core/fpdfapi/page/cpdf_iccprofile.cpp
index ef1b9ef..94270b1 100644
--- a/core/fpdfapi/page/cpdf_iccprofile.cpp
+++ b/core/fpdfapi/page/cpdf_iccprofile.cpp
@@ -12,23 +12,23 @@
 
 namespace {
 
-bool DetectSRGB(const uint8_t* pData, uint32_t dwSize) {
-  return dwSize == 3144 && memcmp(pData + 0x190, "sRGB IEC61966-2.1", 17) == 0;
+bool DetectSRGB(pdfium::span<const uint8_t> span) {
+  return span.size() == 3144 &&
+         memcmp(span.data() + 0x190, "sRGB IEC61966-2.1", 17) == 0;
 }
 
 }  // namespace
 
 CPDF_IccProfile::CPDF_IccProfile(const CPDF_Stream* pStream,
-                                 const uint8_t* pData,
-                                 uint32_t dwSize)
-    : m_bsRGB(DetectSRGB(pData, dwSize)), m_pStream(pStream) {
+                                 pdfium::span<const uint8_t> span)
+    : m_bsRGB(DetectSRGB(span)), m_pStream(pStream) {
   if (m_bsRGB) {
     m_nSrcComponents = 3;
     return;
   }
 
   auto* pIccModule = CPDF_ModuleMgr::Get()->GetIccModule();
-  m_Transform = pIccModule->CreateTransform_sRGB(pData, dwSize);
+  m_Transform = pIccModule->CreateTransform_sRGB(span);
   if (m_Transform)
     m_nSrcComponents = m_Transform->components();
 }
diff --git a/core/fpdfapi/page/cpdf_iccprofile.h b/core/fpdfapi/page/cpdf_iccprofile.h
index a5c9f6d..a9e1170 100644
--- a/core/fpdfapi/page/cpdf_iccprofile.h
+++ b/core/fpdfapi/page/cpdf_iccprofile.h
@@ -11,6 +11,7 @@
 
 #include "core/fxcrt/retain_ptr.h"
 #include "core/fxcrt/unowned_ptr.h"
+#include "third_party/base/span.h"
 
 class CLcmsCmm;
 class CPDF_Stream;
@@ -28,9 +29,7 @@
   uint32_t GetComponents() const { return m_nSrcComponents; }
 
  private:
-  CPDF_IccProfile(const CPDF_Stream* pStream,
-                  const uint8_t* pData,
-                  uint32_t dwSize);
+  CPDF_IccProfile(const CPDF_Stream* pStream, pdfium::span<const uint8_t> span);
   ~CPDF_IccProfile() override;
 
   const bool m_bsRGB;
diff --git a/core/fxcodec/codec/ccodec_iccmodule.h b/core/fxcodec/codec/ccodec_iccmodule.h
index 419bf17..64cfb26 100644
--- a/core/fxcodec/codec/ccodec_iccmodule.h
+++ b/core/fxcodec/codec/ccodec_iccmodule.h
@@ -13,6 +13,7 @@
 #include "core/fxcrt/fx_string.h"
 #include "core/fxcrt/fx_system.h"
 #include "third_party/base/ptr_util.h"
+#include "third_party/base/span.h"
 
 #if defined(USE_SYSTEM_LCMS2)
 #include <lcms2.h>
@@ -45,8 +46,8 @@
   CCodec_IccModule();
   ~CCodec_IccModule();
 
-  std::unique_ptr<CLcmsCmm> CreateTransform_sRGB(const uint8_t* pProfileData,
-                                                 uint32_t dwProfileSize);
+  std::unique_ptr<CLcmsCmm> CreateTransform_sRGB(
+      pdfium::span<const uint8_t> span);
   void Translate(CLcmsCmm* pTransform,
                  const float* pSrcValues,
                  float* pDestValues);
diff --git a/core/fxcodec/codec/fx_codec_icc.cpp b/core/fxcodec/codec/fx_codec_icc.cpp
index fc82e04..7ae93e5 100644
--- a/core/fxcodec/codec/fx_codec_icc.cpp
+++ b/core/fxcodec/codec/fx_codec_icc.cpp
@@ -50,10 +50,8 @@
 CCodec_IccModule::~CCodec_IccModule() {}
 
 std::unique_ptr<CLcmsCmm> CCodec_IccModule::CreateTransform_sRGB(
-    const unsigned char* pSrcProfileData,
-    uint32_t dwSrcProfileSize) {
-  ScopedCmsProfile srcProfile(
-      cmsOpenProfileFromMem(pSrcProfileData, dwSrcProfileSize));
+    pdfium::span<const uint8_t> span) {
+  ScopedCmsProfile srcProfile(cmsOpenProfileFromMem(span.data(), span.size()));
   if (!srcProfile)
     return nullptr;
 
diff --git a/testing/fuzzers/pdf_codec_icc_fuzzer.cc b/testing/fuzzers/pdf_codec_icc_fuzzer.cc
index 2f4fa44..faafc36 100644
--- a/testing/fuzzers/pdf_codec_icc_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_icc_fuzzer.cc
@@ -5,11 +5,12 @@
 #include <cstdint>
 
 #include "core/fxcodec/codec/ccodec_iccmodule.h"
+#include "third_party/base/span.h"
 
 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
   CCodec_IccModule icc_module;
   std::unique_ptr<CLcmsCmm> transform =
-      icc_module.CreateTransform_sRGB(data, size);
+      icc_module.CreateTransform_sRGB(pdfium::make_span(data, size));
 
   if (transform) {
     float src[4];