diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-09-04 17:17:48 +0200 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2020-09-10 20:54:16 +0200 |
commit | 60e0c6fd03ac26df00877efea65537828e43583c (patch) | |
tree | 770fdbb3f78f000af66c640c4b43d7fe1d160acd /vcl | |
parent | 434d611e22c4fe76a11d2de26b9f185bb04e5ad3 (diff) |
xmlsecurity: pdf incremental updates that are non-commenting are invalid
I.e. it's OK to add incremental updates for annotation/commenting
purposes and that doesn't invalite existing signatures. Everything else
does.
(cherry picked from commit 61834cd574568613f0b0a2ee099a60fa5a8d9804)
[ Also disable a pdfium assert on Windows, only on this branch, where it
fails during CppunitTest_xmlsecurity_pdfsigning for reasons unclear to
me. ]
Conflicts:
include/vcl/filter/PDFiumLibrary.hxx
vcl/source/pdf/PDFiumLibrary.cxx
Change-Id: I4607c242b3c6f6b01517b02407e9e7a095e2e069
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/102325
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 604807524bf9..861b7dda0acb 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -15,6 +15,10 @@ #include <vcl/filter/PDFiumLibrary.hxx> #include <fpdf_doc.h> +#include <vcl/bitmap.hxx> + +#include <bitmapwriteaccess.hxx> + namespace vcl::pdf { PDFium::PDFium() @@ -29,6 +33,58 @@ PDFium::PDFium() PDFium::~PDFium() { FPDF_DestroyLibrary(); } +PDFiumDocument::PDFiumDocument(FPDF_DOCUMENT pPdfDocument) + : mpPdfDocument(pPdfDocument) +{ +} + +PDFiumDocument::~PDFiumDocument() +{ + if (mpPdfDocument) + FPDF_CloseDocument(mpPdfDocument); +} + +std::unique_ptr<PDFiumPage> PDFiumDocument::openPage(int nIndex) +{ + std::unique_ptr<PDFiumPage> pPDFiumPage; + FPDF_PAGE pPage = FPDF_LoadPage(mpPdfDocument, nIndex); + if (pPage) + { + pPDFiumPage = std::make_unique<PDFiumPage>(pPage); + } + return pPDFiumPage; +} + +int PDFiumDocument::getPageCount() { return FPDF_GetPageCount(mpPdfDocument); } + +BitmapChecksum PDFiumPage::getChecksum() +{ + size_t nPageWidth = FPDF_GetPageWidth(mpPage); + size_t nPageHeight = FPDF_GetPageHeight(mpPage); + FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1); + if (!pPdfBitmap) + { + return 0; + } + + // Intentionally not using FPDF_ANNOT here, annotations/commenting is OK to not affect the + // checksum, signature verification wants this. + FPDF_RenderPageBitmap(pPdfBitmap, mpPage, /*start_x=*/0, /*start_y=*/0, nPageWidth, nPageHeight, + /*rotate=*/0, /*flags=*/0); + Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24); + { + BitmapScopedWriteAccess pWriteAccess(aBitmap); + const auto pPdfBuffer = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap)); + const int nStride = FPDFBitmap_GetStride(pPdfBitmap); + for (size_t nRow = 0; nRow < nPageHeight; ++nRow) + { + ConstScanline pPdfLine = pPdfBuffer + (nStride * nRow); + pWriteAccess->CopyScanline(nRow, pPdfLine, ScanlineFormat::N32BitTcBgra, nStride); + } + } + return aBitmap.GetChecksum(); +} + } // end vcl::pdf #endif // HAVE_FEATURE_PDFIUM |