From 4fde70e28c6aff85ad30a958823e658678f5cfb6 Mon Sep 17 00:00:00 2001 From: Artem Strygin Date: Mon, 4 Sep 2017 17:01:41 +0300 Subject: Fix length field in dictionary on create stream The CPDF_stream constructors were not setting the "Length" into the stream dictionary. The "Length" was being set by the SetData methods. This CL fixes the constructor to properly set the "Length" field. Change-Id: Iee1bd7f7a096d415ab01ee3d2f3416e19e87ece9 Reviewed-on: https://pdfium-review.googlesource.com/13010 Reviewed-by: dsinclair Commit-Queue: Art Snake --- core/fpdfapi/parser/cpdf_object_unittest.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'core/fpdfapi/parser/cpdf_object_unittest.cpp') diff --git a/core/fpdfapi/parser/cpdf_object_unittest.cpp b/core/fpdfapi/parser/cpdf_object_unittest.cpp index dd170ba90e..169e0f1e56 100644 --- a/core/fpdfapi/parser/cpdf_object_unittest.cpp +++ b/core/fpdfapi/parser/cpdf_object_unittest.cpp @@ -828,6 +828,30 @@ TEST(PDFStreamTest, SetDataAndRemoveFilter) { EXPECT_FALSE(stream->GetDict()->KeyExist("DecodeParms")); } +TEST(PDFStreamTest, LengthInDictionaryOnCreate) { + static constexpr uint32_t kBufSize = 100; + // The length field should be created on stream create. + { + std::unique_ptr data; + data.reset(FX_Alloc(uint8_t, kBufSize)); + auto stream = pdfium::MakeUnique( + std::move(data), kBufSize, pdfium::MakeUnique()); + EXPECT_EQ(static_cast(kBufSize), + stream->GetDict()->GetIntegerFor("Length")); + } + // The length field should be corrected on stream create. + { + std::unique_ptr data; + data.reset(FX_Alloc(uint8_t, kBufSize)); + auto dict = pdfium::MakeUnique(); + dict->SetNewFor("Length", 30000); + auto stream = pdfium::MakeUnique(std::move(data), kBufSize, + std::move(dict)); + EXPECT_EQ(static_cast(kBufSize), + stream->GetDict()->GetIntegerFor("Length")); + } +} + TEST(PDFDictionaryTest, CloneDirectObject) { CPDF_IndirectObjectHolder objects_holder; auto dict = pdfium::MakeUnique(); -- cgit v1.2.3