diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-12-01 17:31:41 +0100 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2016-12-01 19:35:22 +0000 |
commit | c4cb8b5d1460bbf080366817d26c08685490d541 (patch) | |
tree | 2752c52fb640323f99ac85fae9c126df72840eca /xmlsecurity | |
parent | b1f91c0a04dd751d4f6cb8352bcbaa16c9388285 (diff) |
xmlsecurity PDF verify: avoid seeking before the start of the stream
Happened when the doc was smaller than 1024 bytes.
Change-Id: Ie5eea5905a09722e7958495d26e6c78ee234d3ba
Reviewed-on: https://gerrit.libreoffice.org/31500
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'xmlsecurity')
-rw-r--r-- | xmlsecurity/qa/unit/pdfsigning/data/small.pdf | bin | 0 -> 834 bytes | |||
-rw-r--r-- | xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx | 2 | ||||
-rw-r--r-- | xmlsecurity/source/pdfio/pdfdocument.cxx | 6 |
3 files changed, 7 insertions, 1 deletions
diff --git a/xmlsecurity/qa/unit/pdfsigning/data/small.pdf b/xmlsecurity/qa/unit/pdfsigning/data/small.pdf Binary files differnew file mode 100644 index 000000000000..60675454f9d3 --- /dev/null +++ b/xmlsecurity/qa/unit/pdfsigning/data/small.pdf diff --git a/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx b/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx index 6e5e476532ee..fae2a71d38f7 100644 --- a/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx +++ b/xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx @@ -394,6 +394,8 @@ void PDFSigningTest::testTokenize() OUStringLiteral("name-bracket.pdf"), // %%EOF at the end wasn't followed by a newline. OUStringLiteral("noeol.pdf"), + // File that's intentionally smaller than 1024 bytes. + OUStringLiteral("small.pdf"), }; for (const auto& rName : aNames) diff --git a/xmlsecurity/source/pdfio/pdfdocument.cxx b/xmlsecurity/source/pdfio/pdfdocument.cxx index 3adf02562cf3..fd364779bca9 100644 --- a/xmlsecurity/source/pdfio/pdfdocument.cxx +++ b/xmlsecurity/source/pdfio/pdfdocument.cxx @@ -1392,7 +1392,11 @@ size_t PDFDocument::FindStartXRef(SvStream& rStream) // Find the "startxref" token, somewhere near the end of the document. std::vector<char> aBuf(1024); rStream.Seek(STREAM_SEEK_TO_END); - rStream.SeekRel(static_cast<sal_Int64>(-1) * aBuf.size()); + if (rStream.Tell() > aBuf.size()) + rStream.SeekRel(static_cast<sal_Int64>(-1) * aBuf.size()); + else + // The document is really short, then just read it from the start. + rStream.Seek(0); size_t nBeforePeek = rStream.Tell(); size_t nSize = rStream.ReadBytes(aBuf.data(), aBuf.size()); rStream.Seek(nBeforePeek); |