From ad0ab25d660184de00e63067ed5fcdf9453a66f0 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Tue, 20 Oct 2009 00:59:38 +0000 Subject: fix bug in C API, test invalid password specifically git-svn-id: svn+q:///qpdf/trunk@832 71b93d88-0707-0410-a8cf-f5a4172ac649 --- TODO | 5 ----- libqpdf/qpdf-c.cc | 4 +++- qpdf/qtest/qpdf.test | 6 +++++- qpdf/qtest/qpdf/c-invalid-password.out | 5 +++++ qpdf/qtest/qpdf/c-write-damaged.out | 14 +++++++++++++- 5 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 qpdf/qtest/qpdf/c-invalid-password.out diff --git a/TODO b/TODO index 2027fb2e..691fcb37 100644 --- a/TODO +++ b/TODO @@ -16,11 +16,6 @@ * Add comments for the security functions that map them back to the items in Adobe's products. - * Change the C error interface so that warnings and errors are - pointers that can be queried using more C API functions. We need a - way to get a full string as well as an error code, file name, - offset, and message. - * "Delphi wrapper unit 'qpdf.pas' created by Zarko Gajic (http://delphi.about.com). .. use at your own risk and for whatever the purpose you want .. no support provided. Sample code provided." diff --git a/libqpdf/qpdf-c.cc b/libqpdf/qpdf-c.cc index d6e8882a..7704358d 100644 --- a/libqpdf/qpdf-c.cc +++ b/libqpdf/qpdf-c.cc @@ -51,7 +51,7 @@ static void call_read(qpdf_data qpdf) } // must set qpdf->filename -static void call_init_write(qpdf_data qpdf) +void call_init_write(qpdf_data qpdf) { qpdf->qpdf_writer = new QPDFWriter(*(qpdf->qpdf), qpdf->filename); } @@ -76,10 +76,12 @@ static QPDF_ERROR_CODE trap_errors(qpdf_data qpdf, void (*fn)(qpdf_data)) catch (std::runtime_error& e) { qpdf->error = new QPDFExc(qpdf_e_system, "", "", 0, e.what()); + status |= QPDF_ERRORS; } catch (std::exception& e) { qpdf->error = new QPDFExc(qpdf_e_internal, "", "", 0, e.what()); + status |= QPDF_ERRORS; } if (qpdf_more_warnings(qpdf)) diff --git a/qpdf/qtest/qpdf.test b/qpdf/qtest/qpdf.test index fedbeb23..b3c9c620 100644 --- a/qpdf/qtest/qpdf.test +++ b/qpdf/qtest/qpdf.test @@ -830,7 +830,7 @@ my @encrypted_files = ['long-password', 'asdf asdf asdf asdf asdf asdf qwer'], ['long-password', 'asdf asdf asdf asdf asdf asdf qw']); -$n_tests += 3 + (2 * (@encrypted_files)) + (6 * (@encrypted_files - 3)) + 8; +$n_tests += 3 + (2 * (@encrypted_files)) + (6 * (@encrypted_files - 3)) + 0; $td->runtest("encrypted file", {$td->COMMAND => "test_driver 2 U25A0.pdf"}, @@ -952,6 +952,10 @@ $td->runtest("invalid password", {$td->STRING => "enc-R2,V1,U=view.pdf: invalid password\n", $td->EXIT_STATUS => 2}, $td->NORMALIZE_NEWLINES); +$td->runtest("C API: invalid password", + {$td->COMMAND => "qpdf-ctest 2 enc-R2,V1,U=view.pdf '' a.qdf"}, + {$td->FILE => "c-invalid-password.out", $td->EXIT_STATUS => 0}, + $td->NORMALIZE_NEWLINES); my @cenc = ( [11, 'hybrid-xref.pdf', "''", 'r2', ""], diff --git a/qpdf/qtest/qpdf/c-invalid-password.out b/qpdf/qtest/qpdf/c-invalid-password.out new file mode 100644 index 00000000..679643f0 --- /dev/null +++ b/qpdf/qtest/qpdf/c-invalid-password.out @@ -0,0 +1,5 @@ +error: enc-R2,V1,U=view.pdf: invalid password + code: 4 + file: enc-R2,V1,U=view.pdf + pos : 0 + text: invalid password diff --git a/qpdf/qtest/qpdf/c-write-damaged.out b/qpdf/qtest/qpdf/c-write-damaged.out index f2b68ddd..16c43904 100644 --- a/qpdf/qtest/qpdf/c-write-damaged.out +++ b/qpdf/qtest/qpdf/c-write-damaged.out @@ -1,3 +1,15 @@ warning: append-page-content-damaged.pdf: file is damaged + code: 5 + file: append-page-content-damaged.pdf + pos : 0 + text: file is damaged warning: append-page-content-damaged.pdf: can't find startxref -warning: Attempting to reconstruct cross-reference table + code: 5 + file: append-page-content-damaged.pdf + pos : 0 + text: can't find startxref +warning: append-page-content-damaged.pdf: Attempting to reconstruct cross-reference table + code: 5 + file: append-page-content-damaged.pdf + pos : 0 + text: Attempting to reconstruct cross-reference table -- cgit v1.2.3-54-g00ecf