aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorm-holger <m-holger@kubitscheck.org>2022-08-15 16:13:11 +0200
committerm-holger <m-holger@kubitscheck.org>2022-09-01 18:20:16 +0200
commit805c1ad47968e33e1296af9a31492f6916ad9113 (patch)
tree4aba6da08ae9d441ecf57eabefdc76185137d28d /qpdf
parent2b7e9ba2f5a247ea45ac19cdf73506f351d5afb1 (diff)
downloadqpdf-805c1ad47968e33e1296af9a31492f6916ad9113.tar.zst
Reset QPDFValue::qpdf and QPDFValue::og when the owning QPDF object gets destroyed
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qtest/type-checks.test6
-rw-r--r--qpdf/test_driver.cc19
2 files changed, 22 insertions, 3 deletions
diff --git a/qpdf/qtest/type-checks.test b/qpdf/qtest/type-checks.test
index 03d75a6c..17b3c994 100644
--- a/qpdf/qtest/type-checks.test
+++ b/qpdf/qtest/type-checks.test
@@ -14,7 +14,7 @@ cleanup();
my $td = new TestDriver('type-checks');
-my $n_tests = 5;
+my $n_tests = 6;
# Whenever object-types.pdf is edited, object-types-os.pdf should be
# regenerated.
@@ -43,6 +43,10 @@ $td->runtest("compound type checks",
{$td->COMMAND => "test_driver 82 object-types-os.pdf"},
{$td->STRING => "test 82 done\n", $td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
+$td->runtest("indirect objects belonging to destroyed QPDF",
+ {$td->COMMAND => "test_driver 92 -"},
+ {$td->STRING => "test 92 done\n", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
cleanup();
$td->report($n_tests);
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index aa4f9ce5..5572e824 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -3258,6 +3258,20 @@ test_91(QPDF& pdf, char const* arg2)
2, &p, qpdf_dl_none, qpdf_sj_inline, "", std::set<std::string>());
}
+static void
+test_92(QPDF& pdf, char const* arg2)
+{
+ // Exercise indirect objects owned by destroyed QPDF object.
+ QPDF* qpdf = new QPDF();
+ qpdf->emptyPDF();
+ auto root = qpdf->getRoot();
+ assert(root.getOwningQPDF() != nullptr);
+ assert(root.isIndirect());
+ delete qpdf;
+ assert(root.getOwningQPDF() == nullptr);
+ assert(!root.isIndirect());
+}
+
void
runtest(int n, char const* filename1, char const* arg2)
{
@@ -3265,7 +3279,7 @@ runtest(int n, char const* filename1, char const* arg2)
// the test suite to see how the test is invoked to find the file
// that the test is supposed to operate on.
- std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87};
+ std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87, 92};
if (n == 0) {
// Throw in some random test cases that don't fit anywhere
@@ -3362,7 +3376,8 @@ runtest(int n, char const* filename1, char const* arg2)
{76, test_76}, {77, test_77}, {78, test_78}, {79, test_79},
{80, test_80}, {81, test_81}, {82, test_82}, {83, test_83},
{84, test_84}, {85, test_85}, {86, test_86}, {87, test_87},
- {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91}};
+ {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91},
+ {92, test_92}};
auto fn = test_functions.find(n);
if (fn == test_functions.end()) {