aboutsummaryrefslogtreecommitdiffstats
path: root/libqpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-05-03 13:41:07 +0200
committerJay Berkenbilt <ejb@ql.org>2022-05-04 00:31:22 +0200
commit92b692466f7a4dbf4e51e6a77713c029a3e18ab1 (patch)
treeba139d7b9c290bfc2a83c2719cf0ce86cf27ad36 /libqpdf
parentb20f0519224b0c089f78730fb20291cc2d539979 (diff)
downloadqpdf-92b692466f7a4dbf4e51e6a77713c029a3e18ab1.tar.zst
Remove remaining incorrect assert calls from implementation
Diffstat (limited to 'libqpdf')
-rw-r--r--libqpdf/AES_PDF_native.cc1
-rw-r--r--libqpdf/Pl_AES_PDF.cc11
-rw-r--r--libqpdf/Pl_Buffer.cc1
-rw-r--r--libqpdf/Pl_LZWDecoder.cc1
-rw-r--r--libqpdf/QPDFWriter.cc9
-rw-r--r--libqpdf/QPDF_encryption.cc2
-rw-r--r--libqpdf/QPDF_linearization.cc4
-rw-r--r--libqpdf/QPDF_optimization.cc2
-rw-r--r--libqpdf/QPDF_pages.cc8
9 files changed, 19 insertions, 20 deletions
diff --git a/libqpdf/AES_PDF_native.cc b/libqpdf/AES_PDF_native.cc
index 3a831efe..1316a643 100644
--- a/libqpdf/AES_PDF_native.cc
+++ b/libqpdf/AES_PDF_native.cc
@@ -4,7 +4,6 @@
#include <qpdf/QPDFCryptoImpl.hh>
#include <qpdf/QUtil.hh>
#include <qpdf/rijndael.h>
-#include <assert.h>
#include <cstring>
#include <stdexcept>
#include <stdlib.h>
diff --git a/libqpdf/Pl_AES_PDF.cc b/libqpdf/Pl_AES_PDF.cc
index 80cd8534..dc281fae 100644
--- a/libqpdf/Pl_AES_PDF.cc
+++ b/libqpdf/Pl_AES_PDF.cc
@@ -3,7 +3,6 @@
#include <qpdf/QIntC.hh>
#include <qpdf/QPDFCryptoProvider.hh>
#include <qpdf/QUtil.hh>
-#include <assert.h>
#include <cstring>
#include <stdexcept>
#include <stdlib.h>
@@ -115,7 +114,10 @@ Pl_AES_PDF::finish()
// encountered files for which the output is not a
// multiple of the block size. In this case, pad with
// zeroes and hope for the best.
- assert(this->buf_size > this->offset);
+ if (this->offset >= this->buf_size) {
+ throw std::logic_error("buffer overflow in AES encryption"
+ " pipeline");
+ }
std::memset(
this->inbuf + this->offset, 0, this->buf_size - this->offset);
this->offset = this->buf_size;
@@ -147,7 +149,10 @@ Pl_AES_PDF::initializeVector()
void
Pl_AES_PDF::flush(bool strip_padding)
{
- assert(this->offset == this->buf_size);
+ if (this->offset != this->buf_size) {
+ throw std::logic_error(
+ "AES pipeline: flush called when buffer was not full");
+ }
if (first) {
first = false;
diff --git a/libqpdf/Pl_Buffer.cc b/libqpdf/Pl_Buffer.cc
index b47124d3..4f45acbd 100644
--- a/libqpdf/Pl_Buffer.cc
+++ b/libqpdf/Pl_Buffer.cc
@@ -1,7 +1,6 @@
#include <qpdf/Pl_Buffer.hh>
#include <algorithm>
-#include <assert.h>
#include <stdexcept>
#include <stdlib.h>
#include <string.h>
diff --git a/libqpdf/Pl_LZWDecoder.cc b/libqpdf/Pl_LZWDecoder.cc
index 68caa5c9..db6d7490 100644
--- a/libqpdf/Pl_LZWDecoder.cc
+++ b/libqpdf/Pl_LZWDecoder.cc
@@ -3,7 +3,6 @@
#include <qpdf/QIntC.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QUtil.hh>
-#include <assert.h>
#include <stdexcept>
#include <string.h>
diff --git a/libqpdf/QPDFWriter.cc b/libqpdf/QPDFWriter.cc
index 0b7e7c42..e5270449 100644
--- a/libqpdf/QPDFWriter.cc
+++ b/libqpdf/QPDFWriter.cc
@@ -11,18 +11,17 @@
#include <qpdf/Pl_PNGFilter.hh>
#include <qpdf/Pl_RC4.hh>
#include <qpdf/Pl_StdioFile.hh>
-#include <qpdf/QTC.hh>
-#include <qpdf/QUtil.hh>
-#include <qpdf/RC4.hh>
-#include <assert.h>
-
#include <qpdf/QIntC.hh>
#include <qpdf/QPDF.hh>
#include <qpdf/QPDFObjectHandle.hh>
#include <qpdf/QPDF_Name.hh>
#include <qpdf/QPDF_String.hh>
+#include <qpdf/QTC.hh>
+#include <qpdf/QUtil.hh>
+#include <qpdf/RC4.hh>
#include <algorithm>
+#include <cassert>
#include <stdlib.h>
QPDFWriter::Members::Members(QPDF& pdf) :
diff --git a/libqpdf/QPDF_encryption.cc b/libqpdf/QPDF_encryption.cc
index b943777f..14b22d88 100644
--- a/libqpdf/QPDF_encryption.cc
+++ b/libqpdf/QPDF_encryption.cc
@@ -15,7 +15,7 @@
#include <qpdf/RC4.hh>
#include <algorithm>
-#include <assert.h>
+#include <cassert>
#include <string.h>
static unsigned char const padding_string[] = {
diff --git a/libqpdf/QPDF_linearization.cc b/libqpdf/QPDF_linearization.cc
index ec422406..cf88bb70 100644
--- a/libqpdf/QPDF_linearization.cc
+++ b/libqpdf/QPDF_linearization.cc
@@ -12,7 +12,6 @@
#include <qpdf/QUtil.hh>
#include <algorithm>
-#include <assert.h>
#include <iostream>
#include <math.h>
#include <string.h>
@@ -172,9 +171,6 @@ QPDF::readLinearizationData()
// This function throws an exception (which is trapped by
// checkLinearization()) for any errors that prevent loading.
- // Hint table parsing code needs at least 32 bits in a long.
- assert(sizeof(long) >= 4);
-
if (!isLinearized()) {
throw std::logic_error("called readLinearizationData for file"
" that is not linearized");
diff --git a/libqpdf/QPDF_optimization.cc b/libqpdf/QPDF_optimization.cc
index d22aa378..ac1bbfe6 100644
--- a/libqpdf/QPDF_optimization.cc
+++ b/libqpdf/QPDF_optimization.cc
@@ -6,7 +6,7 @@
#include <qpdf/QPDF_Array.hh>
#include <qpdf/QPDF_Dictionary.hh>
#include <qpdf/QTC.hh>
-#include <assert.h>
+#include <cassert>
QPDF::ObjUser::ObjUser() :
ou_type(ou_bad),
diff --git a/libqpdf/QPDF_pages.cc b/libqpdf/QPDF_pages.cc
index 89a782f4..e8416b2b 100644
--- a/libqpdf/QPDF_pages.cc
+++ b/libqpdf/QPDF_pages.cc
@@ -1,7 +1,5 @@
#include <qpdf/QPDF.hh>
-#include <assert.h>
-
#include <qpdf/QPDFExc.hh>
#include <qpdf/QTC.hh>
#include <qpdf/QUtil.hh>
@@ -233,6 +231,11 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
QTC::TC("qpdf", "QPDF insert indirect page");
}
+ if ((pos < 0) || (QIntC::to_size(pos) > this->m->all_pages.size())) {
+ throw std::runtime_error(
+ "QPDF::insertPage called with pos out of range");
+ }
+
QTC::TC(
"qpdf",
"QPDF insert page",
@@ -249,7 +252,6 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
QPDFObjectHandle pages = getRoot().getKey("/Pages");
QPDFObjectHandle kids = pages.getKey("/Kids");
- assert((pos >= 0) && (QIntC::to_size(pos) <= this->m->all_pages.size()));
newpage.replaceKey("/Parent", pages);
kids.insertItem(pos, newpage);