summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/fpdfapi/parser/cpdf_object_unittest.cpp45
-rw-r--r--core/fpdfapi/parser/cpdf_stream.cpp13
-rw-r--r--core/fpdfapi/parser/cpdf_stream.h4
-rw-r--r--core/fpdfdoc/cpvt_generateap.cpp2
4 files changed, 61 insertions, 3 deletions
diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp
index 7d474b2e7d..ffaa2648a3 100644
--- a/core/fpdfapi/parser/cpdf_object_unittest.cpp
+++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp
@@ -785,6 +785,51 @@ TEST(PDFArrayTest, ConvertIndirect) {
EXPECT_EQ(42, array->GetIntegerAt(0));
}
+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>());
+ EXPECT_EQ(static_cast<int>(data.size()),
+ stream->GetDict()->GetIntegerFor("Length"));
+
+ stream->GetDict()->SetNewFor<CPDF_String>("Filter", L"SomeFilter");
+ stream->GetDict()->SetNewFor<CPDF_String>("DecodeParms", L"SomeParams");
+
+ std::vector<uint8_t> new_data(data.size() * 2);
+ stream->SetData(new_data.data(), new_data.size());
+
+ // The "Length" field should be updated for new data size.
+ EXPECT_EQ(static_cast<int>(new_data.size()),
+ stream->GetDict()->GetIntegerFor("Length"));
+
+ // The "Filter" and "DecodeParms" fields should not be changed.
+ EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor("Filter"), L"SomeFilter");
+ EXPECT_EQ(stream->GetDict()->GetUnicodeTextFor("DecodeParms"), L"SomeParams");
+}
+
+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>());
+ EXPECT_EQ(static_cast<int>(data.size()),
+ stream->GetDict()->GetIntegerFor("Length"));
+
+ stream->GetDict()->SetNewFor<CPDF_String>("Filter", L"SomeFilter");
+ stream->GetDict()->SetNewFor<CPDF_String>("DecodeParms", L"SomeParams");
+
+ std::vector<uint8_t> new_data(data.size() * 2);
+ stream->SetDataAndRemoveFilter(new_data.data(), new_data.size());
+ // The "Length" field should be updated for new data size.
+ EXPECT_EQ(static_cast<int>(new_data.size()),
+ stream->GetDict()->GetIntegerFor("Length"));
+
+ // The "Filter" and "DecodeParms" should be removed.
+ EXPECT_FALSE(stream->GetDict()->KeyExist("Filter"));
+ EXPECT_FALSE(stream->GetDict()->KeyExist("DecodeParms"));
+}
+
TEST(PDFDictionaryTest, CloneDirectObject) {
CPDF_IndirectObjectHolder objects_holder;
auto dict = pdfium::MakeUnique<CPDF_Dictionary>();
diff --git a/core/fpdfapi/parser/cpdf_stream.cpp b/core/fpdfapi/parser/cpdf_stream.cpp
index ec12ac5080..d430a4fb45 100644
--- a/core/fpdfapi/parser/cpdf_stream.cpp
+++ b/core/fpdfapi/parser/cpdf_stream.cpp
@@ -97,6 +97,17 @@ 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);
+ m_pDict->RemoveFor("Filter");
+ m_pDict->RemoveFor("DecodeParms");
+}
+
+void CPDF_Stream::SetDataAndRemoveFilter(std::ostringstream* stream) {
+ SetDataAndRemoveFilter(
+ reinterpret_cast<const uint8_t*>(stream->str().c_str()), stream->tellp());
+}
+
void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) {
m_bMemoryBased = true;
m_pDataBuf.reset(FX_Alloc(uint8_t, size));
@@ -106,8 +117,6 @@ void CPDF_Stream::SetData(const uint8_t* pData, uint32_t size) {
if (!m_pDict)
m_pDict = pdfium::MakeUnique<CPDF_Dictionary>();
m_pDict->SetNewFor<CPDF_Number>("Length", static_cast<int>(size));
- m_pDict->RemoveFor("Filter");
- m_pDict->RemoveFor("DecodeParms");
}
void CPDF_Stream::SetData(std::ostringstream* stream) {
diff --git a/core/fpdfapi/parser/cpdf_stream.h b/core/fpdfapi/parser/cpdf_stream.h
index d58f608f72..2795f7daae 100644
--- a/core/fpdfapi/parser/cpdf_stream.h
+++ b/core/fpdfapi/parser/cpdf_stream.h
@@ -42,6 +42,10 @@ class CPDF_Stream : public CPDF_Object {
// Does not takes ownership of |pData|, copies into internally-owned buffer.
void SetData(const uint8_t* pData, uint32_t size);
void SetData(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 InitStream(const uint8_t* pData,
uint32_t size,
diff --git a/core/fpdfdoc/cpvt_generateap.cpp b/core/fpdfdoc/cpvt_generateap.cpp
index 956f91289b..d1abde681d 100644
--- a/core/fpdfdoc/cpvt_generateap.cpp
+++ b/core/fpdfdoc/cpvt_generateap.cpp
@@ -429,7 +429,7 @@ bool GenerateWidgetAP(CPDF_Document* pDoc,
} break;
}
if (pNormalStream) {
- pNormalStream->SetData(&sAppStream);
+ pNormalStream->SetDataAndRemoveFilter(&sAppStream);
pStreamDict = pNormalStream->GetDict();
if (pStreamDict) {
pStreamDict->SetMatrixFor("Matrix", matrix);