Commit 218900d2c3d155ee139338414f7a57921636de38
1 parent
028f106b
flatten scalar references for unreferenced objects
git-svn-id: svn+q:///qpdf/trunk@946 71b93d88-0707-0410-a8cf-f5a4172ac649
Showing
4 changed files
with
27 additions
and
7 deletions
libqpdf/QPDF_optimization.cc
| @@ -69,18 +69,25 @@ QPDF::flattenScalarReferences() | @@ -69,18 +69,25 @@ QPDF::flattenScalarReferences() | ||
| 69 | queue.push_back(this->trailer); | 69 | queue.push_back(this->trailer); |
| 70 | std::set<ObjGen> visited; | 70 | std::set<ObjGen> visited; |
| 71 | 71 | ||
| 72 | + // Add every object in the xref table to the queue. This ensures | ||
| 73 | + // that we flatten scalar references in unreferenced objects. | ||
| 74 | + // This becomes important if we are preserving object streams in a | ||
| 75 | + // file that has unreferenced objects in its object streams. (See | ||
| 76 | + // QPDF bug 2974522 at SourceForge.) | ||
| 77 | + for (std::map<ObjGen, QPDFXRefEntry>::iterator iter = | ||
| 78 | + this->xref_table.begin(); | ||
| 79 | + iter != this->xref_table.end(); ++iter) | ||
| 80 | + { | ||
| 81 | + ObjGen const& og = (*iter).first; | ||
| 82 | + queue.push_back(getObjectByID(og.obj, og.gen)); | ||
| 83 | + } | ||
| 84 | + | ||
| 72 | while (! queue.empty()) | 85 | while (! queue.empty()) |
| 73 | { | 86 | { |
| 74 | QPDFObjectHandle node = queue.front(); | 87 | QPDFObjectHandle node = queue.front(); |
| 75 | queue.pop_front(); | 88 | queue.pop_front(); |
| 76 | if (node.isIndirect()) | 89 | if (node.isIndirect()) |
| 77 | { | 90 | { |
| 78 | - if (node.isScalar()) | ||
| 79 | - { | ||
| 80 | - throw std::logic_error( | ||
| 81 | - "INTERNAL ERROR:" | ||
| 82 | - " flattenScalarReferences landed at indirect scalar"); | ||
| 83 | - } | ||
| 84 | ObjGen og(node.getObjectID(), node.getGeneration()); | 91 | ObjGen og(node.getObjectID(), node.getGeneration()); |
| 85 | if (visited.count(og) > 0) | 92 | if (visited.count(og) > 0) |
| 86 | { | 93 | { |
qpdf/qtest/qpdf.test
| @@ -77,7 +77,7 @@ flush_tiff_cache(); | @@ -77,7 +77,7 @@ flush_tiff_cache(); | ||
| 77 | show_ntests(); | 77 | show_ntests(); |
| 78 | # ---------- | 78 | # ---------- |
| 79 | $td->notify("--- Miscellaneous Tests ---"); | 79 | $td->notify("--- Miscellaneous Tests ---"); |
| 80 | -$n_tests += 16; | 80 | +$n_tests += 18; |
| 81 | 81 | ||
| 82 | $td->runtest("qpdf version", | 82 | $td->runtest("qpdf version", |
| 83 | {$td->COMMAND => "qpdf --version"}, | 83 | {$td->COMMAND => "qpdf --version"}, |
| @@ -121,6 +121,19 @@ $td->runtest("show new xref stream", | @@ -121,6 +121,19 @@ $td->runtest("show new xref stream", | ||
| 121 | $td->EXIT_STATUS => 0}, | 121 | $td->EXIT_STATUS => 0}, |
| 122 | $td->NORMALIZE_NEWLINES); | 122 | $td->NORMALIZE_NEWLINES); |
| 123 | 123 | ||
| 124 | +# Handle file with object stream containing an unreferenced object | ||
| 125 | +# that in turn contains an indirect scalar (bug 2974522). | ||
| 126 | +$td->runtest("unreferenced indirect scalar", | ||
| 127 | + {$td->COMMAND => | ||
| 128 | + "qpdf --qdf --static-id --object-streams=preserve" . | ||
| 129 | + " unreferenced-indirect-scalar.pdf a.qdf"}, | ||
| 130 | + {$td->STRING => "", | ||
| 131 | + $td->EXIT_STATUS => 0}, | ||
| 132 | + $td->NORMALIZE_NEWLINES); | ||
| 133 | +$td->runtest("check output", | ||
| 134 | + {$td->FILE => "a.qdf"}, | ||
| 135 | + {$td->FILE => "unreferenced-indirect-scalar.out"}); | ||
| 136 | + | ||
| 124 | # Min/Force version | 137 | # Min/Force version |
| 125 | $td->runtest("set min version", | 138 | $td->runtest("set min version", |
| 126 | {$td->COMMAND => "qpdf --min-version=1.6 good1.pdf a.pdf"}, | 139 | {$td->COMMAND => "qpdf --min-version=1.6 good1.pdf a.pdf"}, |
qpdf/qtest/qpdf/unreferenced-indirect-scalar.out
0 → 100644
No preview for this file type
qpdf/qtest/qpdf/unreferenced-indirect-scalar.pdf
0 → 100644
No preview for this file type