Kaydet (Commit) 83b25e4b authored tarafından Caolán McNamara's avatar Caolán McNamara

forcepoint#71 sanity check when copying pieces of imported pdf

Change-Id: I7e340e15c95cdfa8b185f61fad7e14bd00babf21
Reviewed-on: https://gerrit.libreoffice.org/58555
Tested-by: Jenkins
Reviewed-by: 's avatarCaolán McNamara <caolanm@redhat.com>
Tested-by: 's avatarCaolán McNamara <caolanm@redhat.com>
üst 2ffe2282
...@@ -47,6 +47,7 @@ public: ...@@ -47,6 +47,7 @@ public:
PdfExportTest(); PdfExportTest();
virtual void setUp() override; virtual void setUp() override;
virtual void tearDown() override; virtual void tearDown() override;
void topdf(const OUString& rFile);
void load(const OUString& rFile, vcl::filter::PDFDocument& rDocument); void load(const OUString& rFile, vcl::filter::PDFDocument& rDocument);
/// Tests that a pdf image is roundtripped back to PDF as a vector format. /// Tests that a pdf image is roundtripped back to PDF as a vector format.
void testTdf106059(); void testTdf106059();
...@@ -59,6 +60,7 @@ public: ...@@ -59,6 +60,7 @@ public:
void testTdf106206(); void testTdf106206();
/// Tests export of PDF images without reference XObjects. /// Tests export of PDF images without reference XObjects.
void testTdf106693(); void testTdf106693();
void testForcePoint71();
void testTdf106972(); void testTdf106972();
void testTdf106972Pdf17(); void testTdf106972Pdf17();
void testTdf107013(); void testTdf107013();
...@@ -95,6 +97,7 @@ public: ...@@ -95,6 +97,7 @@ public:
CPPUNIT_TEST(testTdf105093); CPPUNIT_TEST(testTdf105093);
CPPUNIT_TEST(testTdf106206); CPPUNIT_TEST(testTdf106206);
CPPUNIT_TEST(testTdf106693); CPPUNIT_TEST(testTdf106693);
CPPUNIT_TEST(testForcePoint71);
CPPUNIT_TEST(testTdf106972); CPPUNIT_TEST(testTdf106972);
CPPUNIT_TEST(testTdf106972Pdf17); CPPUNIT_TEST(testTdf106972Pdf17);
CPPUNIT_TEST(testTdf107013); CPPUNIT_TEST(testTdf107013);
...@@ -170,7 +173,7 @@ void PdfExportTest::tearDown() ...@@ -170,7 +173,7 @@ void PdfExportTest::tearDown()
char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/pdfexport/data/"; char const DATA_DIRECTORY[] = "/vcl/qa/cppunit/pdfexport/data/";
void PdfExportTest::load(const OUString& rFile, vcl::filter::PDFDocument& rDocument) void PdfExportTest::topdf(const OUString& rFile)
{ {
// Import the bugdoc and export as PDF. // Import the bugdoc and export as PDF.
OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFile; OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFile;
...@@ -181,6 +184,11 @@ void PdfExportTest::load(const OUString& rFile, vcl::filter::PDFDocument& rDocum ...@@ -181,6 +184,11 @@ void PdfExportTest::load(const OUString& rFile, vcl::filter::PDFDocument& rDocum
utl::MediaDescriptor aMediaDescriptor; utl::MediaDescriptor aMediaDescriptor;
aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export"); aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList()); xStorable->storeToURL(maTempFile.GetURL(), aMediaDescriptor.getAsConstPropertyValueList());
}
void PdfExportTest::load(const OUString& rFile, vcl::filter::PDFDocument& rDocument)
{
topdf(rFile);
// Parse the export result. // Parse the export result.
SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ); SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
...@@ -1450,6 +1458,12 @@ void PdfExportTest::testTdf113143() ...@@ -1450,6 +1458,12 @@ void PdfExportTest::testTdf113143()
CPPUNIT_ASSERT_LESS(nLarger, nSmaller); CPPUNIT_ASSERT_LESS(nLarger, nSmaller);
} }
void PdfExportTest::testForcePoint71()
{
// I just care it doesn't crash
topdf("forcepoint71.key");
}
CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest); CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
} }
......
...@@ -9023,7 +9023,11 @@ sal_Int32 PDFWriterImpl::copyExternalResource(SvMemoryStream& rDocBuffer, filter ...@@ -9023,7 +9023,11 @@ sal_Int32 PDFWriterImpl::copyExternalResource(SvMemoryStream& rDocBuffer, filter
{ {
// Copy the last part here, in the complex case. // Copy the last part here, in the complex case.
sal_uInt64 nDictEnd = rObject.GetDictionaryOffset() + rObject.GetDictionaryLength(); sal_uInt64 nDictEnd = rObject.GetDictionaryOffset() + rObject.GetDictionaryLength();
aLine.append(static_cast<const sal_Char*>(rDocBuffer.GetData()) + nCopyStart, nDictEnd - nCopyStart); const sal_Int32 nLen = nDictEnd - nCopyStart;
if (nLen < 0)
SAL_WARN("vcl.pdfwriter", "copyExternalResource() failed");
else
aLine.append(static_cast<const sal_Char*>(rDocBuffer.GetData()) + nCopyStart, nLen);
} }
else else
// Can copy it as-is. // Can copy it as-is.
...@@ -9086,7 +9090,11 @@ sal_Int32 PDFWriterImpl::copyExternalResource(SvMemoryStream& rDocBuffer, filter ...@@ -9086,7 +9090,11 @@ sal_Int32 PDFWriterImpl::copyExternalResource(SvMemoryStream& rDocBuffer, filter
{ {
// Copy the last part here, in the complex case. // Copy the last part here, in the complex case.
sal_uInt64 nArrEnd = rObject.GetArrayOffset() + rObject.GetArrayLength(); sal_uInt64 nArrEnd = rObject.GetArrayOffset() + rObject.GetArrayLength();
aLine.append(static_cast<const sal_Char*>(rDocBuffer.GetData()) + nCopyStart, nArrEnd - nCopyStart); const sal_Int32 nLen = nArrEnd - nCopyStart;
if (nLen < 0)
SAL_WARN("vcl.pdfwriter", "copyExternalResource() failed");
else
aLine.append(static_cast<const sal_Char*>(rDocBuffer.GetData()) + nCopyStart, nLen);
} }
else else
// Can copy it as-is. // Can copy it as-is.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment