Convert ProgressiveDecoder::m_pDecodeBuf to std::vector<>

-- Call spancpy() in one place that was asking for it.

Change-Id: Ifc298de470f0a4509b49e4440133801fa799f7b0
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/82733
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/progressive_decoder.cpp b/core/fxcodec/progressive_decoder.cpp
index b3f6883..b7928f6 100644
--- a/core/fxcodec/progressive_decoder.cpp
+++ b/core/fxcodec/progressive_decoder.cpp
@@ -16,6 +16,7 @@
 #include "core/fxcodec/jpeg/jpeg_progressive_decoder.h"
 #include "core/fxcrt/fx_safe_types.h"
 #include "core/fxcrt/fx_stream.h"
+#include "core/fxcrt/span_util.h"
 #include "core/fxge/dib/cfx_cmyk_to_srgb.h"
 #include "core/fxge/dib/cfx_dibitmap.h"
 #include "core/fxge/dib/fx_dib.h"
@@ -254,13 +255,13 @@
   double scale_y = static_cast<double>(m_sizeY) / m_clipBox.Height();
   int32_t row =
       static_cast<int32_t>((line - m_clipBox.top) * scale_y) + m_startY;
-  *pSrcBuf = m_pDecodeBuf.get();
+  *pSrcBuf = m_DecodeBuf.data();
   int32_t src_Bpp = pDIBitmap->GetBPP() >> 3;
   int32_t dest_Bpp = (m_SrcFormat & 0xff) >> 3;
   int32_t src_left = m_startX;
   int32_t dest_left = m_clipBox.left;
   const uint8_t* src_scan = pDIBitmap->GetScanline(row) + src_left * src_Bpp;
