7#include "core/fpdfapi/parser/cpdf_stream_acc.h"
11#include "core/fdrm/fx_crypt.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_stream.h"
14#include "core/fpdfapi/parser/fpdf_parser_decode.h"
15#include "core/fxcrt/data_vector.h"
16#include "third_party/base/check_op.h"
18CPDF_StreamAcc::CPDF_StreamAcc(
RetainPtr<
const CPDF_Stream> pStream)
19 : m_pStream(std::move(pStream)) {}
23void CPDF_StreamAcc::LoadAllData(
bool bRawAccess,
24 uint32_t estimated_size,
27 DCHECK(!estimated_size);
34 bool bProcessRawData = bRawAccess || !m_pStream->HasFilter();
38 ProcessFilteredData(estimated_size, bImageAcc);
42 LoadAllData(
false, 0,
false);
46 uint32_t estimated_size) {
47 LoadAllData(
false, estimated_size,
false);
51 LoadAllData(
false, estimated_size,
true);
55 LoadAllData(
true, 0,
false);
63 return m_pStream->GetDict()->GetIntegerFor(
"Length1");
74pdfium::span<
const uint8_t> CPDF_StreamAcc::
GetSpan()
const {
76 return absl::get<DataVector<uint8_t>>(m_Data);
77 if (m_pStream && m_pStream->IsMemoryBased())
78 return m_pStream->GetInMemoryRawData();
83 return m_pStream ? m_pStream->KeyForCache() : 0;
88 pdfium::span<
const uint8_t> span = GetSpan();
89 CRYPT_SHA1Generate(span.data(), span.size(), digest);
90 return ByteString(digest, 20);
95 return std::move(absl::get<DataVector<uint8_t>>(m_Data));
97 auto span = absl::get<pdfium::span<
const uint8_t>>(m_Data);
98 return DataVector<uint8_t>(span.begin(), span.end());
101void CPDF_StreamAcc::ProcessRawData() {
102 if (m_pStream->IsUninitialized())
105 uint32_t dwSrcSize = m_pStream->GetRawSize();
109 if (m_pStream->IsMemoryBased()) {
110 m_Data = m_pStream->GetInMemoryRawData();
114 DataVector<uint8_t> data = ReadRawStream();
118 m_Data = std::move(data);
121void CPDF_StreamAcc::ProcessFilteredData(uint32_t estimated_size,
123 if (m_pStream->IsUninitialized())
126 uint32_t dwSrcSize = m_pStream->GetRawSize();
130 absl::variant<pdfium::span<
const uint8_t>, DataVector<uint8_t>> src_data;
131 pdfium::span<
const uint8_t> src_span;
132 if (m_pStream->IsMemoryBased()) {
133 src_span = m_pStream->GetInMemoryRawData();
136 DataVector<uint8_t> temp_src_data = ReadRawStream();
137 if (temp_src_data.empty())
140 src_span = pdfium::make_span(temp_src_data);
141 src_data = std::move(temp_src_data);
145 uint32_t dwDecodedSize = 0;
147 absl::optional<DecoderArray> decoder_array =
148 GetDecoderArray(m_pStream->GetDict());
149 if (!decoder_array.has_value() || decoder_array.value().empty() ||
150 !PDF_DataDecode(src_span, estimated_size, bImageAcc,
151 decoder_array.value(), &pDecodedData, &dwDecodedSize,
152 &m_ImageDecoder, &m_pImageParam)) {
153 m_Data = std::move(src_data);
158 DCHECK_NE(pDecodedData.get(), src_span.data());
160 m_Data = DataVector<uint8_t>(pDecodedData.get(),
161 pDecodedData.get() + dwDecodedSize);
163 m_Data = std::move(src_data);
167DataVector<uint8_t> CPDF_StreamAcc::ReadRawStream()
const {
169 DCHECK(m_pStream->IsFileBased());
170 return m_pStream->ReadAllRawData();
ByteString ComputeDigest() const
void LoadAllDataFiltered()
void LoadAllDataFilteredWithEstimatedSize(uint32_t estimated_size)
pdfium::span< const uint8_t > GetSpan() const
uint64_t KeyForCache() const
int GetLength1ForTest() const
~CPDF_StreamAcc() override
void LoadAllDataImageAcc(uint32_t estimated_size)
RetainPtr< const CPDF_Dictionary > GetImageParam() const
RetainPtr< const CPDF_Stream > GetStream() const
DataVector< uint8_t > DetachData()