Use CPDF_StreamAcc::GetSpan() in more places.

Instead of manually creating spans with GetData() and GetSize(). Also
separate GetSpan() into const/non-const versions.

Change-Id: I36ed10489b216d1d329d74b9964969dc02bda74f
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/63191
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_colorspace.cpp b/core/fpdfapi/page/cpdf_colorspace.cpp
index 8dba4c2..fcd84a6 100644
--- a/core/fpdfapi/page/cpdf_colorspace.cpp
+++ b/core/fpdfapi/page/cpdf_colorspace.cpp
@@ -1163,7 +1163,7 @@
   } else if (const CPDF_Stream* pStream = pTableObj->AsStream()) {
     auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
     pAcc->LoadAllDataFiltered();
-    m_Table = ByteStringView(pAcc->GetData(), pAcc->GetSize());
+    m_Table = ByteStringView(pAcc->GetSpan());
   }
   return 1;
 }
diff --git a/core/fpdfapi/page/cpdf_meshstream.cpp b/core/fpdfapi/page/cpdf_meshstream.cpp
index 2e80fb9..06b2329 100644
--- a/core/fpdfapi/page/cpdf_meshstream.cpp
+++ b/core/fpdfapi/page/cpdf_meshstream.cpp
@@ -122,8 +122,7 @@
 
 bool CPDF_MeshStream::Load() {
   m_pStream->LoadAllDataFiltered();
-  m_BitStream = pdfium::MakeUnique<CFX_BitStream>(
-      pdfium::make_span(m_pStream->GetData(), m_pStream->GetSize()));
+  m_BitStream = pdfium::MakeUnique<CFX_BitStream>(m_pStream->GetSpan());
   const CPDF_Dictionary* pDict = m_pShadingStream->GetDict();
   m_nCoordBits = pDict->GetIntegerFor("BitsPerCoordinate");
   m_nComponentBits = pDict->GetIntegerFor("BitsPerComponent");
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.cpp b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
index 6453ee6..60c8a65 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
@@ -331,10 +331,7 @@
 
         void* context = DecryptStart(obj_num, gen_num);
         bool decrypt_result =
-            DecryptStream(context,
-                          pdfium::make_span(stream_access->GetData(),
-                                            stream_access->GetSize()),
-                          decrypted_buf);
+            DecryptStream(context, stream_access->GetSpan(), decrypted_buf);
         decrypt_result &= DecryptFinish(context, decrypted_buf);
         if (decrypt_result) {
           const uint32_t decrypted_size = decrypted_buf.GetSize();
diff --git a/core/fpdfapi/parser/cpdf_hint_tables.cpp b/core/fpdfapi/parser/cpdf_hint_tables.cpp
index dbe7f3e..e051254 100644
--- a/core/fpdfapi/parser/cpdf_hint_tables.cpp
+++ b/core/fpdfapi/parser/cpdf_hint_tables.cpp
@@ -469,7 +469,7 @@
     return false;
   }
 
-  CFX_BitStream bs(pdfium::make_span(pAcc->GetData(), size));
+  CFX_BitStream bs(pAcc->GetSpan().subspan(0, size));
   return ReadPageHintTable(&bs) &&
          ReadSharedObjHintTable(&bs, shared_hint_table_offset);
 }
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.cpp b/core/fpdfapi/parser/cpdf_stream_acc.cpp
index 93a2d85..cd99751 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.cpp
+++ b/core/fpdfapi/parser/cpdf_stream_acc.cpp
@@ -71,6 +71,14 @@
                                                    : 0;
 }
 
+pdfium::span<uint8_t> CPDF_StreamAcc::GetSpan() {
+  return {GetData(), GetSize()};
+}
+
+pdfium::span<const uint8_t> CPDF_StreamAcc::GetSpan() const {
+  return {GetData(), GetSize()};
+}
+
 ByteString CPDF_StreamAcc::ComputeDigest() const {
   uint8_t digest[20];
   CRYPT_SHA1Generate(GetData(), GetSize(), digest);
diff --git a/core/fpdfapi/parser/cpdf_stream_acc.h b/core/fpdfapi/parser/cpdf_stream_acc.h
index 3cca8d0..046fe5d 100644
--- a/core/fpdfapi/parser/cpdf_stream_acc.h
+++ b/core/fpdfapi/parser/cpdf_stream_acc.h
@@ -37,9 +37,8 @@
 
   uint8_t* GetData() const;
   uint32_t GetSize() const;
-  pdfium::span<uint8_t> GetSpan() const {
-    return pdfium::make_span(GetData(), GetSize());
-  }
+  pdfium::span<uint8_t> GetSpan();
+  pdfium::span<const uint8_t> GetSpan() const;
   ByteString ComputeDigest() const;
   ByteString GetImageDecoder() const { return m_ImageDecoder; }
   const CPDF_Dictionary* GetImageParam() const { return m_pImageParam.Get(); }
diff --git a/fpdfsdk/fpdf_ppo.cpp b/fpdfsdk/fpdf_ppo.cpp
index 13ef81d..481b6b9 100644
--- a/fpdfsdk/fpdf_ppo.cpp
+++ b/fpdfsdk/fpdf_ppo.cpp
@@ -690,14 +690,14 @@
         const CPDF_Stream* pStream = pSrcContentArray->GetStreamAt(i);
         auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
         pAcc->LoadAllDataFiltered();
-        bsSrcContentStream += ByteString(pAcc->GetData(), pAcc->GetSize());
+        bsSrcContentStream += ByteString(pAcc->GetSpan());
         bsSrcContentStream += "\n";
       }
     } else {
       const CPDF_Stream* pStream = pSrcContentObj->AsStream();
       auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pStream);
       pAcc->LoadAllDataFiltered();
-      bsSrcContentStream = ByteString(pAcc->GetData(), pAcc->GetSize());
+      bsSrcContentStream = ByteString(pAcc->GetSpan());
     }
     pNewXObject->SetDataAndRemoveFilter(bsSrcContentStream.raw_span());
   }