aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-12-23 17:46:08 +0100
committerJay Berkenbilt <ejb@ql.org>2018-12-23 17:46:56 +0100
commit6048c6e2f06e21ebbe143df422dccd9bb50a3f6f (patch)
treea52a1bc9e7e63dc942d3fb92cf25adcc87af042c /qpdf
parent968e7e60b7390e0af4032b30714f1f3e2a1ed9de (diff)
downloadqpdf-6048c6e2f06e21ebbe143df422dccd9bb50a3f6f.tar.zst
Don't crash on @file when file doesn't exist (fixes #265)
When @file is used and file doesn't exist, just treat it as a normal argument.
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qpdf.cc17
-rw-r--r--qpdf/qtest/qpdf.test10
-rw-r--r--qpdf/qtest/qpdf/check-at-file.out6
3 files changed, 31 insertions, 2 deletions
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 3d1967d8..1a45180c 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -1408,8 +1408,25 @@ ArgParser::handleArgFileArguments()
new_argv.push_back(PointerHolder<char>(true, QUtil::copy_string(argv[0])));
for (int i = 1; i < argc; ++i)
{
+ char* argfile = 0;
if ((strlen(argv[i]) > 1) && (argv[i][0] == '@'))
{
+ try
+ {
+ argfile = 1 + argv[i];
+ if (strcmp(argfile, "-") != 0)
+ {
+ fclose(QUtil::safe_fopen(argfile, "rb"));
+ }
+ }
+ catch (std::runtime_error&)
+ {
+ // The file's not there; treating as regular option
+ argfile = 0;
+ }
+ }
+ if (argfile)
+ {
readArgsFromFile(1+argv[i]);
}
else
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 1f5009b9..8c976f6d 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -150,7 +150,7 @@ foreach my $c (@completion_tests)
show_ntests();
# ----------
$td->notify("--- Argument Parsing ---");
-$n_tests += 3;
+$n_tests += 4;
$td->runtest("required argument",
{$td->COMMAND => "qpdf --password minimal.pdf"},
@@ -167,6 +167,11 @@ $td->runtest("required argument with choices",
{$td->REGEXP => "must be given as --decode-level=\\{.*all.*\\}",
$td->EXIT_STATUS => 2},
$td->NORMALIZE_NEWLINES);
+copy("minimal.pdf", '@file.pdf');
+$td->runtest("\@file exists and file doesn't",
+ {$td->COMMAND => "qpdf --check \@file.pdf"},
+ {$td->FILE => "check-at-file.out", $td->EXIT_STATUS => 0},
+ $td->NORMALIZE_NEWLINES);
show_ntests();
# ----------
@@ -1100,6 +1105,7 @@ $td->notify("--- Overwrite self ---");
$n_tests += 1;
copy("minimal.pdf", "a.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.*",
@@ -3384,5 +3390,5 @@ sub get_md5_checksum
sub cleanup
{
system("rm -rf *.ps *.pnm ?.pdf ?.qdf *.enc* tif1 tif2 tiff-cache");
- system("rm -rf *split-out* ???-kfo.pdf *.tmpout");
+ system("rm -rf *split-out* ???-kfo.pdf *.tmpout \@file.pdf");
}
diff --git a/qpdf/qtest/qpdf/check-at-file.out b/qpdf/qtest/qpdf/check-at-file.out
new file mode 100644
index 00000000..9d4f1618
--- /dev/null
+++ b/qpdf/qtest/qpdf/check-at-file.out
@@ -0,0 +1,6 @@
+checking @file.pdf
+PDF Version: 1.3
+File is not encrypted
+File is not linearized
+No syntax or stream encoding errors found; the file may still contain
+errors that qpdf cannot detect