Avoid UNSAFE_TODO() in AreColorIndicesOutOfBounds(). Iteration over zipped spans avoids the unsafe indexing. Change-Id: I1dc42dd0b53ba6c35bdcb8e0697b1c300e2376d9 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/127771 Reviewed-by: Lei Zhang <thestig@chromium.org> Reviewed-by: Thomas Sepez <tsepez@google.com> Commit-Queue: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_dib.cpp b/core/fpdfapi/page/cpdf_dib.cpp index 393f53b..4e2dc2c 100644 --- a/core/fpdfapi/page/cpdf_dib.cpp +++ b/core/fpdfapi/page/cpdf_dib.cpp
@@ -84,16 +84,13 @@ return index < comp_datum.m_ColorKeyMin || index > comp_datum.m_ColorKeyMax; } -bool AreColorIndicesOutOfBounds(const uint8_t* indices, - const DIB_COMP_DATA* comp_data, - size_t count) { - UNSAFE_TODO({ - for (size_t i = 0; i < count; ++i) { - if (IsColorIndexOutOfBounds(indices[i], comp_data[i])) { - return true; - } +bool AreColorIndicesOutOfBounds(pdfium::span<const uint8_t> indices, + pdfium::span<const DIB_COMP_DATA> comp_data) { + for (auto [idx, datum] : fxcrt::Zip(indices, comp_data)) { + if (IsColorIndexOutOfBounds(idx, datum)) { + return true; } - }); + } return false; } @@ -1263,10 +1260,9 @@ UNSAFE_TODO({ uint8_t* alpha_channel = m_MaskBuf.data() + 3; for (int col = 0; col < GetWidth(); col++) { - const uint8_t* pPixel = pSrcLine.data() + col * 3; + const auto pPixel = pSrcLine.subspan(col * 3, 3); alpha_channel[col * 4] = - AreColorIndicesOutOfBounds(pPixel, m_CompData.data(), 3) ? 0xFF - : 0; + AreColorIndicesOutOfBounds(pPixel, m_CompData) ? 0xFF : 0; } }); } else {