2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-11-12 15:56:28 +00:00

Improve memory safety of finding PDF header

This commit is contained in:
Jay Berkenbilt 2012-12-25 15:13:44 -05:00
parent 7f84239cad
commit b4e7d6ed32

View File

@ -222,9 +222,11 @@ QPDF::parse(char const* password)
this->provided_password = password; this->provided_password = password;
} }
// Find the header anywhere in the first 1024 bytes of the file. // Find the header anywhere in the first 1024 bytes of the file,
char buffer[1044]; // plus add a little extra space for the header itself.
this->file->read(buffer, sizeof(buffer)); char buffer[1045];
memset(buffer, '\0', sizeof(buffer));
this->file->read(buffer, sizeof(buffer) - 1);
std::string line(buffer); std::string line(buffer);
PCRE::Match m1 = header_re.match(line.c_str()); PCRE::Match m1 = header_re.match(line.c_str());
if (m1) if (m1)