Use fxge::CalculatePitch8() in CFX_DIBBase Use CalculatePitch8() instead of manually doing the same calculation in CFX_DIBBase. Change-Id: Idaa2c40ef3b474073ec48c529f56ae2d73f44183 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/111450 Commit-Queue: Lei Zhang <thestig@chromium.org> Reviewed-by: Nigi <nigi@chromium.org>
diff --git a/core/fxge/dib/cfx_dibbase.cpp b/core/fxge/dib/cfx_dibbase.cpp index 97f8440..b64bc28 100644 --- a/core/fxge/dib/cfx_dibbase.cpp +++ b/core/fxge/dib/cfx_dibbase.cpp
@@ -19,6 +19,7 @@ #include "core/fxcrt/fx_memory.h" #include "core/fxcrt/fx_safe_types.h" #include "core/fxcrt/span_util.h" +#include "core/fxge/calculate_pitch.h" #include "core/fxge/cfx_cliprgn.h" #include "core/fxge/dib/cfx_bitmapstorer.h" #include "core/fxge/dib/cfx_dibitmap.h" @@ -669,14 +670,13 @@ } } } else { - FX_SAFE_UINT32 copy_len = pNewBitmap->GetWidth(); - copy_len *= pNewBitmap->GetBPP(); - copy_len += 7; - copy_len /= 8; - if (!copy_len.IsValid()) + absl::optional<uint32_t> copy_len = fxge::CalculatePitch8( + pNewBitmap->GetBPP(), /*components=*/1, pNewBitmap->GetWidth()); + if (!copy_len.has_value()) { return nullptr; + } - copy_len = std::min<uint32_t>(m_Pitch, copy_len.ValueOrDie()); + copy_len = std::min<uint32_t>(m_Pitch, copy_len.value()); FX_SAFE_UINT32 offset = rect.left; offset *= GetBppFromFormat(m_Format); @@ -689,7 +689,7 @@ GetScanline(row).subspan(offset.ValueOrDie()).data(); uint8_t* dest_scan = pNewBitmap->GetWritableScanline(row - rect.top).data(); - memcpy(dest_scan, src_scan, copy_len.ValueOrDie()); + memcpy(dest_scan, src_scan, copy_len.value()); } } return pNewBitmap;