Commit a77f58142d07c5482c90f5ce0e3dbb9c98451c2a

Authored by Jay Berkenbilt
1 parent 3f05429c

Remove some assertions that are not necessarily true (fixes #514)

Operations that add the same object to multiple places in the pages
tree are throwing exceptions and then later causing assertion
failures. The assert calls shouldn't be there.
Showing 2 changed files with 27 additions and 4 deletions
1 Document-level work 1 Document-level work
2 =================== 2 ===================
3 3
  4 +* Implement the tree helper described in the ABI section and provide
  5 + the getPagesTree method so QPDF::getAllPages can be deprecated in
  6 + 10.4 and people have time to transition before qpdf 11. Maybe I
  7 + should have a qpdf 11 branch so I can make sure I have the
  8 + interfaces the way I want them before releasing 10.4.
  9 +
4 * QPDFPageCopier -- object for moving pages around within files or 10 * QPDFPageCopier -- object for moving pages around within files or
5 between files and performing various transformations 11 between files and performing various transformations
6 12
@@ -182,6 +188,25 @@ Comments appear in the code prefixed by "ABI" @@ -182,6 +188,25 @@ Comments appear in the code prefixed by "ABI"
182 before copying, though maybe we don't because it could cause 188 before copying, though maybe we don't because it could cause
183 multiple copies to be made...usually it's better to handle that 189 multiple copies to be made...usually it's better to handle that
184 explicitly. 190 explicitly.
  191 +* (Also API) Create a helper class for tree structures like the pages
  192 + tree that have /Kids and /Count. It would be great to be able to
  193 + eliminate flattenPagesTree and all the page object to page caching,
  194 + and to get rid of getAllPages() that returns a reference to an
  195 + internal data structure. The tree helper object can have
  196 + bidirectional iterator and const_iterator, implement at and
  197 + operator[], and have reasonable insertion and deletion semantics.
  198 + Then a new getAllPages, perhaps getPagesTree, can return that and
  199 + make it easy to change existing code even if it assumes the result
  200 + of getAllPages() is mutating automatically as the pages tree is
  201 + manipulated. This will free us up to finally get rid of the
  202 + troublesome pages cache and its exposure by getAllPages. See also
  203 + note below with "balance the pages tree". Maybe we can get rid of
  204 + pageobj_to_pages_pos as well or convert it into something that is
  205 + merely advisory and not so heavily trusted. We should either make
  206 + the code not care if the same object appears more than once in the
  207 + pages tree or detect it and shallow copy, though the latter would
  208 + cause a significant performance penalty when manipulating pages if
  209 + we get rid of the cache.
185 210
186 Page splitting/merging 211 Page splitting/merging
187 ====================== 212 ======================
@@ -334,6 +359,8 @@ directory or that are otherwise not publicly accessible. This includes @@ -334,6 +359,8 @@ directory or that are otherwise not publicly accessible. This includes
334 things sent to me by email that are specifically not public. Even so, 359 things sent to me by email that are specifically not public. Even so,
335 I find it useful to make reference to them in this list. 360 I find it useful to make reference to them in this list.
336 361
  362 + * Get rid of remaining assert() calls from non-test code.
  363 +
337 * Consider updating the fuzzer with code that exercises 364 * Consider updating the fuzzer with code that exercises
338 copyAnnotations, file attachments, and name and number trees. Check 365 copyAnnotations, file attachments, and name and number trees. Check
339 fuzzer coverage. 366 fuzzer coverage.
libqpdf/QPDF_pages.cc
@@ -255,13 +255,11 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos) @@ -255,13 +255,11 @@ QPDF::insertPage(QPDFObjectHandle newpage, int pos)
255 int npages = kids.getArrayNItems(); 255 int npages = kids.getArrayNItems();
256 pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); 256 pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages));
257 this->m->all_pages.insert(this->m->all_pages.begin() + pos, newpage); 257 this->m->all_pages.insert(this->m->all_pages.begin() + pos, newpage);
258 - assert(this->m->all_pages.size() == QIntC::to_size(npages));  
259 for (int i = pos + 1; i < npages; ++i) 258 for (int i = pos + 1; i < npages; ++i)
260 { 259 {
261 insertPageobjToPage(this->m->all_pages.at(toS(i)), i, false); 260 insertPageobjToPage(this->m->all_pages.at(toS(i)), i, false);
262 } 261 }
263 insertPageobjToPage(newpage, pos, true); 262 insertPageobjToPage(newpage, pos, true);
264 - assert(this->m->pageobj_to_pages_pos.size() == QIntC::to_size(npages));  
265 } 263 }
266 264
267 void 265 void
@@ -280,9 +278,7 @@ QPDF::removePage(QPDFObjectHandle page) @@ -280,9 +278,7 @@ QPDF::removePage(QPDFObjectHandle page)
280 int npages = kids.getArrayNItems(); 278 int npages = kids.getArrayNItems();
281 pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages)); 279 pages.replaceKey("/Count", QPDFObjectHandle::newInteger(npages));
282 this->m->all_pages.erase(this->m->all_pages.begin() + pos); 280 this->m->all_pages.erase(this->m->all_pages.begin() + pos);
283 - assert(this->m->all_pages.size() == QIntC::to_size(npages));  
284 this->m->pageobj_to_pages_pos.erase(page.getObjGen()); 281 this->m->pageobj_to_pages_pos.erase(page.getObjGen());
285 - assert(this->m->pageobj_to_pages_pos.size() == QIntC::to_size(npages));  
286 for (int i = pos; i < npages; ++i) 282 for (int i = pos; i < npages; ++i)
287 { 283 {
288 insertPageobjToPage(this->m->all_pages.at(toS(i)), i, false); 284 insertPageobjToPage(this->m->all_pages.at(toS(i)), i, false);