2
1
mirror of https://github.com/qpdf/qpdf.git synced 2024-12-22 02:49:00 +00:00

Fix input file = output file test for split pages

This commit is contained in:
Jay Berkenbilt 2021-02-23 08:08:48 -05:00
parent be3a8c0e7a
commit 039eb4a253
3 changed files with 25 additions and 2 deletions

View File

@ -1,3 +1,9 @@
2021-02-23 Jay Berkenbilt <ejb@ql.org>
* The test for the input and output files being the same wasn't
implemented correctly for --split-pages since the specified output
file is really a pattern, not the actual output file.
2021-02-22 Jay Berkenbilt <ejb@ql.org>
* From qpdf CLI, --pages and --split-pages will properly preserve

View File

@ -3738,7 +3738,7 @@ ArgParser::doFinalChecks()
}
}
if (QUtil::same_file(o.infilename, o.outfilename))
if ((! o.split_pages) && QUtil::same_file(o.infilename, o.outfilename))
{
QTC::TC("qpdf", "qpdf same file error");
usage("input file and output file are the same;"
@ -6389,6 +6389,13 @@ static void do_split_pages(QPDF& pdf, Options& o, bool& warnings)
QUtil::uint_to_string(last, QIntC::to_int(pageno_len));
}
std::string outfile = before + page_range + after;
if (QUtil::same_file(o.infilename, outfile.c_str()))
{
std::cerr << whoami
<< ": split pages would overwrite input file with "
<< outfile << std::endl;
exit(EXIT_ERROR);
}
QPDFWriter w(outpdf, outfile.c_str());
set_writer_options(outpdf, o, w);
w.write();

View File

@ -1825,14 +1825,24 @@ $td->runtest("out of range in deleted object",
show_ntests();
# ----------
$td->notify("--- Overwrite self ---");
$n_tests += 1;
$n_tests += 3;
copy("minimal.pdf", "a.pdf");
copy("minimal.pdf", "split-out.pdf");
# Also tests @- for reading args from stdin
$td->runtest("don't overwrite self",
{$td->COMMAND => "(echo a.pdf; echo a.pdf) | qpdf \@-"},
{$td->REGEXP => "input file and output file are the same.*",
$td->EXIT_STATUS => 2});
$td->runtest("output is not really output for split",
{$td->COMMAND => "qpdf --split-pages split-out.pdf split-out.pdf"},
{$td->STRING => "", $td->EXIT_STATUS => 0});
$td->runtest("don't overwrite self (split)",
{$td->COMMAND =>
"qpdf --split-pages split-out-1.pdf split-out.pdf"},
{$td->REGEXP =>
".*split pages would overwrite.* split-out-1.pdf",
$td->EXIT_STATUS => 2});
show_ntests();
# ----------