[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - vcl/qa vcl/source

2019-03-28 Thread Luboš Luňák (via logerrit)
 vcl/qa/cppunit/pdfexport/data/tdf121615.odt |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx  |   58 
 vcl/source/filter/jpeg/JpegWriter.cxx   |5 +-
 3 files changed, 62 insertions(+), 1 deletion(-)

New commits:
commit 57e6e1e1cec5465b81450bcbabac43beaee7ea74
Author: Luboš Luňák 
AuthorDate: Wed Mar 13 17:35:27 2019 +0100
Commit: Xisco Faulí 
CommitDate: Thu Mar 28 14:50:06 2019 +0100

fix grayscale jpeg writing in pdfexport (tdf#121615)

If the bitmap to be written is non-8bit, e.g. in case of using OpenGL
(on Linux the test requires "SAL_FORCEGL=1 SAL_USE_VCLPLUGIN=gen",
on Windows it's probably the default case), then the bitmap is not
in native format for 8bit. This was done correctly by 45e8e0fbee40f
that introduced it but somehow it got lost later (I can't even find
where).

Reviewed-on: https://gerrit.libreoffice.org/69213
Tested-by: Jenkins
Reviewed-by: Luboš Luňák 
(cherry picked from commit 4b48f5c2fd2d0d6de1e1df4c13ceba47b1da7b5e)

Change-Id: Ib1810cb9cf12e373c1cb41da40fa28e96ad7db28
Reviewed-on: https://gerrit.libreoffice.org/69851
Reviewed-by: Luboš Luňák 
Tested-by: Jenkins
Reviewed-by: Xisco Faulí 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf121615.odt 
b/vcl/qa/cppunit/pdfexport/data/tdf121615.odt
new file mode 100644
index ..7d2a87cf0e40
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf121615.odt differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 78cec0a881d7..5c4b4a8c7141 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -29,6 +30,15 @@
 
 using namespace ::com::sun::star;
 
+static std::ostream& operator<<(std::ostream& rStrm, const Color& rColor)
+{
+rStrm << "Color: R:" << static_cast(rColor.GetRed())
+  << " G:" << static_cast(rColor.GetGreen())
+  << " B:" << static_cast(rColor.GetBlue())
+  << " A:" << static_cast(rColor.GetTransparency());
+return rStrm;
+}
+
 namespace
 {
 
@@ -90,6 +100,7 @@ public:
 void testTdf105954();
 void testTdf106702();
 void testTdf113143();
+void testTdf121615();
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
 CPPUNIT_TEST(testTdf106059);
@@ -120,6 +131,7 @@ public:
 CPPUNIT_TEST(testTdf105954);
 CPPUNIT_TEST(testTdf106702);
 CPPUNIT_TEST(testTdf113143);
+CPPUNIT_TEST(testTdf121615);
 CPPUNIT_TEST_SUITE_END();
 };
 
@@ -1465,6 +1477,52 @@ void PdfExportTest::testForcePoint71()
 topdf("forcepoint71.key");
 }
 
+void PdfExportTest::testTdf121615()
+{
+vcl::filter::PDFDocument aDocument;
+load("tdf121615.odt", aDocument);
+
+// The document has one page.
+std::vector aPages = aDocument.GetPages();
+CPPUNIT_ASSERT_EQUAL(static_cast(1), aPages.size());
+
+// Get access to the only image on the only page.
+vcl::filter::PDFObjectElement* pResources = 
aPages[0]->LookupObject("Resources");
+CPPUNIT_ASSERT(pResources);
+auto pXObjects = 
dynamic_cast(pResources->Lookup("XObject"));
+CPPUNIT_ASSERT(pXObjects);
+CPPUNIT_ASSERT_EQUAL(static_cast(1), pXObjects->GetItems().size());
+vcl::filter::PDFObjectElement* pXObject = 
pXObjects->LookupObject(pXObjects->GetItems().begin()->first);
+CPPUNIT_ASSERT(pXObject);
+vcl::filter::PDFStreamElement* pStream = pXObject->GetStream();
+CPPUNIT_ASSERT(pStream);
+SvMemoryStream& rObjectStream = pStream->GetMemory();
+
+// Load the embedded image.
+rObjectStream.Seek( 0 );
+GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
+Graphic aGraphic;
+sal_uInt16 format;
+ErrCode bResult = rFilter.ImportGraphic(aGraphic, OUString( "import" ), 
rObjectStream,
+GRFILTER_FORMAT_DONTKNOW, );
+CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
+
+// The image should be grayscale 8bit JPEG.
+sal_uInt16 jpegFormat = rFilter.GetImportFormatNumberForShortName( 
JPG_SHORTNAME );
+CPPUNIT_ASSERT( jpegFormat != GRFILTER_FORMAT_NOTFOUND );
+CPPUNIT_ASSERT_EQUAL( jpegFormat, format );
+BitmapEx aBitmap = aGraphic.GetBitmapEx();
+CPPUNIT_ASSERT_EQUAL( 200L, aBitmap.GetSizePixel().Width());
+CPPUNIT_ASSERT_EQUAL( 300L, aBitmap.GetSizePixel().Height());
+CPPUNIT_ASSERT_EQUAL( 8, int(aBitmap.GetBitCount()));
+// tdf#121615 was caused by broken handling of data width with 8bit color,
+// so the test image has some black in the bottomright corner, check it's 
there
+CPPUNIT_ASSERT_EQUAL( COL_WHITE, aBitmap.GetPixelColor( 0, 0 ));
+CPPUNIT_ASSERT_EQUAL( COL_WHITE, aBitmap.GetPixelColor( 0, 299 ));
+CPPUNIT_ASSERT_EQUAL( COL_WHITE, aBitmap.GetPixelColor( 199, 0 ));
+CPPUNIT_ASSERT_EQUAL( COL_BLACK, aBitmap.GetPixelColor( 199, 299 ));
+}
+
 

[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - vcl/qa vcl/source

2019-01-31 Thread Libreoffice Gerrit user
 vcl/source/gdi/dibtools.cxx |   14 --
 1 file changed, 12 insertions(+), 2 deletions(-)

New commits:
commit a7815e365bdb5544a0a9c63c6d730cf591f286d7
Author: Caolán McNamara 
AuthorDate: Wed Jan 30 13:36:01 2019 +
Commit: Caolán McNamara 
CommitDate: Thu Jan 31 12:25:08 2019 +0100

Resolves: tdf#122958 bmps with weird compression values that work in mso

Change-Id: Ie1887288cba7c1d56b807dbc9ddb886b9d20ff33
Reviewed-on: https://gerrit.libreoffice.org/67145
Tested-by: Jenkins
Tested-by: Xisco Faulí 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/vcl/qa/cppunit/graphicfilter/data/wmf/fail/CVE-2015-0848-1.wmf 
b/vcl/qa/cppunit/graphicfilter/data/wmf/pass/CVE-2015-0848-1.wmf
similarity index 100%
rename from vcl/qa/cppunit/graphicfilter/data/wmf/fail/CVE-2015-0848-1.wmf
rename to vcl/qa/cppunit/graphicfilter/data/wmf/pass/CVE-2015-0848-1.wmf
diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx
index de8615226492..4088d6287894 100644
--- a/vcl/source/gdi/dibtools.cxx
+++ b/vcl/source/gdi/dibtools.cxx
@@ -939,6 +939,18 @@ bool ImplReadDIBBody(SvStream& rIStm, Bitmap& rBmp, 
AlphaMask* pBmpAlpha, sal_uL
 }
 case BITFIELDS:
 break;
+default:
+// tdf#122958 invalid compression value used
+if (aHeader.nCompression & 0x000F)
+{
+// lets assume that there was an error in the generating 
application
+// and allow through as COMPRESS_NONE if the bottom byte is 0
+SAL_WARN( "vcl", "bad bmp compression scheme: " << 
aHeader.nCompression << ", rejecting bmp");
+return false;
+}
+else
+SAL_WARN( "vcl", "bad bmp compression scheme: " << 
aHeader.nCompression << ", assuming meant to be COMPRESS_NONE");
+SAL_FALLTHROUGH;
 case ZCOMPRESS:
 case COMPRESS_NONE:
 {
@@ -950,8 +962,6 @@ bool ImplReadDIBBody(SvStream& rIStm, Bitmap& rBmp, 
AlphaMask* pBmpAlpha, sal_uL
 return false;
 break;
 }
-default:
-return false;
 }
 
 const Size aSizePixel(aHeader.nWidth, aHeader.nHeight);
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - vcl/qa vcl/source

2018-08-07 Thread Libreoffice Gerrit user
 vcl/qa/cppunit/pdfexport/data/forcepoint71.key |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx |   16 +++-
 vcl/source/gdi/pdfwriter_impl.cxx  |   12 ++--
 3 files changed, 25 insertions(+), 3 deletions(-)

New commits:
commit b900b6ef5651273c8c9a23f388c03e6530870a81
Author: Caolán McNamara 
AuthorDate: Fri Aug 3 10:57:42 2018 +0100
Commit: Michael Stahl 
CommitDate: Tue Aug 7 17:42:32 2018 +0200

forcepoint#71 sanity check when copying pieces of imported pdf

Change-Id: I7e340e15c95cdfa8b185f61fad7e14bd00babf21
Reviewed-on: https://gerrit.libreoffice.org/58579
Tested-by: Jenkins
Reviewed-by: Michael Stahl 

diff --git a/vcl/qa/cppunit/pdfexport/data/forcepoint71.key 
b/vcl/qa/cppunit/pdfexport/data/forcepoint71.key
new file mode 100644
index ..716fe58480a0
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/forcepoint71.key 
differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 5d8214b898c3..78cec0a881d7 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -48,6 +48,7 @@ public:
 PdfExportTest();
 virtual void setUp() override;
 virtual void tearDown() override;
+void topdf(const OUString& rFile);
 void load(const OUString& rFile, vcl::filter::PDFDocument& rDocument);
 /// Tests that a pdf image is roundtripped back to PDF as a vector format.
 void testTdf106059();
@@ -60,6 +61,7 @@ public:
 void testTdf106206();
 /// Tests export of PDF images without reference XObjects.
 void testTdf106693();
+void testForcePoint71();
 void testTdf106972();
 void testTdf106972Pdf17();
 void testTdf107013();
@@ -96,6 +98,7 @@ public:
 CPPUNIT_TEST(testTdf105093);
 CPPUNIT_TEST(testTdf106206);
 CPPUNIT_TEST(testTdf106693);
+CPPUNIT_TEST(testForcePoint71);
 CPPUNIT_TEST(testTdf106972);
 CPPUNIT_TEST(testTdf106972Pdf17);
 CPPUNIT_TEST(testTdf107013);
@@ -171,7 +174,7 @@ void PdfExportTest::tearDown()
 
 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.
 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + rFile;
@@ -182,6 +185,11 @@ void PdfExportTest::load(const OUString& rFile, 
vcl::filter::PDFDocument& rDocum
 utl::MediaDescriptor aMediaDescriptor;
 aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
 xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
+}
+
+void PdfExportTest::load(const OUString& rFile, vcl::filter::PDFDocument& 
rDocument)
+{
+topdf(rFile);
 
 // Parse the export result.
 SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
@@ -1451,6 +1459,12 @@ void PdfExportTest::testTdf113143()
 CPPUNIT_ASSERT_LESS(nLarger, nSmaller);
 }
 
+void PdfExportTest::testForcePoint71()
+{
+// I just care it doesn't crash
+topdf("forcepoint71.key");
+}
+
 CPPUNIT_TEST_SUITE_REGISTRATION(PdfExportTest);
 
 }
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx 
b/vcl/source/gdi/pdfwriter_impl.cxx
index 21ca8d478e5b..acec33b4ec5c 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -9009,7 +9009,11 @@ sal_Int32 
PDFWriterImpl::copyExternalResource(SvMemoryStream& rDocBuffer, filter
 {
 // Copy the last part here, in the complex case.
 sal_uInt64 nDictEnd = rObject.GetDictionaryOffset() + 
rObject.GetDictionaryLength();
-aLine.append(static_cast(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(rDocBuffer.GetData()) + nCopyStart, nLen);
 }
 else
 // Can copy it as-is.
@@ -9072,7 +9076,11 @@ sal_Int32 
PDFWriterImpl::copyExternalResource(SvMemoryStream& rDocBuffer, filter
 {
 // Copy the last part here, in the complex case.
 sal_uInt64 nArrEnd = rObject.GetArrayOffset() + 
rObject.GetArrayLength();
-aLine.append(static_cast(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(rDocBuffer.GetData()) + nCopyStart, nLen);
 }
 else
 // Can copy it as-is.
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org

[Libreoffice-commits] core.git: Branch 'libreoffice-6-1' - vcl/qa vcl/source

2018-05-27 Thread Miklos Vajna
 vcl/qa/cppunit/pdfexport/data/tdf113143.odp |binary
 vcl/qa/cppunit/pdfexport/pdfexport.cxx  |  173 +---
 vcl/source/gdi/pdfextoutdevdata.cxx |6 
 3 files changed, 114 insertions(+), 65 deletions(-)

New commits:
commit 9f098d328439a8acece7d871020cf184e0e14930
Author: Miklos Vajna 
Date:   Thu May 24 17:29:13 2018 +0200

tdf#113143 PDF export: fix mis-scaled JPGs on Impress note pages

This is really similar to commit
4c2172a3e973bc6351107a3a1b554c77b40b75dd (tdf#106702 PDF export: fix
missing images from Writer headers/footers, 2018-05-22) just this one is
about the size of the output rectangle for JPG content, while the
previous problem was about the position of them.

Also extract PdfExportTest::exportAndParse() from the last two tests to
avoid duplication.

(cherry picked from commit 89dc667cebfec5315f0c0361e49d759e88458689)

Change-Id: I9812924d505e9fdaca2a95b4990e7aaa5e44fd7f
Reviewed-on: https://gerrit.libreoffice.org/54792
Tested-by: Jenkins 
Reviewed-by: Caolán McNamara 
Tested-by: Caolán McNamara 

diff --git a/vcl/qa/cppunit/pdfexport/data/tdf113143.odp 
b/vcl/qa/cppunit/pdfexport/data/tdf113143.odp
new file mode 100644
index ..5f8a1b10e2e5
Binary files /dev/null and b/vcl/qa/cppunit/pdfexport/data/tdf113143.odp differ
diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx 
b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
index 28803f0fd1b2..849e87b90f4a 100644
--- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx
+++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx
@@ -39,8 +39,13 @@ class PdfExportTest : public test::BootstrapFixture, public 
unotest::MacrosTest
 uno::Reference mxComponent;
 FPDF_PAGE mpPdfPage = nullptr;
 FPDF_DOCUMENT mpPdfDocument = nullptr;
+utl::TempFile maTempFile;
+SvMemoryStream maMemory;
+// Export the document as PDF, then parse it with PDFium.
+void exportAndParse(const OUString& rURL, const utl::MediaDescriptor& 
rDescriptor);
 
 public:
+PdfExportTest();
 virtual void setUp() override;
 virtual void tearDown() override;
 void load(const OUString& rFile, vcl::filter::PDFDocument& rDocument);
@@ -82,6 +87,7 @@ public:
 void testTdf109143();
 void testTdf105954();
 void testTdf106702();
+void testTdf113143();
 
 CPPUNIT_TEST_SUITE(PdfExportTest);
 CPPUNIT_TEST(testTdf106059);
@@ -110,9 +116,32 @@ public:
 CPPUNIT_TEST(testTdf109143);
 CPPUNIT_TEST(testTdf105954);
 CPPUNIT_TEST(testTdf106702);
+CPPUNIT_TEST(testTdf113143);
 CPPUNIT_TEST_SUITE_END();
 };
 
+PdfExportTest::PdfExportTest()
+{
+maTempFile.EnableKillingFile();
+}
+
+void PdfExportTest::exportAndParse(const OUString& rURL, const 
utl::MediaDescriptor& rDescriptor)
+{
+// Import the bugdoc and export as PDF.
+mxComponent = loadFromDesktop(rURL);
+CPPUNIT_ASSERT(mxComponent.is());
+
+uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
+xStorable->storeToURL(maTempFile.GetURL(), 
rDescriptor.getAsConstPropertyValueList());
+
+// Parse the export result with pdfium.
+SvFileStream aFile(maTempFile.GetURL(), StreamMode::READ);
+maMemory.WriteStream(aFile);
+mpPdfDocument
+= FPDF_LoadMemDocument(maMemory.GetData(), maMemory.GetSize(), 
/*password=*/nullptr);
+CPPUNIT_ASSERT(mpPdfDocument);
+}
+
 void PdfExportTest::setUp()
 {
 test::BootstrapFixture::setUp();
@@ -150,14 +179,12 @@ void PdfExportTest::load(const OUString& rFile, 
vcl::filter::PDFDocument& rDocum
 CPPUNIT_ASSERT(mxComponent.is());
 
 uno::Reference 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());
+xStorable->storeToURL(maTempFile.GetURL(), 
aMediaDescriptor.getAsConstPropertyValueList());
 
 // Parse the export result.
-SvFileStream aStream(aTempFile.GetURL(), StreamMode::READ);
+SvFileStream aStream(maTempFile.GetURL(), StreamMode::READ);
 CPPUNIT_ASSERT(rDocument.Read(aStream));
 }
 
@@ -169,8 +196,6 @@ void PdfExportTest::testTdf106059()
 CPPUNIT_ASSERT(mxComponent.is());
 
 uno::Reference xStorable(mxComponent, uno::UNO_QUERY);
-utl::TempFile aTempFile;
-aTempFile.EnableKillingFile();
 utl::MediaDescriptor aMediaDescriptor;
 aMediaDescriptor["FilterName"] <<= OUString("writer_pdf_Export");
 // Explicitly enable the usage of the reference XObject markup.
@@ -178,11 +203,11 @@ void PdfExportTest::testTdf106059()
 {"UseReferenceXObject", uno::Any(true) }
 }));
 aMediaDescriptor["FilterData"] <<= aFilterData;
-xStorable->storeToURL(aTempFile.GetURL(),