aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2012-09-06 20:39:06 +0200
committerJay Berkenbilt <ejb@ql.org>2012-09-06 20:39:06 +0200
commit8d2b29ef988aa86489e36be50fa881335b81363e (patch)
treebb8b5a589f4241b01df696684ce8c891aeb0d054 /qpdf
parentb51a5b2c09dc679917f62f932ab373b3c397126e (diff)
downloadqpdf-8d2b29ef988aa86489e36be50fa881335b81363e.tar.zst
Fix segmentation fault with use of QPDFWriter::setOutputMemory
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qtest/qpdf.test7
-rw-r--r--qpdf/test_driver.cc27
2 files changed, 22 insertions, 12 deletions
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index fda92b30..b2ee28eb 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -149,7 +149,7 @@ $td->runtest("remove page we don't have",
$td->NORMALIZE_NEWLINES);
# ----------
$td->notify("--- Miscellaneous Tests ---");
-$n_tests += 47;
+$n_tests += 48;
$td->runtest("qpdf version",
{$td->COMMAND => "qpdf --version"},
@@ -322,6 +322,11 @@ $td->runtest("swap and replace",
$td->runtest("check output",
{$td->FILE => "a.pdf"},
{$td->FILE => "test14-out.pdf"});
+# Test 14 also exercises writing to memory without static ID.
+$td->runtest("check non-static ID version",
+ {$td->COMMAND => "./diff-ignore-ID-version a.pdf b.pdf"},
+ {$td->STRING => "okay\n", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
$td->runtest("C API info key functions",
{$td->COMMAND => "qpdf-ctest 16 minimal.pdf '' a.pdf"},
diff --git a/qpdf/test_driver.cc b/qpdf/test_driver.cc
index 3861c403..b277cdf1 100644
--- a/qpdf/test_driver.cc
+++ b/qpdf/test_driver.cc
@@ -646,17 +646,22 @@ void runtest(int n, char const* filename1, char const* filename2)
}
// Exercise writing to memory buffer
- QPDFWriter w(pdf);
- w.setOutputMemory();
- w.setStaticID(true);
- w.setStreamDataMode(qpdf_s_preserve);
- w.write();
- Buffer* b = w.getBuffer();
- FILE* f = QUtil::fopen_wrapper(std::string("open a.pdf"),
- fopen("a.pdf", "wb"));
- fwrite(b->getBuffer(), b->getSize(), 1, f);
- fclose(f);
- delete b;
+ for (int i = 0; i < 2; ++i)
+ {
+ QPDFWriter w(pdf);
+ w.setOutputMemory();
+ // Exercise setOutputMemory with and without static ID
+ w.setStaticID(i == 0);
+ w.setStreamDataMode(qpdf_s_preserve);
+ w.write();
+ Buffer* b = w.getBuffer();
+ std::string const filename = (i == 0 ? "a.pdf" : "b.pdf");
+ FILE* f = QUtil::fopen_wrapper("open " + filename,
+ fopen(filename.c_str(), "wb"));
+ fwrite(b->getBuffer(), b->getSize(), 1, f);
+ fclose(f);
+ delete b;
+ }
}
else if (n == 15)
{