diff options
author | Dan Sinclair <dsinclair@chromium.org> | 2017-06-13 15:21:14 -0400 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2017-06-13 19:33:05 +0000 |
commit | 957480c17682008ae2a14723868fcdcab89b6577 (patch) | |
tree | cf5f1cb09c4385b7a107d8c8efcc99ea046849f8 /fpdfsdk | |
parent | 6500c6faf82f636d55c9ca5682711022890bef1d (diff) | |
download | pdfium-957480c17682008ae2a14723868fcdcab89b6577.tar.xz |
Allow zero length streams when parsing.chromium/3130
It's possible to create a stream of length 0 in a PDF document.
Currently the code will early exit and return a nullptr. This causes
issues when you want to print the given PDF as the FPDF_ImportPages code
ends up only generating up to the zero length object.
This CL allows creating streams with length 0 and updates the PDF saving
code to output a blank stream.
Bug: chromium:732380
Change-Id: I44182ba4aaac7c51284b002ba01bbc34b6bcf9e0
Reviewed-on: https://pdfium-review.googlesource.com/6490
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: dsinclair <dsinclair@chromium.org>
Diffstat (limited to 'fpdfsdk')
-rw-r--r-- | fpdfsdk/fpdfppo_embeddertest.cpp | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/fpdfsdk/fpdfppo_embeddertest.cpp b/fpdfsdk/fpdfppo_embeddertest.cpp index db39700ca1..7e6ff33fc3 100644 --- a/fpdfsdk/fpdfppo_embeddertest.cpp +++ b/fpdfsdk/fpdfppo_embeddertest.cpp @@ -1,11 +1,11 @@ // Copyright 2016 PDFium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. - -#include "public/fpdf_ppo.h" +#include <string> #include "core/fxcrt/fx_basic.h" #include "public/fpdf_edit.h" +#include "public/fpdf_ppo.h" #include "public/fpdfview.h" #include "testing/embedder_test.h" #include "testing/gtest/include/gtest/gtest.h" @@ -131,7 +131,7 @@ TEST_F(FPDFPPOEmbeddertest, BUG_664284) { EXPECT_TRUE(OpenDocument("bug_664284.pdf")); FPDF_PAGE page = LoadPage(0); - EXPECT_TRUE(page); + ASSERT_NE(nullptr, page); FPDF_DOCUMENT output_doc = FPDF_CreateNewDocument(); EXPECT_TRUE(output_doc); @@ -140,3 +140,37 @@ TEST_F(FPDFPPOEmbeddertest, BUG_664284) { UnloadPage(page); } + +TEST_F(FPDFPPOEmbeddertest, ImportWithZeroLengthStream) { + EXPECT_TRUE(OpenDocument("zero_length_stream.pdf")); + FPDF_PAGE page = LoadPage(0); + ASSERT_NE(nullptr, page); + + FPDF_BITMAP bitmap = RenderPage(page); + ASSERT_EQ(200, FPDFBitmap_GetWidth(bitmap)); + ASSERT_EQ(200, FPDFBitmap_GetHeight(bitmap)); + ASSERT_EQ(800, FPDFBitmap_GetStride(bitmap)); + + std::string digest = HashBitmap(bitmap, 200, 200); + FPDFBitmap_Destroy(bitmap); + FPDF_ClosePage(page); + + FPDF_DOCUMENT new_doc = FPDF_CreateNewDocument(); + EXPECT_TRUE(new_doc); + EXPECT_TRUE(FPDF_ImportPages(new_doc, document(), "1", 0)); + + EXPECT_EQ(1, FPDF_GetPageCount(new_doc)); + FPDF_PAGE new_page = FPDF_LoadPage(new_doc, 0); + ASSERT_NE(nullptr, new_page); + FPDF_BITMAP new_bitmap = RenderPage(new_page); + ASSERT_EQ(200, FPDFBitmap_GetWidth(new_bitmap)); + ASSERT_EQ(200, FPDFBitmap_GetHeight(new_bitmap)); + ASSERT_EQ(800, FPDFBitmap_GetStride(new_bitmap)); + + std::string new_digest = HashBitmap(new_bitmap, 200, 200); + FPDFBitmap_Destroy(new_bitmap); + FPDF_ClosePage(new_page); + FPDF_CloseDocument(new_doc); + + EXPECT_EQ(digest, new_digest); +} |