Change `CPDF_IndexedCS::lookup_table_` to a DataVector Stop storing binary data in a ByteString. Change-Id: I0feeb49ca2cd48f7cd75b0069b1b485108f22c36 Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/119933 Reviewed-by: Thomas Sepez <tsepez@google.com> Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fpdfapi/page/cpdf_indexedcs.cpp b/core/fpdfapi/page/cpdf_indexedcs.cpp index 8f4e195..6c11b9e 100644 --- a/core/fpdfapi/page/cpdf_indexedcs.cpp +++ b/core/fpdfapi/page/cpdf_indexedcs.cpp
@@ -5,7 +5,6 @@ #include "core/fpdfapi/page/cpdf_indexedcs.h" #include <set> -#include <vector> #include "core/fpdfapi/page/cpdf_colorspace.h" #include "core/fpdfapi/page/cpdf_docpagedata.h" @@ -76,12 +75,16 @@ return 0; } - if (const CPDF_String* pString = pTableObj->AsString()) { - lookup_table_ = pString->GetString(); - } else if (const CPDF_Stream* pStream = pTableObj->AsStream()) { - auto pAcc = pdfium::MakeRetain<CPDF_StreamAcc>(pdfium::WrapRetain(pStream)); - pAcc->LoadAllDataFiltered(); - lookup_table_ = ByteStringView(pAcc->GetSpan()); + if (const CPDF_String* str_obj = pTableObj->AsString()) { + ByteString str_data = str_obj->GetString(); + pdfium::span<const uint8_t> str_span = str_data.unsigned_span(); + lookup_table_ = DataVector<uint8_t>(str_span.begin(), str_span.end()); + } else if (const CPDF_Stream* stream_obj = pTableObj->AsStream()) { + auto acc = + pdfium::MakeRetain<CPDF_StreamAcc>(pdfium::WrapRetain(stream_obj)); + acc->LoadAllDataFiltered(); + pdfium::span<const uint8_t> str_span = acc->GetSpan(); + lookup_table_ = DataVector<uint8_t>(str_span.begin(), str_span.end()); } return 1; } @@ -101,19 +104,18 @@ FX_SAFE_SIZE_T length = index; length += 1; length *= base_component_count_; - if (!length.IsValid() || length.ValueOrDie() > lookup_table_.GetLength()) { + if (!length.IsValid() || length.ValueOrDie() > lookup_table_.size()) { *R = 0; *G = 0; *B = 0; return false; } - std::vector<float> comps(base_component_count_); - pdfium::span<const uint8_t> pTable = lookup_table_.unsigned_span(); + DataVector<float> comps(base_component_count_); for (uint32_t i = 0; i < base_component_count_; ++i) { comps[i] = component_min_max_[i].min + component_min_max_[i].max * - pTable[index * base_component_count_ + i] / 255; + lookup_table_[index * base_component_count_ + i] / 255; } return m_pBaseCS->GetRGB(comps, R, G, B); }
diff --git a/core/fpdfapi/page/cpdf_indexedcs.h b/core/fpdfapi/page/cpdf_indexedcs.h index 22690c6..4e2cffd 100644 --- a/core/fpdfapi/page/cpdf_indexedcs.h +++ b/core/fpdfapi/page/cpdf_indexedcs.h
@@ -5,10 +5,11 @@ #ifndef CORE_FPDFAPI_PAGE_CPDF_INDEXEDCS_H_ #define CORE_FPDFAPI_PAGE_CPDF_INDEXEDCS_H_ +#include <stdint.h> + #include <set> #include "core/fpdfapi/page/cpdf_basedcs.h" -#include "core/fxcrt/bytestring.h" #include "core/fxcrt/data_vector.h" #include "core/fxcrt/fx_memory_wrappers.h" #include "core/fxcrt/retain_ptr.h" @@ -43,7 +44,7 @@ uint32_t base_component_count_ = 0; int max_index_ = 0; - ByteString lookup_table_; + DataVector<uint8_t> lookup_table_; DataVector<IndexedColorMinMax> component_min_max_; };