Commit 0ca44ef84ce48a2916095f66c219d2b112ce31e8
Committed by
Jay Berkenbilt
1 parent
383f5a00
Fix QPDFObjectHandle::isScalar
Exclude uninitialized, destroyed and reserved objects.
Showing
3 changed files
with
38 additions
and
6 deletions
libqpdf/QPDFObjectHandle.cc
| @@ -469,9 +469,8 @@ QPDFObjectHandle::isReserved() | @@ -469,9 +469,8 @@ QPDFObjectHandle::isReserved() | ||
| 469 | bool | 469 | bool |
| 470 | QPDFObjectHandle::isScalar() | 470 | QPDFObjectHandle::isScalar() |
| 471 | { | 471 | { |
| 472 | - return ( | ||
| 473 | - !(isArray() || isDictionary() || isStream() || isOperator() || | ||
| 474 | - isInlineImage())); | 472 | + return isBool() || isInteger() || isName() || isNull() || isReal() || |
| 473 | + isString(); | ||
| 475 | } | 474 | } |
| 476 | 475 | ||
| 477 | bool | 476 | bool |
qpdf/qtest/object-handle-api.test
| @@ -26,6 +26,10 @@ $td->runtest("equality", | @@ -26,6 +26,10 @@ $td->runtest("equality", | ||
| 26 | {$td->COMMAND => "test_driver 93 minimal.pdf -"}, | 26 | {$td->COMMAND => "test_driver 93 minimal.pdf -"}, |
| 27 | {$td->STRING => "test 93 done\n", $td->EXIT_STATUS => 0}, | 27 | {$td->STRING => "test 93 done\n", $td->EXIT_STATUS => 0}, |
| 28 | $td->NORMALIZE_NEWLINES); | 28 | $td->NORMALIZE_NEWLINES); |
| 29 | +$td->runtest("isScalar checks", | ||
| 30 | + {$td->COMMAND => "test_driver 95 - -"}, | ||
| 31 | + {$td->STRING => "test 95 done\n", $td->EXIT_STATUS => 0}, | ||
| 32 | + $td->NORMALIZE_NEWLINES); | ||
| 29 | 33 | ||
| 30 | cleanup(); | 34 | cleanup(); |
| 31 | -$td->report(3); | 35 | +$td->report(4); |
qpdf/test_driver.cc
| @@ -1559,6 +1559,7 @@ test_42(QPDF& pdf, char const* arg2) | @@ -1559,6 +1559,7 @@ test_42(QPDF& pdf, char const* arg2) | ||
| 1559 | assert(!uninitialized.isInitialized()); | 1559 | assert(!uninitialized.isInitialized()); |
| 1560 | assert(!uninitialized.isInteger()); | 1560 | assert(!uninitialized.isInteger()); |
| 1561 | assert(!uninitialized.isDictionary()); | 1561 | assert(!uninitialized.isDictionary()); |
| 1562 | + assert(!uninitialized.isScalar()); | ||
| 1562 | } | 1563 | } |
| 1563 | 1564 | ||
| 1564 | static void | 1565 | static void |
| @@ -3331,6 +3332,7 @@ test_92(QPDF& pdf, char const* arg2) | @@ -3331,6 +3332,7 @@ test_92(QPDF& pdf, char const* arg2) | ||
| 3331 | assert(resources.isDictionary()); | 3332 | assert(resources.isDictionary()); |
| 3332 | assert(!resources.isIndirect()); | 3333 | assert(!resources.isIndirect()); |
| 3333 | auto contents = page1.getKey("/Contents"); | 3334 | auto contents = page1.getKey("/Contents"); |
| 3335 | + assert(!contents.isScalar()); | ||
| 3334 | auto contents_dict = contents.getDict(); | 3336 | auto contents_dict = contents.getDict(); |
| 3335 | qpdf = nullptr; | 3337 | qpdf = nullptr; |
| 3336 | auto check = [](QPDFObjectHandle& oh) { | 3338 | auto check = [](QPDFObjectHandle& oh) { |
| @@ -3347,6 +3349,7 @@ test_92(QPDF& pdf, char const* arg2) | @@ -3347,6 +3349,7 @@ test_92(QPDF& pdf, char const* arg2) | ||
| 3347 | // Otherwise, they should have retained their old values but just | 3349 | // Otherwise, they should have retained their old values but just |
| 3348 | // lost their connection to the owning QPDF. | 3350 | // lost their connection to the owning QPDF. |
| 3349 | assert(root.isDestroyed()); | 3351 | assert(root.isDestroyed()); |
| 3352 | + assert(!root.isScalar()); | ||
| 3350 | assert(page1.isDestroyed()); | 3353 | assert(page1.isDestroyed()); |
| 3351 | assert(contents.isDestroyed()); | 3354 | assert(contents.isDestroyed()); |
| 3352 | assert(resources.isDictionary()); | 3355 | assert(resources.isDictionary()); |
| @@ -3488,6 +3491,32 @@ test_94(QPDF& pdf, char const* arg2) | @@ -3488,6 +3491,32 @@ test_94(QPDF& pdf, char const* arg2) | ||
| 3488 | assert(p5_new_bleed.unparse() == root_media_unparse); | 3491 | assert(p5_new_bleed.unparse() == root_media_unparse); |
| 3489 | } | 3492 | } |
| 3490 | 3493 | ||
| 3494 | +static void | ||
| 3495 | +test_95(QPDF& pdf, char const* arg2) | ||
| 3496 | +{ | ||
| 3497 | + // Test QPDFObjectHandle::isScalar | ||
| 3498 | + | ||
| 3499 | + auto oh_b = QPDFObjectHandle::newBool(false); | ||
| 3500 | + auto oh_i = QPDFObjectHandle::newInteger(1); | ||
| 3501 | + auto oh_r = QPDFObjectHandle::newReal("42.0"); | ||
| 3502 | + auto oh_n = QPDFObjectHandle::newName("/Test"); | ||
| 3503 | + auto oh_s = QPDFObjectHandle::newString("/Test"); | ||
| 3504 | + auto oh_o = QPDFObjectHandle::newOperator("/Test"); | ||
| 3505 | + auto oh_ii = QPDFObjectHandle::newInlineImage("/Test"); | ||
| 3506 | + auto oh_a = QPDFObjectHandle::newArray(); | ||
| 3507 | + auto oh_d = QPDFObjectHandle::newDictionary(); | ||
| 3508 | + | ||
| 3509 | + assert(oh_b.isScalar()); | ||
| 3510 | + assert(oh_i.isScalar()); | ||
| 3511 | + assert(oh_r.isScalar()); | ||
| 3512 | + assert(oh_n.isScalar()); | ||
| 3513 | + assert(oh_s.isScalar()); | ||
| 3514 | + assert(!oh_o.isScalar()); | ||
| 3515 | + assert(!oh_ii.isScalar()); | ||
| 3516 | + assert(!oh_a.isScalar()); | ||
| 3517 | + assert(!oh_d.isScalar()); | ||
| 3518 | +} | ||
| 3519 | + | ||
| 3491 | void | 3520 | void |
| 3492 | runtest(int n, char const* filename1, char const* arg2) | 3521 | runtest(int n, char const* filename1, char const* arg2) |
| 3493 | { | 3522 | { |
| @@ -3495,7 +3524,7 @@ runtest(int n, char const* filename1, char const* arg2) | @@ -3495,7 +3524,7 @@ runtest(int n, char const* filename1, char const* arg2) | ||
| 3495 | // the test suite to see how the test is invoked to find the file | 3524 | // the test suite to see how the test is invoked to find the file |
| 3496 | // that the test is supposed to operate on. | 3525 | // that the test is supposed to operate on. |
| 3497 | 3526 | ||
| 3498 | - std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87, 92}; | 3527 | + std::set<int> ignore_filename = {61, 81, 83, 84, 85, 86, 87, 92, 95}; |
| 3499 | 3528 | ||
| 3500 | if (n == 0) { | 3529 | if (n == 0) { |
| 3501 | // Throw in some random test cases that don't fit anywhere | 3530 | // Throw in some random test cases that don't fit anywhere |
| @@ -3597,7 +3626,7 @@ runtest(int n, char const* filename1, char const* arg2) | @@ -3597,7 +3626,7 @@ runtest(int n, char const* filename1, char const* arg2) | ||
| 3597 | {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83}, | 3626 | {80, test_80}, {81, test_81}, {82, test_82}, {83, test_83}, |
| 3598 | {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, | 3627 | {84, test_84}, {85, test_85}, {86, test_86}, {87, test_87}, |
| 3599 | {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91}, | 3628 | {88, test_88}, {89, test_89}, {90, test_90}, {91, test_91}, |
| 3600 | - {92, test_92}, {93, test_93}, {94, test_94}}; | 3629 | + {92, test_92}, {93, test_93}, {94, test_94}, {95, test_95}}; |
| 3601 | 3630 | ||
| 3602 | auto fn = test_functions.find(n); | 3631 | auto fn = test_functions.find(n); |
| 3603 | if (fn == test_functions.end()) { | 3632 | if (fn == test_functions.end()) { |