mirror of
https://github.com/qpdf/qpdf.git
synced 2024-12-22 10:58:58 +00:00
Fix segmentation fault with use of QPDFWriter::setOutputMemory
This commit is contained in:
parent
b51a5b2c09
commit
8d2b29ef98
@ -1,3 +1,10 @@
|
|||||||
|
2012-09-06 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
|
* Bug fix: Writing after calling QPDFWriter::setOutputMemory()
|
||||||
|
would cause a segmentation fault because of an internal field not
|
||||||
|
being initialized, rendering that method useless. This has been
|
||||||
|
corrected.
|
||||||
|
|
||||||
2012-08-11 Jay Berkenbilt <ejb@ql.org>
|
2012-08-11 Jay Berkenbilt <ejb@ql.org>
|
||||||
|
|
||||||
* 3.0.1: release
|
* 3.0.1: release
|
||||||
|
8
TODO
8
TODO
@ -1,11 +1,3 @@
|
|||||||
3.0.2
|
|
||||||
=====
|
|
||||||
|
|
||||||
* QPDFWriter::setOutputMemory segfaults without setStaticID because
|
|
||||||
it doesn't set this->filename. Be sure to have a test case that
|
|
||||||
exercises this. Check the function that sets the ID carefully to
|
|
||||||
make sure other cases aren't missed.
|
|
||||||
|
|
||||||
General
|
General
|
||||||
=======
|
=======
|
||||||
|
|
||||||
|
@ -120,6 +120,7 @@ QPDFWriter::setOutputFile(char const* description, FILE* file, bool close_file)
|
|||||||
void
|
void
|
||||||
QPDFWriter::setOutputMemory()
|
QPDFWriter::setOutputMemory()
|
||||||
{
|
{
|
||||||
|
this->filename = "memory buffer";
|
||||||
this->buffer_pipeline = new Pl_Buffer("qpdf output");
|
this->buffer_pipeline = new Pl_Buffer("qpdf output");
|
||||||
to_delete.push_back(this->buffer_pipeline);
|
to_delete.push_back(this->buffer_pipeline);
|
||||||
initializePipelineStack(this->buffer_pipeline);
|
initializePipelineStack(this->buffer_pipeline);
|
||||||
@ -1492,7 +1493,7 @@ QPDFWriter::generateID()
|
|||||||
std::string seed;
|
std::string seed;
|
||||||
seed += QUtil::int_to_string((int)QUtil::get_current_time());
|
seed += QUtil::int_to_string((int)QUtil::get_current_time());
|
||||||
seed += " QPDF ";
|
seed += " QPDF ";
|
||||||
seed += filename;
|
seed += this->filename;
|
||||||
seed += " ";
|
seed += " ";
|
||||||
if (trailer.hasKey("/Info"))
|
if (trailer.hasKey("/Info"))
|
||||||
{
|
{
|
||||||
|
@ -149,7 +149,7 @@ $td->runtest("remove page we don't have",
|
|||||||
$td->NORMALIZE_NEWLINES);
|
$td->NORMALIZE_NEWLINES);
|
||||||
# ----------
|
# ----------
|
||||||
$td->notify("--- Miscellaneous Tests ---");
|
$td->notify("--- Miscellaneous Tests ---");
|
||||||
$n_tests += 47;
|
$n_tests += 48;
|
||||||
|
|
||||||
$td->runtest("qpdf version",
|
$td->runtest("qpdf version",
|
||||||
{$td->COMMAND => "qpdf --version"},
|
{$td->COMMAND => "qpdf --version"},
|
||||||
@ -322,6 +322,11 @@ $td->runtest("swap and replace",
|
|||||||
$td->runtest("check output",
|
$td->runtest("check output",
|
||||||
{$td->FILE => "a.pdf"},
|
{$td->FILE => "a.pdf"},
|
||||||
{$td->FILE => "test14-out.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->runtest("C API info key functions",
|
||||||
{$td->COMMAND => "qpdf-ctest 16 minimal.pdf '' a.pdf"},
|
{$td->COMMAND => "qpdf-ctest 16 minimal.pdf '' a.pdf"},
|
||||||
|
@ -646,17 +646,22 @@ void runtest(int n, char const* filename1, char const* filename2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Exercise writing to memory buffer
|
// Exercise writing to memory buffer
|
||||||
QPDFWriter w(pdf);
|
for (int i = 0; i < 2; ++i)
|
||||||
w.setOutputMemory();
|
{
|
||||||
w.setStaticID(true);
|
QPDFWriter w(pdf);
|
||||||
w.setStreamDataMode(qpdf_s_preserve);
|
w.setOutputMemory();
|
||||||
w.write();
|
// Exercise setOutputMemory with and without static ID
|
||||||
Buffer* b = w.getBuffer();
|
w.setStaticID(i == 0);
|
||||||
FILE* f = QUtil::fopen_wrapper(std::string("open a.pdf"),
|
w.setStreamDataMode(qpdf_s_preserve);
|
||||||
fopen("a.pdf", "wb"));
|
w.write();
|
||||||
fwrite(b->getBuffer(), b->getSize(), 1, f);
|
Buffer* b = w.getBuffer();
|
||||||
fclose(f);
|
std::string const filename = (i == 0 ? "a.pdf" : "b.pdf");
|
||||||
delete b;
|
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)
|
else if (n == 15)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user