summaryrefslogtreecommitdiffstats
path: root/libqpdf/QPDF.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2012-12-25 21:13:44 +0100
committerJay Berkenbilt <ejb@ql.org>2012-12-25 21:13:44 +0100
commitb4e7d6ed32c821ff51ddf4debe691ac06a3938ed (patch)
treea6f195a14cdac778c4352015d716fc1c92666482 /libqpdf/QPDF.cc
parent7f84239cad2ec58166245394e56a4647085e025e (diff)
downloadqpdf-b4e7d6ed32c821ff51ddf4debe691ac06a3938ed.tar.zst
Improve memory safety of finding PDF header
Diffstat (limited to 'libqpdf/QPDF.cc')
-rw-r--r--libqpdf/QPDF.cc8
1 files changed, 5 insertions, 3 deletions
diff --git a/libqpdf/QPDF.cc b/libqpdf/QPDF.cc
index ba96cb64..777fb837 100644
--- a/libqpdf/QPDF.cc
+++ b/libqpdf/QPDF.cc
@@ -222,9 +222,11 @@ QPDF::parse(char const* password)
this->provided_password = password;
}
- // Find the header anywhere in the first 1024 bytes of the file.
- char buffer[1044];
- this->file->read(buffer, sizeof(buffer));
+ // Find the header anywhere in the first 1024 bytes of the file,
+ // plus add a little extra space for the header itself.
+ char buffer[1045];
+ memset(buffer, '\0', sizeof(buffer));
+ this->file->read(buffer, sizeof(buffer) - 1);
std::string line(buffer);
PCRE::Match m1 = header_re.match(line.c_str());
if (m1)