aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog2
-rw-r--r--include/qpdf/qpdf-c.h2
-rw-r--r--libqpdf/qpdf-c.cc12
-rw-r--r--manual/qpdf-manual.xml7
-rw-r--r--qpdf/qpdf-ctest.c7
-rw-r--r--qpdf/qpdf.testcov1
-rw-r--r--qpdf/qtest/qpdf/c-object-handles.out12
7 files changed, 34 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 201b5465..0024dbe7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,7 @@
2021-12-02 Jay Berkenbilt <ejb@ql.org>
+ * C API: Add qpdf_oh_is_initialized.
+
* C API: Add qpdf_get_last_string_length to return the length of
the last string returned. This is necessary in order to fully
retrieve values of strings that may contain embedded null characters.
diff --git a/include/qpdf/qpdf-c.h b/include/qpdf/qpdf-c.h
index 16d1ba64..294166ac 100644
--- a/include/qpdf/qpdf-c.h
+++ b/include/qpdf/qpdf-c.h
@@ -582,6 +582,8 @@ extern "C" {
*/
QPDF_DLL
+ QPDF_BOOL qpdf_oh_is_initialized(qpdf_data data, qpdf_oh oh);
+ QPDF_DLL
QPDF_BOOL qpdf_oh_is_bool(qpdf_data data, qpdf_oh oh);
QPDF_DLL
QPDF_BOOL qpdf_oh_is_null(qpdf_data data, qpdf_oh oh);
diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc
index 618b926d..85dda3b9 100644
--- a/libqpdf/qpdf-c.cc
+++ b/libqpdf/qpdf-c.cc
@@ -881,8 +881,7 @@ qpdf_oh_valid_internal(qpdf_data qpdf, qpdf_oh oh)
{
auto i = qpdf->oh_cache.find(oh);
bool result = ((i != qpdf->oh_cache.end()) &&
- (i->second).getPointer() &&
- (i->second)->isInitialized());
+ (i->second).getPointer());
if (! result)
{
QTC::TC("qpdf", "qpdf-c invalid object handle");
@@ -892,11 +891,18 @@ qpdf_oh_valid_internal(qpdf_data qpdf, qpdf_oh oh)
qpdf->qpdf->getFilename(),
std::string("C API object handle ") +
QUtil::uint_to_string(oh),
- 0, "attempted access to unknown/uninitialized object handle"));
+ 0, "attempted access to unknown object handle"));
}
return result;
}
+QPDF_BOOL qpdf_oh_is_initialized(qpdf_data qpdf, qpdf_oh oh)
+{
+ QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_initialized");
+ return (qpdf_oh_valid_internal(qpdf, oh) &&
+ qpdf->oh_cache[oh]->isInitialized());
+}
+
QPDF_BOOL qpdf_oh_is_bool(qpdf_data qpdf, qpdf_oh oh)
{
QTC::TC("qpdf", "qpdf-c called qpdf_oh_is_bool");
diff --git a/manual/qpdf-manual.xml b/manual/qpdf-manual.xml
index 217542b8..f721d234 100644
--- a/manual/qpdf-manual.xml
+++ b/manual/qpdf-manual.xml
@@ -5133,6 +5133,13 @@ print "\n";
embedded null characters.
</para>
</listitem>
+ <listitem>
+ <para>
+ Add <function>qpdf_oh_is_initialized</function> to the
+ C API. While you can't directly create uninitialized objects
+ from the C API, you still have to be able to detect them.
+ </para>
+ </listitem>
</itemizedlist>
</listitem>
</itemizedlist>
diff --git a/qpdf/qpdf-ctest.c b/qpdf/qpdf-ctest.c
index a57ea44f..c5d6d199 100644
--- a/qpdf/qpdf-ctest.c
+++ b/qpdf/qpdf-ctest.c
@@ -512,6 +512,7 @@ static void test24(char const* infile,
qpdf_oh_get_object_id(qpdf, root_from_trailer));
qpdf_oh pages = qpdf_oh_get_key(qpdf, root, "/Pages");
assert(qpdf_oh_is_dictionary(qpdf, pages));
+ assert(qpdf_oh_is_initialized(qpdf, pages));
qpdf_oh kids = qpdf_oh_get_key(qpdf, pages, "/Kids");
assert(qpdf_oh_is_array(qpdf, kids));
assert(qpdf_oh_get_array_n_items(qpdf, kids) == 1);
@@ -687,6 +688,12 @@ static void test24(char const* infile,
qpdf_set_suppress_original_object_IDs(qpdf, QPDF_TRUE);
qpdf_write(qpdf);
report_errors();
+
+ /* Make sure we detect uninitialized objects */
+ qpdf_data qpdf2 = qpdf_init();
+ trailer = qpdf_get_trailer(qpdf2);
+ assert(! qpdf_oh_is_initialized(qpdf2, trailer));
+ qpdf_cleanup(&qpdf2);
}
int main(int argc, char* argv[])
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index 277bf8df..b974af63 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -600,3 +600,4 @@ QPDF_pages findPage not found 0
qpdf overlay page with no resources 0
QPDFObjectHandle check ownership 0
qpdf weak crypto warning 0
+qpdf-c called qpdf_oh_is_initialized 0
diff --git a/qpdf/qtest/qpdf/c-object-handles.out b/qpdf/qtest/qpdf/c-object-handles.out
index 7fef9dad..675bacac 100644
--- a/qpdf/qtest/qpdf/c-object-handles.out
+++ b/qpdf/qtest/qpdf/c-object-handles.out
@@ -7,18 +7,18 @@ item 0: 0 0.00
item 1: 0 0.00
item 2: 612 612.00
item 3: 792 792.00
-warning: minimal.pdf (C API object handle 6): attempted access to unknown/uninitialized object handle
+warning: minimal.pdf (C API object handle 6): attempted access to unknown object handle
code: 5
file: minimal.pdf
pos : 0
- text: attempted access to unknown/uninitialized object handle
-warning: minimal.pdf (C API object handle 9): attempted access to unknown/uninitialized object handle
+ text: attempted access to unknown object handle
+warning: minimal.pdf (C API object handle 9): attempted access to unknown object handle
code: 5
file: minimal.pdf
pos : 0
- text: attempted access to unknown/uninitialized object handle
-warning: minimal.pdf (C API object handle 9): attempted access to unknown/uninitialized object handle
+ text: attempted access to unknown object handle
+warning: minimal.pdf (C API object handle 9): attempted access to unknown object handle
code: 5
file: minimal.pdf
pos : 0
- text: attempted access to unknown/uninitialized object handle
+ text: attempted access to unknown object handle