Use spans for arguments in IccModule::Translate()

Avoid passing arrays as raw pointers.

-- Allocate doubles off of the numeric partition.

Change-Id: I2b76abb849b6629c2aeaa3d223117700cb196d54
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/84632
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 331b5cb..53ab29c 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -986,8 +986,8 @@
   }
   if (m_pProfile->transform()) {
     float rgb[3];
-    IccModule::Translate(m_pProfile->transform(), CountComponents(),
-                         pBuf.data(), rgb);
+    IccModule::Translate(m_pProfile->transform(), pBuf.first(CountComponents()),
+                         rgb);
     *R = rgb[0];
     *G = rgb[1];
     *B = rgb[2];
diff --git a/core/fxcodec/icc/iccmodule.cpp b/core/fxcodec/icc/iccmodule.cpp
index 4d7437f..9cf0c4f 100644
--- a/core/fxcodec/icc/iccmodule.cpp
+++ b/core/fxcodec/icc/iccmodule.cpp
@@ -110,25 +110,26 @@
 
 // static
 void IccModule::Translate(CLcmsCmm* pTransform,
-                          uint32_t nSrcComponents,
-                          const float* pSrcValues,
-                          float* pDestValues) {
+                          pdfium::span<const float> pSrcValues,
+                          pdfium::span<float> pDestValues) {
   if (!pTransform)
     return;
 
   uint8_t output[4];
   // TODO(npm): Currently the CmsDoTransform method is part of LCMS and it will
   // apply some member of m_hTransform to the input. We need to go over all the
-  // places which set transform to verify that only |nSrcComponents| are used.
+  // places which set transform to verify that only `pSrcValues.size()`
+  // components are used.
   if (pTransform->IsLab()) {
-    std::vector<double> inputs(std::max(nSrcComponents, 16u));
-    for (uint32_t i = 0; i < nSrcComponents; ++i)
+    std::vector<double, FxAllocAllocator<double>> inputs(
+        std::max<size_t>(pSrcValues.size(), 16));
+    for (uint32_t i = 0; i < pSrcValues.size(); ++i)
       inputs[i] = pSrcValues[i];
     cmsDoTransform(pTransform->transform(), inputs.data(), output, 1);
   } else {
     std::vector<uint8_t, FxAllocAllocator<uint8_t>> inputs(
-        std::max(nSrcComponents, 16u));
-    for (uint32_t i = 0; i < nSrcComponents; ++i) {
+        std::max<size_t>(pSrcValues.size(), 16));
+    for (size_t i = 0; i < pSrcValues.size(); ++i) {
       inputs[i] =
           pdfium::clamp(static_cast<int>(pSrcValues[i] * 255.0f), 0, 255);
     }
diff --git a/core/fxcodec/icc/iccmodule.h b/core/fxcodec/icc/iccmodule.h
index 6a7f872..0f2fa7f 100644
--- a/core/fxcodec/icc/iccmodule.h
+++ b/core/fxcodec/icc/iccmodule.h
@@ -47,9 +47,8 @@
   static std::unique_ptr<CLcmsCmm> CreateTransformSRGB(
       pdfium::span<const uint8_t> span);
   static void Translate(CLcmsCmm* pTransform,
-                        uint32_t nSrcComponents,
-                        const float* pSrcValues,
-                        float* pDestValues);
+                        pdfium::span<const float> pSrcValues,
+                        pdfium::span<float> pDestValues);
   static void TranslateScanline(CLcmsCmm* pTransform,
                                 uint8_t* pDest,
                                 const uint8_t* pSrc,
diff --git a/testing/fuzzers/pdf_codec_icc_fuzzer.cc b/testing/fuzzers/pdf_codec_icc_fuzzer.cc
index ca027331..298adbb 100644
--- a/testing/fuzzers/pdf_codec_icc_fuzzer.cc
+++ b/testing/fuzzers/pdf_codec_icc_fuzzer.cc
@@ -11,13 +11,14 @@
   std::unique_ptr<CLcmsCmm> transform =
       IccModule::CreateTransformSRGB(pdfium::make_span(data, size));
 
-  if (transform) {
-    float src[4];
-    float dst[4];
-    for (int i = 0; i < 4; i++)
-      src[i] = 0.5f;
-    IccModule::Translate(transform.get(), transform->components(), src, dst);
-  }
+  if (!transform)
+    return 0;
+
+  const float src[4] = {0.5f, 0.5f, 0.5f, 0.5f};
+  float dst[4];
+  IccModule::Translate(transform.get(),
+                       pdfium::make_span(src).first(transform->components()),
+                       pdfium::make_span(dst));
 
   return 0;
 }