Commit b4e7d6ed32c821ff51ddf4debe691ac06a3938ed
1 parent
7f84239c
Improve memory safety of finding PDF header
Showing
1 changed file
with
5 additions
and
3 deletions
libqpdf/QPDF.cc
| ... | ... | @@ -222,9 +222,11 @@ QPDF::parse(char const* password) |
| 222 | 222 | this->provided_password = password; |
| 223 | 223 | } |
| 224 | 224 | |
| 225 | - // Find the header anywhere in the first 1024 bytes of the file. | |
| 226 | - char buffer[1044]; | |
| 227 | - this->file->read(buffer, sizeof(buffer)); | |
| 225 | + // Find the header anywhere in the first 1024 bytes of the file, | |
| 226 | + // plus add a little extra space for the header itself. | |
| 227 | + char buffer[1045]; | |
| 228 | + memset(buffer, '\0', sizeof(buffer)); | |
| 229 | + this->file->read(buffer, sizeof(buffer) - 1); | |
| 228 | 230 | std::string line(buffer); |
| 229 | 231 | PCRE::Match m1 = header_re.match(line.c_str()); |
| 230 | 232 | if (m1) | ... | ... |