summaryrefslogtreecommitdiff
path: root/core/fpdfapi/parser/cpdf_object_unittest.cpp
diff options
context:
space:
mode:
authorArtem Strygin <art-snake@yandex-team.ru>2017-09-04 17:01:41 +0300
committerChromium commit bot <commit-bot@chromium.org>2017-09-05 16:04:08 +0000
commit4fde70e28c6aff85ad30a958823e658678f5cfb6 (patch)
treebaaeb84083b6f245940f58ae2331ee08aad0527e /core/fpdfapi/parser/cpdf_object_unittest.cpp
parent16b77c7176313531609a3a062d286f555c4710a1 (diff)
downloadpdfium-4fde70e28c6aff85ad30a958823e658678f5cfb6.tar.xz
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 <dsinclair@chromium.org> Commit-Queue: Art Snake <art-snake@yandex-team.ru>
Diffstat (limited to 'core/fpdfapi/parser/cpdf_object_unittest.cpp')
-rw-r--r--core/fpdfapi/parser/cpdf_object_unittest.cpp24
1 files changed, 24 insertions, 0 deletions
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<uint8_t, FxFreeDeleter> data;
+ data.reset(FX_Alloc(uint8_t, kBufSize));
+ auto stream = pdfium::MakeUnique<CPDF_Stream>(
+ std::move(data), kBufSize, pdfium::MakeUnique<CPDF_Dictionary>());
+ EXPECT_EQ(static_cast<int>(kBufSize),
+ stream->GetDict()->GetIntegerFor("Length"));
+ }
+ // The length field should be corrected on stream create.
+ {
+ std::unique_ptr<uint8_t, FxFreeDeleter> data;
+ data.reset(FX_Alloc(uint8_t, kBufSize));
+ auto dict = pdfium::MakeUnique<CPDF_Dictionary>();
+ dict->SetNewFor<CPDF_Number>("Length", 30000);
+ auto stream = pdfium::MakeUnique<CPDF_Stream>(std::move(data), kBufSize,
+ std::move(dict));
+ EXPECT_EQ(static_cast<int>(kBufSize),
+ stream->GetDict()->GetIntegerFor("Length"));
+ }
+}
+
TEST(PDFDictionaryTest, CloneDirectObject) {
CPDF_IndirectObjectHolder objects_holder;
auto dict = pdfium::MakeUnique<CPDF_Dictionary>();