diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-02-27 16:38:54 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-03-14 13:39:49 +0100 |
commit | 65e22b5e821c9bbaf3febb3438c1a397c6bdb6ea (patch) | |
tree | c1bf874e4d1d5bb9a0bd1db5bd6ff124ced7c3b8 /vcl/qa | |
parent | 2ffc2672afff20a8c32cbfe7518923c739346a59 (diff) |
tdf#106206 PDF export: fix unexpected /Im0 in page contents stream
The early return should just skip the code that's specific to pdf
images, not everything.
Change-Id: Ia9e02b05051a085a9fdf2f690c21f9ffccb7bf4d
Reviewed-on: https://gerrit.libreoffice.org/34685
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
(cherry picked from commit e7adffff8039175bc50b56b4c07ce0b9d8fed629)
Diffstat (limited to 'vcl/qa')
-rw-r--r-- | vcl/qa/cppunit/pdfexport/data/tdf106206.odt | bin | 0 -> 74641 bytes | |||
-rw-r--r-- | vcl/qa/cppunit/pdfexport/pdfexport.cxx | 54 |
2 files changed, 54 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/pdfexport/data/tdf106206.odt b/vcl/qa/cppunit/pdfexport/data/tdf106206.odt Binary files differnew file mode 100644 index 000000000000..3581157de443 --- /dev/null +++ b/vcl/qa/cppunit/pdfexport/data/tdf106206.odt diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index af6e86b7d17e..edd63e6fc351 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -44,6 +44,8 @@ public: void testTdf105461(); /// Tests that embedded video from Impress is not exported as a linked one. void testTdf105093(); + /// Tests export of non-PDF images. + void testTdf106206(); #endif CPPUNIT_TEST_SUITE(PdfExportTest); @@ -51,6 +53,7 @@ public: CPPUNIT_TEST(testTdf106059); CPPUNIT_TEST(testTdf105461); CPPUNIT_TEST(testTdf105093); + CPPUNIT_TEST(testTdf106206); #endif CPPUNIT_TEST_SUITE_END(); }; @@ -200,6 +203,57 @@ void PdfExportTest::testTdf105093() // This key was missing, the embedded video was handled as a linked one. CPPUNIT_ASSERT(pFileSpec->LookupElement("EF")); } + +void PdfExportTest::testTdf106206() +{ + // Import the bugdoc and export as PDF. + OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "tdf106206.odt"; + mxComponent = loadFromDesktop(aURL); + CPPUNIT_ASSERT(mxComponent.is()); + + uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); + utl::TempFile aTempFile; + aTempFile.EnableKillingFile(); + utl::MediaDescriptor aMediaDescriptor; + aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); + xStorable->storeToURL(aTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); + + // Parse the export result. + xmlsecurity::pdfio::PDFDocument aDocument; + SvFileStream aStream(aTempFile.GetURL(), StreamMode::READ); + CPPUNIT_ASSERT(aDocument.Read(aStream)); + + // The document has one page. + std::vector<xmlsecurity::pdfio::PDFObjectElement*> aPages = aDocument.GetPages(); + CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), aPages.size()); + + // The page has a stream. + xmlsecurity::pdfio::PDFObjectElement* pContents = aPages[0]->LookupObject("Contents"); + CPPUNIT_ASSERT(pContents); + xmlsecurity::pdfio::PDFStreamElement* pStream = pContents->GetStream(); + CPPUNIT_ASSERT(pStream); + SvMemoryStream& rObjectStream = pStream->GetMemory(); + // Uncompress it. + SvMemoryStream aUncompressed; + ZCodec aZCodec; + aZCodec.BeginCompression(); + rObjectStream.Seek(0); + aZCodec.Decompress(rObjectStream, aUncompressed); + CPPUNIT_ASSERT(aZCodec.EndCompression()); + + // Make sure there is an image reference there. + OString aImage("/Im"); + auto pStart = static_cast<const char*>(aUncompressed.GetData()); + const char* pEnd = pStart + aUncompressed.GetSize(); + auto it = std::search(pStart, pEnd, aImage.getStr(), aImage.getStr() + aImage.getLength()); + CPPUNIT_ASSERT(it != pEnd); + + // And also that it's not an invalid one. + OString aInvalidImage("/Im0"); + it = std::search(pStart, pEnd, aInvalidImage.getStr(), aInvalidImage.getStr() + aInvalidImage.getLength()); + // This failed, object #0 was referenced. + CPPUNIT_ASSERT(bool(it == pEnd)); +} #endif CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest); |