Commit 92b692466f7a4dbf4e51e6a77713c029a3e18ab1
1 parent
b20f0519
Remove remaining incorrect assert calls from implementation
Showing
10 changed files
with
25 additions
and
20 deletions
README-maintainer
| ... | ... | @@ -123,6 +123,12 @@ CODING RULES |
| 123 | 123 | "Code Formatting" section in manual/contributing.rst for details. |
| 124 | 124 | See also "CODE FORMATTING" below. |
| 125 | 125 | |
| 126 | +* Do not use assert in non-test code for any purpose other than as a | |
| 127 | + sanity check during development that would be safe to remove in | |
| 128 | + production. assert is for strong invariant checking. When developing | |
| 129 | + and using assert for that purpose, make sure to use the Debug | |
| 130 | + configuration since assert is disabled in other configurations. | |
| 131 | + | |
| 126 | 132 | * In a source file, include the header file that declares the source |
| 127 | 133 | class first followed by a blank line. If a config file is needed |
| 128 | 134 | first, put a blank line between that and the header followed by | ... | ... |
libqpdf/AES_PDF_native.cc
libqpdf/Pl_AES_PDF.cc
| ... | ... | @@ -3,7 +3,6 @@ |
| 3 | 3 | #include <qpdf/QIntC.hh> |
| 4 | 4 | #include <qpdf/QPDFCryptoProvider.hh> |
| 5 | 5 | #include <qpdf/QUtil.hh> |
| 6 | -#include <assert.h> | |
| 7 | 6 | #include <cstring> |
| 8 | 7 | #include <stdexcept> |
| 9 | 8 | #include <stdlib.h> |
| ... | ... | @@ -115,7 +114,10 @@ Pl_AES_PDF::finish() |
| 115 | 114 | // encountered files for which the output is not a |
| 116 | 115 | // multiple of the block size. In this case, pad with |
| 117 | 116 | // zeroes and hope for the best. |
| 118 | - assert(this->buf_size > this->offset); | |
| 117 | + if (this->offset >= this->buf_size) { | |
| 118 | + throw std::logic_error("buffer overflow in AES encryption" | |
| 119 | + " pipeline"); | |
| 120 | + } | |
| 119 | 121 | std::memset( |
| 120 | 122 | this->inbuf + this->offset, 0, this->buf_size - this->offset); |
| 121 | 123 | this->offset = this->buf_size; |
| ... | ... | @@ -147,7 +149,10 @@ Pl_AES_PDF::initializeVector() |
| 147 | 149 | void |
| 148 | 150 | Pl_AES_PDF::flush(bool strip_padding) |
| 149 | 151 | { |
| 150 | - assert(this->offset == this->buf_size); | |
| 152 | + if (this->offset != this->buf_size) { | |
| 153 | + throw std::logic_error( | |
| 154 | + "AES pipeline: flush called when buffer was not full"); | |
| 155 | + } | |
| 151 | 156 | |
| 152 | 157 | if (first) { |
| 153 | 158 | first = false; | ... | ... |
libqpdf/Pl_Buffer.cc
libqpdf/Pl_LZWDecoder.cc
libqpdf/QPDFWriter.cc
| ... | ... | @@ -11,18 +11,17 @@ |
| 11 | 11 | #include <qpdf/Pl_PNGFilter.hh> |
| 12 | 12 | #include <qpdf/Pl_RC4.hh> |
| 13 | 13 | #include <qpdf/Pl_StdioFile.hh> |
| 14 | -#include <qpdf/QTC.hh> | |
| 15 | -#include <qpdf/QUtil.hh> | |
| 16 | -#include <qpdf/RC4.hh> | |
| 17 | -#include <assert.h> | |
| 18 | - | |
| 19 | 14 | #include <qpdf/QIntC.hh> |
| 20 | 15 | #include <qpdf/QPDF.hh> |
| 21 | 16 | #include <qpdf/QPDFObjectHandle.hh> |
| 22 | 17 | #include <qpdf/QPDF_Name.hh> |
| 23 | 18 | #include <qpdf/QPDF_String.hh> |
| 19 | +#include <qpdf/QTC.hh> | |
| 20 | +#include <qpdf/QUtil.hh> | |
| 21 | +#include <qpdf/RC4.hh> | |
| 24 | 22 | |
| 25 | 23 | #include <algorithm> |
| 24 | +#include <cassert> | |
| 26 | 25 | #include <stdlib.h> |
| 27 | 26 | |
| 28 | 27 | QPDFWriter::Members::Members(QPDF& pdf) : | ... | ... |
libqpdf/QPDF_encryption.cc
libqpdf/QPDF_linearization.cc
| ... | ... | @@ -12,7 +12,6 @@ |
| 12 | 12 | #include <qpdf/QUtil.hh> |
| 13 | 13 | |
| 14 | 14 | #include <algorithm> |
| 15 | -#include <assert.h> | |
| 16 | 15 | #include <iostream> |
| 17 | 16 | #include <math.h> |
| 18 | 17 | #include <string.h> |
| ... | ... | @@ -172,9 +171,6 @@ QPDF::readLinearizationData() |
| 172 | 171 | // This function throws an exception (which is trapped by |
| 173 | 172 | // checkLinearization()) for any errors that prevent loading. |
| 174 | 173 | |
| 175 | - // Hint table parsing code needs at least 32 bits in a long. | |
| 176 | - assert(sizeof(long) >= 4); | |
| 177 | - | |
| 178 | 174 | if (!isLinearized()) { |
| 179 | 175 | throw std::logic_error("called readLinearizationData for file" |
| 180 | 176 | " that is not linearized"); | ... | ... |
libqpdf/QPDF_optimization.cc
libqpdf/QPDF_pages.cc
| 1 | 1 | #include <qpdf/QPDF.hh> |
| 2 | 2 | |
| 3 | -#include <assert.h> | |
| 4 | - | |
| 5 | 3 | #include <qpdf/QPDFExc.hh> |
| 6 | 4 | #include <qpdf/QTC.hh> |
| 7 | 5 | #include <qpdf/QUtil.hh> |
| ... | ... | @@ -233,6 +231,11 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) |
| 233 | 231 | QTC::TC("qpdf", "QPDF insert indirect page"); |
| 234 | 232 | } |
| 235 | 233 | |
| 234 | + if ((pos < 0) || (QIntC::to_size(pos) > this->m->all_pages.size())) { | |
| 235 | + throw std::runtime_error( | |
| 236 | + "QPDF::insertPage called with pos out of range"); | |
| 237 | + } | |
| 238 | + | |
| 236 | 239 | QTC::TC( |
| 237 | 240 | "qpdf", |
| 238 | 241 | "QPDF insert page", |
| ... | ... | @@ -249,7 +252,6 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) |
| 249 | 252 | |
| 250 | 253 | QPDFObjectHandle pages = getRoot().getKey("/Pages"); |
| 251 | 254 | QPDFObjectHandle kids = pages.getKey("/Kids"); |
| 252 | - assert((pos >= 0) && (QIntC::to_size(pos) <= this->m->all_pages.size())); | |
| 253 | 255 | |
| 254 | 256 | newpage.replaceKey("/Parent", pages); |
| 255 | 257 | kids.insertItem(pos, newpage); | ... | ... |