aboutsummaryrefslogtreecommitdiffstats
path: root/qpdf
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2009-03-08 20:00:19 +0100
committerJay Berkenbilt <ejb@ql.org>2009-03-08 20:00:19 +0100
commit599daddb47fc0340e48b02f7ba00ef86bfef8c45 (patch)
tree8c2d6e168b815b8090861de563beaba885f128aa /qpdf
parent9210dd46d2521e8e61e94d00e37a487bf9a7eda7 (diff)
downloadqpdf-599daddb47fc0340e48b02f7ba00ef86bfef8c45.tar.zst
decode streams on check, always exit abnormally when warnings are detected
git-svn-id: svn+q:///qpdf/trunk@660 71b93d88-0707-0410-a8cf-f5a4172ac649
Diffstat (limited to 'qpdf')
-rw-r--r--qpdf/qpdf.cc20
-rw-r--r--qpdf/qpdf.testcov1
-rw-r--r--qpdf/qtest/qpdf.test33
3 files changed, 41 insertions, 13 deletions
diff --git a/qpdf/qpdf.cc b/qpdf/qpdf.cc
index 9a349902..279eef33 100644
--- a/qpdf/qpdf.cc
+++ b/qpdf/qpdf.cc
@@ -12,6 +12,9 @@
#include <qpdf/QPDFWriter.hh>
+static int const EXIT_ERROR = 2;
+static int const EXIT_WARNING = 3;
+
static char const* whoami = 0;
// Note: let's not be too noisy about documenting the fact that this
@@ -158,7 +161,7 @@ void usage(std::string const& msg)
<< "Usage: " << whoami << " [options] infile outfile" << std::endl
<< "For detailed help, run " << whoami << " --help" << std::endl
<< std::endl;
- exit(2);
+ exit(EXIT_ERROR);
}
static void show_encryption(QPDF& pdf)
@@ -752,7 +755,7 @@ int main(int argc, char* argv[])
}
else
{
- exit(2);
+ exit(EXIT_ERROR);
}
}
if (show_linearization)
@@ -777,7 +780,7 @@ int main(int argc, char* argv[])
QTC::TC("qpdf", "unable to filter");
std::cerr << "Unable to filter stream data."
<< std::endl;
- exit(2);
+ exit(EXIT_ERROR);
}
else
{
@@ -869,6 +872,8 @@ int main(int argc, char* argv[])
// traversal of file, so any structural errors
// would be exposed.
pdf.flattenScalarReferences();
+ // Also explicitly decode all streams.
+ pdf.decodeStreams();
okay = true;
}
}
@@ -880,8 +885,7 @@ int main(int argc, char* argv[])
{
if (! pdf.getWarnings().empty())
{
- // special exit status for warnings without errors
- exit(3);
+ exit(EXIT_WARNING);
}
else
{
@@ -946,11 +950,15 @@ int main(int argc, char* argv[])
}
w.write();
}
+ if (! pdf.getWarnings().empty())
+ {
+ exit(EXIT_WARNING);
+ }
}
catch (std::exception& e)
{
std::cerr << e.what() << std::endl;
- exit(2);
+ exit(EXIT_ERROR);
}
return 0;
diff --git a/qpdf/qpdf.testcov b/qpdf/qpdf.testcov
index 93f850f4..3110f76a 100644
--- a/qpdf/qpdf.testcov
+++ b/qpdf/qpdf.testcov
@@ -117,3 +117,4 @@ QPDF piping xref stream from encrypted file 0
unable to filter 0
QPDF_String non-trivial UTF-16 0
QPDF xref overwrite object 0
+QPDF decoding error warning 0
diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test
index 7432edbd..0751afbd 100644
--- a/qpdf/qtest/qpdf.test
+++ b/qpdf/qtest/qpdf.test
@@ -183,7 +183,7 @@ for (my $i = 1; $i <= scalar(@badfiles); ++$i)
$td->runtest("recover heifer file",
{$td->COMMAND => "qpdf --static-id -qdf heifer.pdf a.pdf"},
{$td->FILE => "heifer.out",
- $td->EXIT_STATUS => 0},
+ $td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("check output",
{$td->FILE => "a.pdf"},
@@ -206,7 +206,7 @@ $td->runtest("damaged replaced page contents",
{$td->COMMAND => "qpdf --static-id -qdf" .
" append-page-content-damaged.pdf a.pdf"},
{$td->FILE => "append-page-content-damaged.out",
- $td->EXIT_STATUS => 0},
+ $td->EXIT_STATUS => 3},
$td->NORMALIZE_NEWLINES);
$td->runtest("check output",
{$td->FILE => "a.pdf"},
@@ -282,7 +282,7 @@ check_pdf("no recompression",
show_ntests();
# ----------
$td->notify("--- Object Stream Tests ---");
-$n_tests += 36 * 4;
+$n_tests += 36 * 6;
$n_compare_pdfs += 36;
for (my $n = 16; $n <= 19; ++$n)
@@ -294,7 +294,7 @@ for (my $n = 16; $n <= 19; ++$n)
{
foreach my $qdf ('-qdf', '', '-encrypt "" x 128 --')
{
- # 4 tests + 1 compare_pdfs
+ # 6 tests + 1 compare_pdfs
$td->runtest("object stream mode",
{$td->COMMAND =>
"qpdf --static-id $flags $qdf $in a.pdf"},
@@ -316,6 +316,12 @@ for (my $n = 16; $n <= 19; ++$n)
$td->runtest("compare files",
{$td->FILE => "a.qdf"},
{$td->FILE => "b.qdf"});
+ $td->runtest("fix-qdf identity check",
+ {$td->COMMAND => "fix-qdf a.qdf >| b.pdf"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0});
+ $td->runtest("compare files",
+ {$td->FILE => "a.qdf"},
+ {$td->FILE => "b.qdf"});
}
}
flush_tiff_cache();
@@ -324,12 +330,14 @@ for (my $n = 16; $n <= 19; ++$n)
show_ntests();
# ----------
$td->notify("--- Specific File Tests ---");
-$n_tests += 1;
+$n_tests += 2;
+$n_compare_pdfs += 1;
# Special PDF files that caused problems at some point
# This file is a PDF 1.1 file with /# as a name and with
-# inconsistencies in its free table.
+# inconsistencies in its free table. It also has LZW streams that
+# happen to test boundary conditions in the LZW decoder.
$td->runtest("old and complex",
{$td->COMMAND => "qpdf --check old-and-complex.pdf"},
{$td->STRING => +("checking old-and-complex.pdf\n" .
@@ -339,6 +347,12 @@ $td->runtest("old and complex",
$td->EXIT_STATUS => 0},
$td->NORMALIZE_NEWLINES);
+$td->runtest("convert to qdf",
+ {$td->COMMAND => "qpdf --qdf old-and-complex.pdf a.qdf"},
+ {$td->STRING => "", $td->EXIT_STATUS => 0});
+
+compare_pdfs("old-and-complex.pdf", "a.qdf");
+
show_ntests();
# ----------
$td->notify("--- Mutability Tests ---");
@@ -823,7 +837,7 @@ foreach my $file (@files)
show_ntests();
# ----------
$td->notify("--- fix-qdf Tests ---");
-$n_tests += 2;
+$n_tests += 4;
for (my $n = 1; $n <= 2; ++$n)
{
@@ -831,6 +845,11 @@ for (my $n = 1; $n <= 2; ++$n)
{$td->COMMAND => "fix-qdf fix$n.qdf"},
{$td->FILE => "fix$n.qdf.out",
$td->EXIT_STATUS => 0});
+
+ $td->runtest("identity fix-qdf $n",
+ {$td->COMMAND => "fix-qdf fix$n.qdf.out"},
+ {$td->FILE => "fix$n.qdf.out",
+ $td->EXIT_STATUS => 0});
}
show_ntests();