[Libreoffice-commits] core.git: include/vcl vcl/source xmlsecurity/source
Miklos Vajna (via logerrit)
logerrit at kemper.freedesktop.org
Wed Nov 25 08:13:59 UTC 2020
include/vcl/filter/PDFiumLibrary.hxx | 4 ++
vcl/source/pdf/PDFiumLibrary.cxx | 41 +++++++++++++++++++++++
xmlsecurity/source/helper/pdfsignaturehelper.cxx | 27 +++------------
3 files changed, 52 insertions(+), 20 deletions(-)
New commits:
commit 2c9f4c6a5e1a9ce5ef501c8f5a7f5cd421bf86f7
Author: Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Tue Nov 24 21:03:59 2020 +0100
Commit: Miklos Vajna <vmiklos at collabora.com>
CommitDate: Wed Nov 25 09:13:12 2020 +0100
pdfium: add sig getters: ByteRange, DocMDPPermission, Contents and SubFilter
Change-Id: Ieab577de92898568e27a879af1ca1bda170a307d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106554
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
diff --git a/include/vcl/filter/PDFiumLibrary.hxx b/include/vcl/filter/PDFiumLibrary.hxx
index 8d139889591a..e14c855780b7 100644
--- a/include/vcl/filter/PDFiumLibrary.hxx
+++ b/include/vcl/filter/PDFiumLibrary.hxx
@@ -242,6 +242,10 @@ public:
PDFiumSignature(FPDF_SIGNATURE pSignature);
FPDF_SIGNATURE getPointer() { return mpSignature; }
+ std::vector<int> getByteRange();
+ int getDocMDPPermission();
+ std::vector<unsigned char> getContents();
+ OString getSubFilter();
};
class VCL_DLLPUBLIC PDFiumDocument final
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx
index 3e9ae64dc950..a1d618e33105 100644
--- a/vcl/source/pdf/PDFiumLibrary.cxx
+++ b/vcl/source/pdf/PDFiumLibrary.cxx
@@ -196,6 +196,47 @@ PDFiumSignature::PDFiumSignature(FPDF_SIGNATURE pSignature)
{
}
+std::vector<int> PDFiumSignature::getByteRange()
+{
+ int nByteRangeLen = FPDFSignatureObj_GetByteRange(mpSignature, nullptr, 0);
+ std::vector<int> aByteRange(nByteRangeLen);
+ if (nByteRangeLen <= 0)
+ {
+ return aByteRange;
+ }
+
+ FPDFSignatureObj_GetByteRange(mpSignature, aByteRange.data(), aByteRange.size());
+ return aByteRange;
+}
+
+int PDFiumSignature::getDocMDPPermission()
+{
+ return FPDFSignatureObj_GetDocMDPPermission(mpSignature);
+}
+
+std::vector<unsigned char> PDFiumSignature::getContents()
+{
+ int nContentsLen = FPDFSignatureObj_GetContents(mpSignature, nullptr, 0);
+ std::vector<unsigned char> aContents(nContentsLen);
+ if (aContents.empty())
+ {
+ return aContents;
+ }
+
+ FPDFSignatureObj_GetContents(mpSignature, aContents.data(), aContents.size());
+ return aContents;
+}
+
+OString PDFiumSignature::getSubFilter()
+{
+ int nSubFilterLen = FPDFSignatureObj_GetSubFilter(mpSignature, nullptr, 0);
+ std::vector<char> aSubFilterBuf(nSubFilterLen);
+ FPDFSignatureObj_GetSubFilter(mpSignature, aSubFilterBuf.data(), aSubFilterBuf.size());
+ // Buffer is NUL-terminated.
+ OString aSubFilter(aSubFilterBuf.data(), aSubFilterBuf.size() - 1);
+ return aSubFilter;
+}
+
PDFiumDocument::PDFiumDocument(FPDF_DOCUMENT pPdfDocument)
: mpPdfDocument(pPdfDocument)
{
diff --git a/xmlsecurity/source/helper/pdfsignaturehelper.cxx b/xmlsecurity/source/helper/pdfsignaturehelper.cxx
index a9ab7a84546c..062dba819adf 100644
--- a/xmlsecurity/source/helper/pdfsignaturehelper.cxx
+++ b/xmlsecurity/source/helper/pdfsignaturehelper.cxx
@@ -132,16 +132,13 @@ struct Signature
void GetByteRangesFromPDF(std::unique_ptr<vcl::pdf::PDFiumSignature>& pSignature,
std::vector<std::pair<size_t, size_t>>& rByteRanges)
{
- int nByteRangeLen = FPDFSignatureObj_GetByteRange(pSignature->getPointer(), nullptr, 0);
- if (nByteRangeLen <= 0)
+ std::vector<int> aByteRange = pSignature->getByteRange();
+ if (aByteRange.empty())
{
SAL_WARN("xmlsecurity.helper", "GetByteRangesFromPDF: no byte ranges");
return;
}
- std::vector<int> aByteRange(nByteRangeLen);
- FPDFSignatureObj_GetByteRange(pSignature->getPointer(), aByteRange.data(), aByteRange.size());
-
size_t nByteRangeOffset = 0;
for (size_t i = 0; i < aByteRange.size(); ++i)
{
@@ -183,7 +180,7 @@ int GetMDPPerm(const std::vector<Signature>& rSignatures)
for (const auto& rSignature : rSignatures)
{
- int nPerm = FPDFSignatureObj_GetDocMDPPermission(rSignature.m_pSignature->getPointer());
+ int nPerm = rSignature.m_pSignature->getDocMDPPermission();
if (nPerm != 0)
{
return nPerm;
@@ -346,24 +343,14 @@ bool ValidateSignature(SvStream& rStream, const Signature& rSignature,
const std::set<unsigned int>& rSignatureEOFs,
const std::vector<unsigned int>& rTrailerEnds)
{
- int nContentsLen
- = FPDFSignatureObj_GetContents(rSignature.m_pSignature->getPointer(), nullptr, 0);
- if (nContentsLen <= 0)
+ std::vector<unsigned char> aContents = rSignature.m_pSignature->getContents();
+ if (aContents.empty())
{
SAL_WARN("xmlsecurity.helper", "ValidateSignature: no contents");
return false;
}
- std::vector<unsigned char> aContents(nContentsLen);
- FPDFSignatureObj_GetContents(rSignature.m_pSignature->getPointer(), aContents.data(),
- aContents.size());
-
- int nSubFilterLen
- = FPDFSignatureObj_GetSubFilter(rSignature.m_pSignature->getPointer(), nullptr, 0);
- std::vector<char> aSubFilterBuf(nSubFilterLen);
- FPDFSignatureObj_GetSubFilter(rSignature.m_pSignature->getPointer(), aSubFilterBuf.data(),
- aSubFilterBuf.size());
- // Buffer is NUL-terminated.
- OString aSubFilter(aSubFilterBuf.data(), aSubFilterBuf.size() - 1);
+
+ OString aSubFilter = rSignature.m_pSignature->getSubFilter();
const bool bNonDetached = aSubFilter == "adbe.pkcs7.sha1";
if (aSubFilter.isEmpty()
More information about the Libreoffice-commits
mailing list