summaryrefslogtreecommitdiff
path: root/core/fpdfapi
diff options
context:
space:
mode:
Diffstat (limited to 'core/fpdfapi')
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp2
-rw-r--r--core/fpdfapi/edit/cpdf_pagecontentmanager.cpp2
-rw-r--r--core/fpdfapi/page/cpdf_image.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_crypto_handler.cpp4
-rw-r--r--core/fpdfapi/parser/cpdf_object_unittest.cpp10
-rw-r--r--core/fpdfapi/parser/cpdf_stream.cpp36
-rw-r--r--core/fpdfapi/parser/cpdf_stream.h14
-rw-r--r--core/fpdfapi/parser/cpdf_syntax_parser.cpp3
8 files changed, 35 insertions, 40 deletions
diff --git a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
index e2fa801a58..ea1a1956ae 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentgenerator.cpp
@@ -176,7 +176,7 @@ void CPDF_PageContentGenerator::UpdateContentStreams(
if (buf->tellp() <= 0)
page_content_manager.ScheduleRemoveStreamByIndex(stream_index);
else
- old_stream->SetData(buf);
+ old_stream->SetDataFromStringstream(buf);
}
page_content_manager.ExecuteScheduledRemovals();
diff --git a/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp b/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
index b635144b36..b3fe4ae39a 100644
--- a/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
+++ b/core/fpdfapi/edit/cpdf_pagecontentmanager.cpp
@@ -60,7 +60,7 @@ CPDF_Stream* CPDF_PageContentManager::GetStreamByIndex(size_t stream_index) {
size_t CPDF_PageContentManager::AddStream(std::ostringstream* buf) {
CPDF_Stream* new_stream = doc_->NewIndirect<CPDF_Stream>();
- new_stream->SetData(buf);
+ new_stream->SetDataFromStringstream(buf);
// If there is one Content stream (not in an array), now there will be two, so
// create an array with the old and the new one. The new one's index is 1.
diff --git a/core/fpdfapi/page/cpdf_image.cpp b/core/fpdfapi/page/cpdf_image.cpp
index a8b593682b..a1be407dfe 100644
--- a/core/fpdfapi/page/cpdf_image.cpp
+++ b/core/fpdfapi/page/cpdf_image.cpp
@@ -155,7 +155,7 @@ void CPDF_Image::SetJpegImageInline(
if (!pDict)
return;
- m_pStream->InitStream(&(data[0]), size, std::move(pDict));
+ m_pStream->InitStream(data, std::move(pDict));
}
void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) {
@@ -316,7 +316,7 @@ void CPDF_Image::SetImage(const RetainPtr<CFX_DIBitmap>& pBitmap) {
if (!m_pStream)
m_pStream = pdfium::MakeUnique<CPDF_Stream>();
- m_pStream->InitStream(dest_buf, dest_size, std::move(pDict));
+ m_pStream->InitStream({dest_buf, dest_size}, std::move(pDict));
m_bIsMask = pBitmap->IsAlphaMask();
m_Width = BitmapWidth;
m_Height = BitmapHeight;
diff --git a/core/fpdfapi/parser/cpdf_crypto_handler.cpp b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
index 30d5dc03ff..4f77bc903b 100644
--- a/core/fpdfapi/parser/cpdf_crypto_handler.cpp
+++ b/core/fpdfapi/parser/cpdf_crypto_handler.cpp
@@ -329,7 +329,7 @@ std::unique_ptr<CPDF_Object> CPDF_CryptoHandler::DecryptObjectTree(
stream_access->LoadAllDataRaw();
if (IsCipherAES() && stream_access->GetSize() < 16) {
- stream->SetData(nullptr, 0);
+ stream->SetData({});
continue;
}
@@ -348,7 +348,7 @@ std::unique_ptr<CPDF_Object> CPDF_CryptoHandler::DecryptObjectTree(
stream->SetData(decrypted_buf.DetachBuffer(), decrypted_size);
} else {
// Decryption failed, set the stream to empty
- stream->SetData(nullptr, 0);
+ stream->SetData({});
}
}
}
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 78a0af7299..768ce98265 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -803,8 +803,7 @@ TEST(PDFArrayTest, ConvertIndirect) {
TEST(PDFStreamTest, SetData) {
std::vector<uint8_t> data(100);
auto stream = pdfium::MakeUnique<CPDF_Stream>();
- stream->InitStream(data.data(), data.size(),
- pdfium::MakeUnique<CPDF_Dictionary>());
+ stream->InitStream(data, pdfium::MakeUnique<CPDF_Dictionary>());
EXPECT_EQ(static_cast<int>(data.size()),
stream->GetDict()->GetIntegerFor(pdfium::stream::kLength));
@@ -814,7 +813,7 @@ TEST(PDFStreamTest, SetData) {
L"SomeParams");
std::vector<uint8_t> new_data(data.size() * 2);
- stream->SetData(new_data.data(), new_data.size());
+ stream->SetData(new_data);
// The "Length" field should be updated for new data size.
EXPECT_EQ(static_cast<int>(new_data.size()),
@@ -830,8 +829,7 @@ TEST(PDFStreamTest, SetData) {
TEST(PDFStreamTest, SetDataAndRemoveFilter) {
std::vector<uint8_t> data(100);
auto stream = pdfium::MakeUnique<CPDF_Stream>();
- stream->InitStream(data.data(), data.size(),
- pdfium::MakeUnique<CPDF_Dictionary>());
+ stream->InitStream(data, pdfium::MakeUnique<CPDF_Dictionary>());
EXPECT_EQ(static_cast<int>(data.size()),
stream->GetDict()->GetIntegerFor(pdfium::stream::kLength));
@@ -841,7 +839,7 @@ TEST(PDFStreamTest, SetDataAndRemoveFilter) {
L"SomeParams");
std::vector<uint8_t> new_data(data.size() * 2);
- stream->SetDataAndRemoveFilter(new_data.data(), new_data.size());
+ stream->SetDataAndRemoveFilter(new_data);
// The "Length" field should be updated for new data size.
EXPECT_EQ(static_cast<int>(new_data.size()),
stream->GetDict()->GetIntegerFor(pdfium::stream::kLength));
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp
index 64478996a8..81d0e840c0 100644
--- a/core/fpdfapi/parser/cpdf_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -69,11 +69,10 @@ const CPDF_Stream* CPDF_Stream::AsStream() const {
return this;
}
-void CPDF_Stream::InitStream(const uint8_t* pData,
- uint32_t size,
+void CPDF_Stream::InitStream(pdfium::span<const uint8_t> pData,
std::unique_ptr<CPDF_Dictionary> pDict) {
m_pDict = std::move(pDict);
- SetData(pData, size);
+ SetData(pData);
}
void CPDF_Stream::InitStreamFromFile(
@@ -111,29 +110,31 @@ std::unique_ptr<CPDF_Object> CPDF_Stream::CloneNonCyclic(
std::move(pNewDict));
}
-void CPDF_Stream::SetDataAndRemoveFilter(const uint8_t* pData, uint32_t size) {
- SetData(pData, size);
+void CPDF_Stream::SetDataAndRemoveFilter(pdfium::span<const uint8_t> pData) {
+ SetData(pData);
m_pDict->RemoveFor("Filter");
m_pDict->RemoveFor(pdfium::stream::kDecodeParms);
}
-void CPDF_Stream::SetDataAndRemoveFilter(std::ostringstream* stream) {
+void CPDF_Stream::SetDataFromStringstreamAndRemoveFilter(
+ std::ostringstream* stream) {
if (stream->tellp() <= 0) {
- SetDataAndRemoveFilter(nullptr, 0);
+ SetDataAndRemoveFilter({});
return;
}
SetDataAndRemoveFilter(
- reinterpret_cast<const uint8_t*>(stream->str().c_str()), stream->tellp());
+ {reinterpret_cast<const uint8_t*>(stream->str().c_str()),
+ static_cast<size_t>(stream->tellp())});
}
-void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) {
+void CPDF_Stream::SetData(pdfium::span<const uint8_t> pData) {
std::unique_ptr<uint8_t, FxFreeDeleter> data_copy;
- if (pData) {
- data_copy.reset(FX_Alloc(uint8_t, size));
- memcpy(data_copy.get(), pData, size);
+ if (!pData.empty()) {
+ data_copy.reset(FX_Alloc(uint8_t, pData.size()));
+ memcpy(data_copy.get(), pData.data(), pData.size());
}
- SetData(std::move(data_copy), size);
+ SetData(std::move(data_copy), pData.size());
}
void CPDF_Stream::SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
@@ -147,14 +148,13 @@ void CPDF_Stream::SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size));
}
-void CPDF_Stream::SetData(std::ostringstream* stream) {
+void CPDF_Stream::SetDataFromStringstream(std::ostringstream* stream) {
if (stream->tellp() <= 0) {
- SetData(nullptr, 0);
+ SetData({});
return;
}
-
- SetData(reinterpret_cast<const uint8_t*>(stream->str().c_str()),
- stream->tellp());
+ SetData({reinterpret_cast<const uint8_t*>(stream->str().c_str()),
+ static_cast<size_t>(stream->tellp())});
}
bool CPDF_Stream::ReadRawData(FX_FILESIZE offset,
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h
index 4a5ac61011..3deb9cddec 100644
--- a/core/fpdfapi/parser/cpdf_stream.h
+++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -18,7 +18,6 @@
class CPDF_Stream : public CPDF_Object {
public:
CPDF_Stream();
-
CPDF_Stream(std::unique_ptr<uint8_t, FxFreeDeleter> pData,
uint32_t size,
std::unique_ptr<CPDF_Dictionary> pDict);
@@ -42,17 +41,16 @@ class CPDF_Stream : public CPDF_Object {
// Use CPDF_StreamAcc to data access in all cases.
uint8_t* GetInMemoryRawData() const { return m_pDataBuf.get(); }
- // Does not takes ownership of |pData|, copies into internally-owned buffer.
- void SetData(const uint8_t* pData, uint32_t size);
+ // Copies span into internally-owned buffer.
+ void SetData(pdfium::span<const uint8_t> pData);
void SetData(std::unique_ptr<uint8_t, FxFreeDeleter> pData, uint32_t size);
- void SetData(std::ostringstream* stream);
+ void SetDataFromStringstream(std::ostringstream* stream);
// Set data and remove "Filter" and "DecodeParms" fields from stream
// dictionary.
- void SetDataAndRemoveFilter(const uint8_t* pData, uint32_t size);
- void SetDataAndRemoveFilter(std::ostringstream* stream);
+ void SetDataAndRemoveFilter(pdfium::span<const uint8_t> pData);
+ void SetDataFromStringstreamAndRemoveFilter(std::ostringstream* stream);
- void InitStream(const uint8_t* pData,
- uint32_t size,
+ void InitStream(pdfium::span<const uint8_t> pData,
std::unique_ptr<CPDF_Dictionary> pDict);
void InitStreamFromFile(const RetainPtr<IFX_SeekableReadStream>& pFile,
std::unique_ptr<CPDF_Dictionary> pDict);
diff --git a/core/fpdfapi/parser/cpdf_syntax_parser.cpp b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
index 89bf991cd4..65a8d78b13 100644
--- a/core/fpdfapi/parser/cpdf_syntax_parser.cpp
+++ b/core/fpdfapi/parser/cpdf_syntax_parser.cpp
@@ -708,8 +708,7 @@ std::unique_ptr<CPDF_Stream> CPDF_SyntaxParser::ReadStream(
pStream->InitStreamFromFile(data, std::move(pDict));
} else {
DCHECK(!len);
- // Empty stream
- pStream->InitStream(nullptr, 0, std::move(pDict));
+ pStream->InitStream({}, std::move(pDict)); // Empty stream
}
const FX_FILESIZE end_stream_offset = GetPos();
memset(m_WordBuffer, 0, kEndObjStr.GetLength() + 1);