From 8657c6f00489b5c26fc0c00f2fc91c5682acbe95 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Wed, 18 Jul 2012 09:50:05 -0400 Subject: Prevent seeking before beginning of BufferInputSource --- libqpdf/QPDF.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'libqpdf/QPDF.cc') diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc index 4a764964..1a8a689d 100644 --- a/libqpdf/QPDF.cc +++ b/libqpdf/QPDF.cc @@ -231,6 +231,10 @@ QPDF::BufferInputSource::~BufferInputSource() qpdf_offset_t QPDF::BufferInputSource::findAndSkipNextEOL() { + if (this->cur_offset < 0) + { + throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); + } qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize(); if (this->cur_offset >= end_pos) { @@ -301,6 +305,12 @@ QPDF::BufferInputSource::seek(qpdf_offset_t offset, int whence) "INTERNAL ERROR: invalid argument to BufferInputSource::seek"); break; } + + if (this->cur_offset < 0) + { + throw std::runtime_error( + this->description + ": seek before beginning of buffer"); + } } void @@ -312,6 +322,10 @@ QPDF::BufferInputSource::rewind() size_t QPDF::BufferInputSource::read(char* buffer, size_t length) { + if (this->cur_offset < 0) + { + throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); + } qpdf_offset_t end_pos = (qpdf_offset_t) this->buf->getSize(); if (this->cur_offset >= end_pos) { -- cgit v1.2.3-54-g00ecf