diff options
author | Albert Astals Cid <aacid@kde.org> | 2020-10-07 00:08:44 +0200 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2020-10-07 00:10:36 +0200 |
commit | d4be954367cb1ff6f372b74bbd8f186238ec86fc (patch) | |
tree | fec79fc3bc9d3bbd0a8c7d081edd30abb213c7d2 /cpp | |
parent | 4fee2408dad1a2e872810eadec89cb07dc982312 (diff) |
cpp: Fix crashes in embedded file handling on broken files
Fixes #966
Diffstat (limited to 'cpp')
-rw-r--r-- | cpp/poppler-embedded-file.cpp | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/cpp/poppler-embedded-file.cpp b/cpp/poppler-embedded-file.cpp index 4ce03950..ab873de2 100644 --- a/cpp/poppler-embedded-file.cpp +++ b/cpp/poppler-embedded-file.cpp @@ -1,7 +1,7 @@ /* * Copyright (C) 2009-2011, Pino Toscano <pino@kde.org> * Copyright (C) 2016 Jakub Alba <jakubalba@gmail.com> - * Copyright (C) 2018 Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2018, 2020 Albert Astals Cid <aacid@kde.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -96,7 +96,8 @@ ustring embedded_file::description() const */ int embedded_file::size() const { - return d->file_spec->getEmbeddedFile()->size(); + const EmbFile *ef = d->file_spec->getEmbeddedFile(); + return ef ? ef->size() : -1; } /** @@ -105,7 +106,8 @@ int embedded_file::size() const */ time_type embedded_file::modification_date() const { - const GooString *goo = d->file_spec->getEmbeddedFile()->modDate(); + const EmbFile *ef = d->file_spec->getEmbeddedFile(); + const GooString *goo = ef ? ef->modDate() : nullptr; return goo ? dateStringToTime(goo) : time_type(-1); } @@ -115,7 +117,8 @@ time_type embedded_file::modification_date() const */ time_type embedded_file::creation_date() const { - const GooString *goo = d->file_spec->getEmbeddedFile()->createDate(); + const EmbFile *ef = d->file_spec->getEmbeddedFile(); + const GooString *goo = ef ? ef->createDate() : nullptr; return goo ? dateStringToTime(goo) : time_type(-1); } @@ -124,7 +127,8 @@ time_type embedded_file::creation_date() const */ byte_array embedded_file::checksum() const { - const GooString *cs = d->file_spec->getEmbeddedFile()->checksum(); + const EmbFile *ef = d->file_spec->getEmbeddedFile(); + const GooString *cs = ef ? ef->checksum() : nullptr; if (!cs) { return byte_array(); } @@ -141,7 +145,8 @@ byte_array embedded_file::checksum() const */ std::string embedded_file::mime_type() const { - const GooString *goo = d->file_spec->getEmbeddedFile()->mimeType(); + const EmbFile *ef = d->file_spec->getEmbeddedFile(); + const GooString *goo = ef ? ef->mimeType() : nullptr; return goo ? std::string(goo->c_str()) : std::string(); } @@ -155,7 +160,8 @@ byte_array embedded_file::data() const if (!is_valid()) { return byte_array(); } - Stream *stream = d->file_spec->getEmbeddedFile()->stream(); + EmbFile *ef = d->file_spec->getEmbeddedFile(); + Stream *stream = ef ? ef->stream() : nullptr; if (!stream) { return byte_array(); } |