Commit 92b692466f7a4dbf4e51e6a77713c029a3e18ab1

Authored by Jay Berkenbilt
1 parent b20f0519

Remove remaining incorrect assert calls from implementation

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
... ... @@ -4,7 +4,6 @@
4 4 #include <qpdf/QPDFCryptoImpl.hh>
5 5 #include <qpdf/QUtil.hh>
6 6 #include <qpdf/rijndael.h>
7   -#include <assert.h>
8 7 #include <cstring>
9 8 #include <stdexcept>
10 9 #include <stdlib.h>
... ...
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
1 1 #include <qpdf/Pl_Buffer.hh>
2 2  
3 3 #include <algorithm>
4   -#include <assert.h>
5 4 #include <stdexcept>
6 5 #include <stdlib.h>
7 6 #include <string.h>
... ...
libqpdf/Pl_LZWDecoder.cc
... ... @@ -3,7 +3,6 @@
3 3 #include <qpdf/QIntC.hh>
4 4 #include <qpdf/QTC.hh>
5 5 #include <qpdf/QUtil.hh>
6   -#include <assert.h>
7 6 #include <stdexcept>
8 7 #include <string.h>
9 8  
... ...
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
... ... @@ -15,7 +15,7 @@
15 15 #include <qpdf/RC4.hh>
16 16  
17 17 #include <algorithm>
18   -#include <assert.h>
  18 +#include <cassert>
19 19 #include <string.h>
20 20  
21 21 static unsigned char const padding_string[] = {
... ...
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
... ... @@ -6,7 +6,7 @@
6 6 #include <qpdf/QPDF_Array.hh>
7 7 #include <qpdf/QPDF_Dictionary.hh>
8 8 #include <qpdf/QTC.hh>
9   -#include <assert.h>
  9 +#include <cassert>
10 10  
11 11 QPDF::ObjUser::ObjUser() :
12 12 ou_type(ou_bad),
... ...
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);
... ...