diff options
author | Jay Berkenbilt <ejb@ql.org> | 2021-01-06 15:49:10 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2021-01-06 16:11:34 +0100 |
commit | 6fe7b704c7dfb517e4de20fb25536fab1de83d56 (patch) | |
tree | 5c2c15a93944ba01dc609197dfad1d7a823eae51 /libqpdf | |
parent | 2c078337fa77e26554be817ead3cd080f31f6e9b (diff) | |
download | qpdf-6fe7b704c7dfb517e4de20fb25536fab1de83d56.tar.zst |
Warn rather than segv on access after closing input source (fixes #495)
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QPDF.cc | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 29508a40..34f15706 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -45,6 +45,51 @@ static char const* EMPTY_PDF = "110\n" "%%EOF\n"; +class InvalidInputSource: public InputSource +{ + public: + virtual ~InvalidInputSource() = default; + virtual qpdf_offset_t findAndSkipNextEOL() override + { + throwException(); + return 0; + } + virtual std::string const& getName() const override + { + static std::string name("closed input source"); + return name; + } + virtual qpdf_offset_t tell() override + { + throwException(); + return 0; + } + virtual void seek(qpdf_offset_t offset, int whence) override + { + throwException(); + } + virtual void rewind() override + { + throwException(); + } + virtual size_t read(char* buffer, size_t length) override + { + throwException(); + return 0; + } + virtual void unreadCh(char ch) override + { + throwException(); + } + + private: + void throwException() + { + throw std::runtime_error( + "QPDF operation attempted after closing input source"); + } +}; + QPDF::ForeignStreamData::ForeignStreamData( PointerHolder<EncryptionParameters> encp, PointerHolder<InputSource> file, @@ -254,7 +299,7 @@ QPDF::processInputSource(PointerHolder<InputSource> source, void QPDF::closeInputSource() { - this->m->file = 0; + this->m->file = new InvalidInputSource(); } void |