fix(deepdoc): guard docling crop against missing page images (#17147)

This commit is contained in:
Yurii214
2026-07-24 05:20:06 +02:00
committed by GitHub
parent 74218bdd6a
commit cd9db94daa
2 changed files with 49 additions and 0 deletions

View File

@@ -174,6 +174,26 @@ class DoclingParser(RAGFlowPdfParser):
if not poss:
return (None, None) if need_position else None
# a position tag is emitted even when page rendering failed (__images__ leaves
# page_images empty), and a tag can name a page beyond the rendered range, so
# indexing page_images below would raise IndexError. mirror
# cropout_docling_table and the sibling parsers: bail out when there are no
# page images and drop positions that fall outside them.
if not getattr(self, "page_images", None):
self.logger.warning("[Docling] crop called without page images; skipping image generation.")
return (None, None) if need_position else None
page_count = len(self.page_images)
valid_poss = []
for p in poss:
if p[0] and all(0 <= pn < page_count for pn in p[0]):
valid_poss.append(p)
else:
self.logger.warning(f"[Docling] Position on pages {p[0]} is out of range for {page_count} rendered page(s); skipping it.")
poss = valid_poss
if not poss:
return (None, None) if need_position else None
GAP = 6
pos = poss[0]
poss.insert(0, ([pos[0][0]], pos[1], pos[2], max(0, pos[3] - 120), max(pos[3] - GAP, 0)))