Commit ec48820c3cf8ead0add464c60f5dddd84ba0097d

Authored by Jay Berkenbilt
1 parent 258675fc

Fix loop detection in NNTree

libqpdf/NNTree.cc
@@ -450,8 +450,8 @@ NNTreeIterator::split(QPDFObjectHandle to_split, @@ -450,8 +450,8 @@ NNTreeIterator::split(QPDFObjectHandle to_split,
450 450
451 // CURRENT STATE: half the items from the kids or items array in 451 // CURRENT STATE: half the items from the kids or items array in
452 // the node being split have been moved into a new node. The new 452 // the node being split have been moved into a new node. The new
453 - // node is not yet attached to the tree. The iterator have a path  
454 - // element or leaf node that is out of bounds. 453 + // node is not yet attached to the tree. The iterator may have a
  454 + // path element or leaf node that is out of bounds.
455 455
456 // We need to adjust the parent to add the second node to /Kids 456 // We need to adjust the parent to add the second node to /Kids
457 // and, if needed, update kid_number to traverse through it. We 457 // and, if needed, update kid_number to traverse through it. We
@@ -748,6 +748,13 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty) @@ -748,6 +748,13 @@ NNTreeIterator::deepen(QPDFObjectHandle node, bool first, bool allow_empty)
748 bool failed = false; 748 bool failed = false;
749 749
750 std::set<QPDFObjGen> seen; 750 std::set<QPDFObjGen> seen;
  751 + for (auto i: this->path)
  752 + {
  753 + if (i.node.isIndirect())
  754 + {
  755 + seen.insert(i.node.getObjGen());
  756 + }
  757 + }
751 while (! failed) 758 while (! failed)
752 { 759 {
753 if (node.isIndirect()) 760 if (node.isIndirect())
qpdf/qtest/qpdf/name-tree.pdf
@@ -288,7 +288,8 @@ endobj @@ -288,7 +288,8 @@ endobj
288 << 288 <<
289 /Limits [ (E) (Z) ] 289 /Limits [ (E) (Z) ]
290 /Kids [ 290 /Kids [
291 - 30 0 R 291 + 27 0 R
  292 + 37 0 R
292 ] 293 ]
293 >> 294 >>
294 endobj 295 endobj
@@ -350,8 +351,17 @@ endobj @@ -350,8 +351,17 @@ endobj
350 >> 351 >>
351 endobj 352 endobj
352 353
  354 +37 0 obj
  355 +<<
  356 + /Limits [ (E) (Z) ]
  357 + /Kids [
  358 + 30 0 R
  359 + ]
  360 +>>
  361 +endobj
  362 +
353 xref 363 xref
354 -0 37 364 +0 38
355 0000000000 65535 f 365 0000000000 65535 f
356 0000000025 00000 n 366 0000000025 00000 n
357 0000000079 00000 n 367 0000000079 00000 n
@@ -383,12 +393,13 @@ xref @@ -383,12 +393,13 @@ xref
383 0000002282 00000 n 393 0000002282 00000 n
384 0000002341 00000 n 394 0000002341 00000 n
385 0000002413 00000 n 395 0000002413 00000 n
386 -0000002483 00000 n  
387 -0000002531 00000 n  
388 -0000002634 00000 n  
389 -0000002718 00000 n  
390 -0000002790 00000 n  
391 -0000002862 00000 n 396 +0000002494 00000 n
  397 +0000002542 00000 n
  398 +0000002645 00000 n
  399 +0000002729 00000 n
  400 +0000002801 00000 n
  401 +0000002873 00000 n
  402 +0000002943 00000 n
392 trailer << 403 trailer <<
393 /Root 1 0 R 404 /Root 1 0 R
394 /QTest 8 0 R 405 /QTest 8 0 R
@@ -400,9 +411,9 @@ trailer &lt;&lt; @@ -400,9 +411,9 @@ trailer &lt;&lt;
400 /Bad4 23 0 R 411 /Bad4 23 0 R
401 /Bad5 28 0 R 412 /Bad5 28 0 R
402 /Bad6 31 0 R 413 /Bad6 31 0 R
403 - /Size 37 414 + /Size 38
404 /ID [<2c3b7a6ec7fc61db8a5db4eebf57f540><2c3b7a6ec7fc61db8a5db4eebf57f540>] 415 /ID [<2c3b7a6ec7fc61db8a5db4eebf57f540><2c3b7a6ec7fc61db8a5db4eebf57f540>]
405 >> 416 >>
406 startxref 417 startxref
407 -2932 418 +3013
408 %%EOF 419 %%EOF