Remove a check that is always true in CPDF_IndexedCS.
By the time CPDF_IndexedCS::GetRGB() gets called,
CPDF_IndexedCS::v_Load() would have already set `m_nBaseComponents` to a
non-zero value. So there is no need to check if `m_nBaseComponents` is
zero. Add DCHECKs to validate these assumptions instead.
Change-Id: I9893e1e653144180b24cbc31dc0ee90d4f9319f2
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/101251
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_indexedcs.cpp b/core/fpdfapi/page/cpdf_indexedcs.cpp
index 33a8a1b..32a36bd 100644
--- a/core/fpdfapi/page/cpdf_indexedcs.cpp
+++ b/core/fpdfapi/page/cpdf_indexedcs.cpp
@@ -53,6 +53,7 @@
return 0;
m_nBaseComponents = m_pBaseCS->CountComponents();
+ DCHECK(m_nBaseComponents);
m_pCompMinMax = DataVector<float>(Fx2DSizeOrDie(m_nBaseComponents, 2));
float defvalue;
for (uint32_t i = 0; i < m_nBaseComponents; i++) {
@@ -84,17 +85,19 @@
if (index < 0 || index > m_MaxIndex)
return false;
- if (m_nBaseComponents) {
- FX_SAFE_SIZE_T length = index;
- length += 1;
- length *= m_nBaseComponents;
- if (!length.IsValid() || length.ValueOrDie() > m_Table.GetLength()) {
- *R = 0;
- *G = 0;
- *B = 0;
- return false;
- }
+ DCHECK(m_nBaseComponents);
+ DCHECK_EQ(m_nBaseComponents, m_pBaseCS->CountComponents());
+
+ FX_SAFE_SIZE_T length = index;
+ length += 1;
+ length *= m_nBaseComponents;
+ if (!length.IsValid() || length.ValueOrDie() > m_Table.GetLength()) {
+ *R = 0;
+ *G = 0;
+ *B = 0;
+ return false;
}
+
std::vector<float> comps(m_nBaseComponents);
const uint8_t* pTable = m_Table.raw_str();
for (uint32_t i = 0; i < m_nBaseComponents; ++i) {
@@ -102,6 +105,5 @@
m_pCompMinMax[i * 2] +
m_pCompMinMax[i * 2 + 1] * pTable[index * m_nBaseComponents + i] / 255;
}
- DCHECK_EQ(m_nBaseComponents, m_pBaseCS->CountComponents());
return m_pBaseCS->GetRGB(comps, R, G, B);
}