vcl/source/pdf/PDFiumLibrary.cxx |   22 ++++++++++++++++------
 1 file changed, 16 insertions(+), 6 deletions(-)

New commits:
commit 7346edfee5c2391f828b09baa3dc94d5834d3cd8
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Wed Sep 23 12:23:37 2020 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Wed Sep 23 14:04:07 2020 +0200

    These PDFium-provided string sizes must always be multiples of 2
    
    ...as both FPDFTextObj_GetText (see
    workdir/UnpackedTarball/pdfium/public/fpdf_edit.h) and 
FPDFAnnot_GetStringValue
    (see workdir/UnpackedTarball/pdfium/public/fpdf_annot.h) return UTF-16LE 
strings
    but measure their sizes in bytes.  So half the returned sizes early, which
    avoids over-allocating double sized sal_Unicode arrays, and is a 
prerequisite
    for a follow-up endianness-issue fix.
    
    Change-Id: I4565819044a44ca9435f9bffdea083d5807cfe4d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103242
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index f8d5b79c8f6f..024665efc7e2 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -12,6 +12,8 @@
 
 #if HAVE_FEATURE_PDFIUM
 
+#include <cassert>
+
 #include <vcl/filter/PDFiumLibrary.hxx>
 #include <fpdf_annot.h>
 #include <fpdf_edit.h>
@@ -224,13 +226,17 @@ OUString 
PDFiumPageObject::getText(std::unique_ptr<PDFiumTextPage> const& pTextP
 {
     OUString sReturnText;
 
-    const int nBytes = FPDFTextObj_GetText(mpPageObject, 
pTextPage->getPointer(), nullptr, 0);
+    int nBytes = FPDFTextObj_GetText(mpPageObject, pTextPage->getPointer(), 
nullptr, 0);
+    assert(nBytes % 2 == 0);
+    nBytes /= 2;
 
     std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nBytes]);
 
-    const int nActualBytes
-        = FPDFTextObj_GetText(mpPageObject, pTextPage->getPointer(), 
pText.get(), nBytes);
-    if (nActualBytes > 2)
+    int nActualBytes
+        = FPDFTextObj_GetText(mpPageObject, pTextPage->getPointer(), 
pText.get(), nBytes * 2);
+    assert(nActualBytes % 2 == 0);
+    nActualBytes /= 2;
+    if (nActualBytes > 1)
         sReturnText = OUString(pText.get());
 
     return sReturnText;
@@ -416,11 +422,15 @@ OUString PDFiumAnnotation::getString(OString const& rKey)
 {
     OUString rString;
     unsigned long nSize = FPDFAnnot_GetStringValue(mpAnnotation, 
rKey.getStr(), nullptr, 0);
-    if (nSize > 2)
+    assert(nSize % 2 == 0);
+    nSize /= 2;
+    if (nSize > 1)
     {
         std::unique_ptr<sal_Unicode[]> pText(new sal_Unicode[nSize]);
         unsigned long nStringSize = FPDFAnnot_GetStringValue(
-            mpAnnotation, rKey.getStr(), 
reinterpret_cast<FPDF_WCHAR*>(pText.get()), nSize);
+            mpAnnotation, rKey.getStr(), 
reinterpret_cast<FPDF_WCHAR*>(pText.get()), nSize * 2);
+        assert(nStringSize % 2 == 0);
+        nStringSize /= 2;
         if (nStringSize > 0)
             rString = OUString(pText.get());
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to