-  uint8_t* dest_scan = m_pDecodeBuf.get() + dest_left * dest_Bpp;
+  uint8_t* dest_scan = m_DecodeBuf.data() + dest_left * dest_Bpp;
   switch (pDIBitmap->GetFormat()) {
     case FXDIB_Format::k1bppMask:
     case FXDIB_Format::k1bppRgb:
@@ -338,7 +339,7 @@
     if (dest_row >= dest_top + dest_height) {
       return;
     }
-    PngOneOneMapResampleHorz(pDIBitmap, dest_row, m_pDecodeBuf.get(),
+    PngOneOneMapResampleHorz(pDIBitmap, dest_row, m_DecodeBuf.data(),
                              m_SrcFormat);
     if (m_SrcPassNumber == 1 && scale_y > 1.0) {
       ResampleVert(pDIBitmap, scale_y, dest_row);
@@ -454,11 +455,11 @@
   if (m_GifTransIndex != -1 && m_pDeviceBitmap->IsAlphaFormat()) {
     pal_index = m_GifTransIndex;
   }
-  memset(m_pDecodeBuf.get(), pal_index, m_SrcWidth);
+  memset(m_DecodeBuf.data(), pal_index, m_SrcWidth);
   bool bLastPass = (row_num % 2) == 1;
   int32_t line = row_num + m_GifFrameRect.top;
   int32_t left = m_GifFrameRect.left;
-  memcpy(m_pDecodeBuf.get() + left, row_buf, img_width);
+  memcpy(m_DecodeBuf.data() + left, row_buf, img_width);
   int src_top = m_clipBox.top;
   int src_bottom = m_clipBox.bottom;
   int dest_top = m_startY;
@@ -473,7 +474,7 @@
   if (dest_row >= dest_top + dest_height)
     return;
 
-  ReSampleScanline(pDIBitmap, dest_row, m_pDecodeBuf.get(), m_SrcFormat);
+  ReSampleScanline(pDIBitmap, dest_row, m_DecodeBuf.data(), m_SrcFormat);
   if (scale_y > 1.0 && m_SrcPassNumber == 1) {
     ResampleVert(pDIBitmap, scale_y, dest_row);
     return;
@@ -511,8 +512,7 @@
   RetainPtr<CFX_DIBitmap> pDIBitmap = m_pDeviceBitmap;
   DCHECK(pDIBitmap);
 
-  pdfium::span<const uint8_t> src_span = row_buf.first(m_ScanlineSize);
-  std::copy(std::begin(src_span), std::end(src_span), m_pDecodeBuf.get());
+  fxcrt::spancpy(pdfium::make_span(m_DecodeBuf), row_buf.first(m_ScanlineSize));
 
   int src_top = m_clipBox.top;
   int src_bottom = m_clipBox.bottom;
@@ -530,7 +530,7 @@
   if (dest_row >= dest_top + dest_height)
     return;
 
-  ReSampleScanline(pDIBitmap, dest_row, m_pDecodeBuf.get(), m_SrcFormat);
+  ReSampleScanline(pDIBitmap, dest_row, m_DecodeBuf.data(), m_SrcFormat);
   if (scale_y <= 1.0)
     return;
 
@@ -714,7 +714,7 @@
     const RetainPtr<CFX_DIBitmap>& pDIBitmap) {
   GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
   m_ScanlineSize = FxAlignToBoundary<4>(m_SrcWidth * m_SrcComponents);
-  m_pDecodeBuf.reset(FX_Alloc(uint8_t, m_ScanlineSize));
+  m_DecodeBuf.resize(m_ScanlineSize);
   FXDIB_ResampleOptions options;
   options.bInterpolateBilinear = true;
   m_WeightHorz.CalculateWeights(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
@@ -789,7 +789,7 @@
   m_SrcFormat = FXCodec_8bppRgb;
   GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
   int scanline_size = FxAlignToBoundary<4>(m_SrcWidth);
-  m_pDecodeBuf.reset(FX_Alloc(uint8_t, scanline_size));
+  m_DecodeBuf.resize(scanline_size);
   FXDIB_ResampleOptions options;
   options.bInterpolateBilinear = true;
   m_WeightHorz.CalculateWeights(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
@@ -984,7 +984,7 @@
   }
   int scanline_size = (m_SrcWidth + down_scale - 1) / down_scale;
   scanline_size = FxAlignToBoundary<4>(scanline_size * m_SrcComponents);
-  m_pDecodeBuf.reset(FX_Alloc(uint8_t, scanline_size));
+  m_DecodeBuf.resize(scanline_size);
   FXDIB_ResampleOptions options;
   options.bInterpolateBilinear = true;
   m_WeightHorz.CalculateWeights(m_sizeX, 0, m_sizeX, m_clipBox.Width(), 0,
@@ -1018,7 +1018,7 @@
 
   while (true) {
     bool readRes = JpegProgressiveDecoder::ReadScanline(m_pJpegContext.get(),
-                                                        m_pDecodeBuf.get());
+                                                        m_DecodeBuf.data());
     while (!readRes) {
       FXCODEC_STATUS error_status = FXCODEC_STATUS_DECODE_FINISH;
       if (!JpegReadMoreData(&error_status)) {
@@ -1028,11 +1028,11 @@
         return m_status;
       }
       readRes = JpegProgressiveDecoder::ReadScanline(m_pJpegContext.get(),
-                                                     m_pDecodeBuf.get());
+                                                     m_DecodeBuf.data());
     }
     if (m_SrcFormat == FXCodec_Rgb) {
       int src_Bpp = (m_SrcFormat & 0xff) >> 3;
-      RGB2BGR(m_pDecodeBuf.get() + m_clipBox.left * src_Bpp, m_clipBox.Width());
+      RGB2BGR(m_DecodeBuf.data() + m_clipBox.left * src_Bpp, m_clipBox.Width());
     }
     if (m_SrcRow >= m_clipBox.bottom) {
       m_pDeviceBitmap = nullptr;
@@ -1040,7 +1040,7 @@
       m_status = FXCODEC_STATUS_DECODE_FINISH;
       return m_status;
     }
-    Resample(m_pDeviceBitmap, m_SrcRow, m_pDecodeBuf.get(), m_SrcFormat);
+    Resample(m_pDeviceBitmap, m_SrcRow, m_DecodeBuf.data(), m_SrcFormat);
     m_SrcRow++;
   }
 }
@@ -1186,7 +1186,7 @@
   }
   GetTransMethod(m_pDeviceBitmap->GetFormat(), m_SrcFormat);
   int scanline_size = FxAlignToBoundary<4>(m_SrcWidth * m_SrcComponents);
-  m_pDecodeBuf.reset(FX_Alloc(uint8_t, scanline_size));
+  m_DecodeBuf.resize(scanline_size);
   m_WeightHorzOO.CalculateWeights(m_sizeX, m_clipBox.Width());
   m_WeightVert.CalculateWeights(m_sizeY, m_clipBox.Height());
   m_status = FXCODEC_STATUS_DECODE_TOBECONTINUE;
@@ -2018,7 +2018,7 @@
     if (dest_row >= dest_top + dest_height)
       return;
 
-    ReSampleScanline(pDeviceBitmap, dest_row, m_pDecodeBuf.get(), src_format);
+    ReSampleScanline(pDeviceBitmap, dest_row, m_DecodeBuf.data(), src_format);
     if (scale_y > 1.0)
       ResampleVert(pDeviceBitmap, scale_y, dest_row);
   }
diff --git a/core/fxcodec/progressive_decoder.h b/core/fxcodec/progressive_decoder.h
index 3014d8e..7d4e1ec 100644
--- a/core/fxcodec/progressive_decoder.h
+++ b/core/fxcodec/progressive_decoder.h
@@ -221,7 +221,7 @@
   RetainPtr<IFX_SeekableReadStream> m_pFile;
   RetainPtr<CFX_DIBitmap> m_pDeviceBitmap;
   RetainPtr<CFX_CodecMemory> m_pCodecMemory;
-  std::unique_ptr<uint8_t, FxFreeDeleter> m_pDecodeBuf;
+  std::vector<uint8_t, FxAllocAllocator<uint8_t>> m_DecodeBuf;
   std::vector<FX_ARGB, FxAllocAllocator<FX_ARGB>> m_SrcPalette;
   std::unique_ptr<ProgressiveDecoderIface::Context> m_pJpegContext;
 #ifdef PDF_ENABLE_XFA_BMP