Commit ad0ab25d660184de00e63067ed5fcdf9453a66f0

Authored by Jay Berkenbilt
1 parent 8b073eed

fix bug in C API, test invalid password specifically

git-svn-id: svn+q:///qpdf/trunk@832 71b93d88-0707-0410-a8cf-f5a4172ac649
@@ -16,11 +16,6 @@ @@ -16,11 +16,6 @@
16 * Add comments for the security functions that map them back to the 16 * Add comments for the security functions that map them back to the
17 items in Adobe's products. 17 items in Adobe's products.
18 18
19 - * Change the C error interface so that warnings and errors are  
20 - pointers that can be queried using more C API functions. We need a  
21 - way to get a full string as well as an error code, file name,  
22 - offset, and message.  
23 -  
24 * "Delphi wrapper unit 'qpdf.pas' created by Zarko Gajic 19 * "Delphi wrapper unit 'qpdf.pas' created by Zarko Gajic
25 (http://delphi.about.com). .. use at your own risk and for whatever 20 (http://delphi.about.com). .. use at your own risk and for whatever
26 the purpose you want .. no support provided. Sample code provided." 21 the purpose you want .. no support provided. Sample code provided."
libqpdf/qpdf-c.cc
@@ -51,7 +51,7 @@ static void call_read(qpdf_data qpdf) @@ -51,7 +51,7 @@ static void call_read(qpdf_data qpdf)
51 } 51 }
52 52
53 // must set qpdf->filename 53 // must set qpdf->filename
54 -static void call_init_write(qpdf_data qpdf) 54 +void call_init_write(qpdf_data qpdf)
55 { 55 {
56 qpdf->qpdf_writer = new QPDFWriter(*(qpdf->qpdf), qpdf->filename); 56 qpdf->qpdf_writer = new QPDFWriter(*(qpdf->qpdf), qpdf->filename);
57 } 57 }
@@ -76,10 +76,12 @@ static QPDF_ERROR_CODE trap_errors(qpdf_data qpdf, void (*fn)(qpdf_data)) @@ -76,10 +76,12 @@ static QPDF_ERROR_CODE trap_errors(qpdf_data qpdf, void (*fn)(qpdf_data))
76 catch (std::runtime_error& e) 76 catch (std::runtime_error& e)
77 { 77 {
78 qpdf->error = new QPDFExc(qpdf_e_system, "", "", 0, e.what()); 78 qpdf->error = new QPDFExc(qpdf_e_system, "", "", 0, e.what());
  79 + status |= QPDF_ERRORS;
79 } 80 }
80 catch (std::exception& e) 81 catch (std::exception& e)
81 { 82 {
82 qpdf->error = new QPDFExc(qpdf_e_internal, "", "", 0, e.what()); 83 qpdf->error = new QPDFExc(qpdf_e_internal, "", "", 0, e.what());
  84 + status |= QPDF_ERRORS;
83 } 85 }
84 86
85 if (qpdf_more_warnings(qpdf)) 87 if (qpdf_more_warnings(qpdf))
qpdf/qtest/qpdf.test
@@ -830,7 +830,7 @@ my @encrypted_files = @@ -830,7 +830,7 @@ my @encrypted_files =
830 ['long-password', 'asdf asdf asdf asdf asdf asdf qwer'], 830 ['long-password', 'asdf asdf asdf asdf asdf asdf qwer'],
831 ['long-password', 'asdf asdf asdf asdf asdf asdf qw']); 831 ['long-password', 'asdf asdf asdf asdf asdf asdf qw']);
832 832
833 -$n_tests += 3 + (2 * (@encrypted_files)) + (6 * (@encrypted_files - 3)) + 8; 833 +$n_tests += 3 + (2 * (@encrypted_files)) + (6 * (@encrypted_files - 3)) + 0;
834 834
835 $td->runtest("encrypted file", 835 $td->runtest("encrypted file",
836 {$td->COMMAND => "test_driver 2 U25A0.pdf"}, 836 {$td->COMMAND => "test_driver 2 U25A0.pdf"},
@@ -952,6 +952,10 @@ $td->runtest("invalid password", @@ -952,6 +952,10 @@ $td->runtest("invalid password",
952 {$td->STRING => "enc-R2,V1,U=view.pdf: invalid password\n", 952 {$td->STRING => "enc-R2,V1,U=view.pdf: invalid password\n",
953 $td->EXIT_STATUS => 2}, 953 $td->EXIT_STATUS => 2},
954 $td->NORMALIZE_NEWLINES); 954 $td->NORMALIZE_NEWLINES);
  955 +$td->runtest("C API: invalid password",
  956 + {$td->COMMAND => "qpdf-ctest 2 enc-R2,V1,U=view.pdf '' a.qdf"},
  957 + {$td->FILE => "c-invalid-password.out", $td->EXIT_STATUS => 0},
  958 + $td->NORMALIZE_NEWLINES);
955 959
956 my @cenc = ( 960 my @cenc = (
957 [11, 'hybrid-xref.pdf', "''", 'r2', ""], 961 [11, 'hybrid-xref.pdf', "''", 'r2', ""],
qpdf/qtest/qpdf/c-invalid-password.out 0 → 100644
  1 +error: enc-R2,V1,U=view.pdf: invalid password
  2 + code: 4
  3 + file: enc-R2,V1,U=view.pdf
  4 + pos : 0
  5 + text: invalid password
qpdf/qtest/qpdf/c-write-damaged.out
1 warning: append-page-content-damaged.pdf: file is damaged 1 warning: append-page-content-damaged.pdf: file is damaged
  2 + code: 5
  3 + file: append-page-content-damaged.pdf
  4 + pos : 0
  5 + text: file is damaged
2 warning: append-page-content-damaged.pdf: can't find startxref 6 warning: append-page-content-damaged.pdf: can't find startxref
3 -warning: Attempting to reconstruct cross-reference table 7 + code: 5
  8 + file: append-page-content-damaged.pdf
  9 + pos : 0
  10 + text: can't find startxref
  11 +warning: append-page-content-damaged.pdf: Attempting to reconstruct cross-reference table
  12 + code: 5
  13 + file: append-page-content-damaged.pdf
  14 + pos : 0
  15 + text: Attempting to reconstruct cross-reference table