From 78741a33f3144f1f10e4b0e05addf3b3b408bb9c Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Wed, 23 Sep 2020 11:41:05 +0200 Subject: [PATCH] Convert attribute value to UTF-8 when passing it to libxml2 Using toUtf8, requiring the OUString to actually contain well-formed data, but which is likely OK for this test-code--only function, and is also what similar dumpAsXml functions e.g. in editeng/source/items/textitem.cxx already use. This appears to have been broken ever since the code's introduction in 553f10c71a2cc92f5f5890e24948f5277e3d2758 "add dumpAsXml() to more pool items", and it would typically only have written the leading zero or one (depending on the architecture's endianness) characters. (I ran across it on big-endian s390x, where CppunitTest_sd_tiledrendering SdTiledRenderingTest::testTdf104405 failed because of > Entity: line 2: parser error : Input is not proper UTF-8, indicate encoding ! > Bytes: 0xCF 0x22 0x2F 0x3E > ation=""/> & rxInputStream, diff --git a/svl/source/items/poolitem.cxx b/svl/source/items/poolitem.cxx index c5e09ddf904..25f2720b547 100644 --- a/svl/source/items/poolitem.cxx +++ b/svl/source/items/poolitem.cxx @@ -549,7 +549,8 @@ void SfxPoolItem::dumpAsXml(xmlTextWriterPtr pWriter) const OUString rText; IntlWrapper aIntlWrapper(SvtSysLocale().GetUILanguageTag()); if (GetPresentation( SfxItemPresentation::Complete, MapUnit::Map100thMM, MapUnit::Map100thMM, rText, aIntlWrapper)) - xmlTextWriterWriteAttribute(pWriter, BAD_CAST("presentation"), BAD_CAST(rText.getStr())); + xmlTextWriterWriteAttribute( + pWriter, BAD_CAST("presentation"), BAD_CAST(rText.toUtf8().getStr())); xmlTextWriterEndElement(pWriter); } diff --git a/svl/source/misc/msodocumentlockfile.cxx b/svl/source/misc/msodocumentlockfile.cxx index 9650db03999..0c857ffb53e 100644 --- a/svl/source/misc/msodocumentlockfile.cxx +++ b/svl/source/misc/msodocumentlockfile.cxx @@ -228,8 +228,16 @@ LockFileEntry MSODocumentLockFile::GetLockData() nUTF16Len = *++pBuf; // use Excel/PowerPoint position if (nUTF16Len > 0 && nUTF16Len <= 52) // skip wrong format - aResult[LockFileComponent::OOOUSERNAME] - = OUString(reinterpret_cast(pBuf + 2), nUTF16Len); + { + OUStringBuffer str(nUTF16Len); + sal_uInt8 const* p = reinterpret_cast(pBuf + 2); + for (int i = 0; i != nUTF16Len; ++i) + { + str.append(sal_Unicode(p[0] | (sal_uInt32(p[1]) << 8))); + p += 2; + } + aResult[LockFileComponent::OOOUSERNAME] = str.makeStringAndClear(); + } } } return aResult; diff --git a/vcl/qa/cppunit/pdfexport/pdfexport.cxx b/vcl/qa/cppunit/pdfexport/pdfexport.cxx index fe402b4ed8b..e6fbce7a19e 100644 --- a/vcl/qa/cppunit/pdfexport/pdfexport.cxx +++ b/vcl/qa/cppunit/pdfexport/pdfexport.cxx @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -1720,6 +1721,12 @@ void PdfExportTest::testTdf115262() unsigned long nTextSize = FPDFTextObj_GetText(pPageObject, pTextPage, nullptr, 0); std::vector aText(nTextSize); FPDFTextObj_GetText(pPageObject, pTextPage, aText.data(), nTextSize); +#if defined OSL_BIGENDIAN + // The data returned by FPDFTextObj_GetText is documented to always be UTF-16LE: + for (auto & j: aText) { + j = OSL_SWAPWORD(j); + } +#endif OUString sText(aText.data(), nTextSize / 2 - 1); if (sText == "400") nRowTop = fTop; @@ -1755,6 +1762,12 @@ void PdfExportTest::testTdf121962() unsigned long nTextSize = FPDFTextObj_GetText(pPageObject, pTextPage, nullptr, 0); std::vector aText(nTextSize); FPDFTextObj_GetText(pPageObject, pTextPage, aText.data(), nTextSize); +#if defined OSL_BIGENDIAN + // The data returned by FPDFTextObj_GetText is documented to always be UTF-16LE: + for (auto & j: aText) { + j = OSL_SWAPWORD(j); + } +#endif OUString sText(aText.data(), nTextSize / 2 - 1); CPPUNIT_ASSERT(sText != "** Expression is faulty **"); } @@ -1787,6 +1800,12 @@ void PdfExportTest::testTdf115967() unsigned long nTextSize = FPDFTextObj_GetText(pPageObject, pTextPage, nullptr, 2); std::vector aText(nTextSize); FPDFTextObj_GetText(pPageObject, pTextPage, aText.data(), nTextSize); +#if defined OSL_BIGENDIAN + // The data returned by FPDFTextObj_GetText is documented to always be UTF-16LE: + for (auto & j: aText) { + j = OSL_SWAPWORD(j); + } +#endif OUString sChar(aText.data(), nTextSize / 2 - 1); sText += sChar.trim(); } diff --git a/vcl/source/filter/png/PngImageReader.cxx b/vcl/source/filter/png/PngImageReader.cxx index 958cae34eb4..6e9f3825fac 100644 --- a/vcl/source/filter/png/PngImageReader.cxx +++ b/vcl/source/filter/png/PngImageReader.cxx @@ -188,6 +188,8 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool bUseBitmap32) for (auto& rRow : aRows) rRow.resize(aRowSizeBytes, 0); + auto const alphaFirst = (eFormat == ScanlineFormat::N32BitTcAbgr + || eFormat == ScanlineFormat::N32BitTcArgb); for (int pass = 0; pass < nNumberOfPasses; pass++) { for (png_uint_32 y = 0; y < height; y++) @@ -199,10 +201,17 @@ bool reader(SvStream& rStream, BitmapEx& rBitmapEx, bool bUseBitmap32) for (size_t i = 0; i < aRowSizeBytes; i += 4) { sal_Int8 alpha = pRow[i + 3]; + if (alphaFirst) + { + pScanline[iColor++] = alpha; + } pScanline[iColor++] = vcl::bitmap::premultiply(pRow[i + 0], alpha); pScanline[iColor++] = vcl::bitmap::premultiply(pRow[i + 1], alpha); pScanline[iColor++] = vcl::bitmap::premultiply(pRow[i + 2], alpha); - pScanline[iColor++] = alpha; + if (!alphaFirst) + { + pScanline[iColor++] = alpha; + } } } } -- 2.30.2