Kaydet (Commit) c4cb8b5d authored tarafından Miklos Vajna's avatar Miklos Vajna

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/31500Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst b1f91c0a
......@@ -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)
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment