← Back to Pull requests

fix(docx): clamp the declared table cell span to the table limits #5702

Open
unknown opened this pull request with 315 lines diff across 3 files
View on GitHub
unknown unknown commented on Dec 01, 2026 13:47 UTC
Author

<!-- Thank you for contributing to Docling! -->

a docx table lost the whole table, and all the text in it, when one cell declared a huge span. the backend sized the table grid from w:gridSpan, w:gridBefore and w:gridAfter, so a value above max_table_cells made TableData reject the table and the table walk swallowed the error. now each declared value is clamped, the way the pptx, xlsx, html, asciidoc and latex backends already clamp a span

Checklist:

  • Documentation has been updated, if necessary.

  • Examples have been added, if necessary.

  • Tests have been added, if necessary.
  • Review evidence:

    _handle_tables in docling/backend/msword_backend.py reads the cell span with tc.grid_span and the row offsets with row.grid_cols_before and row.grid_cols_after, then sets num_cols to the largest of those sums. a small file can declare 1000001 there. TableData refuses a grid above settings.max_table_cells (1000000), and _walk_linear catches that error with except Exception and only logs it at debug level, so the user gets a document with no table and none of the text from that table, and no message

    AGENTS.md says a declared value such as a colspan must be limited, and names clamp_span. the pptx backend does that since #5603, and the xlsx, html, asciidoc and latex backends use it too. the docx backend was the only one that did not

    i converted a real .docx (a plain 2x2 table with one extra attribute) with a real DocumentConverter:

    master:

    tables=0  markdown=''
    

    this PR:

    tables=1  dims=[(2, 1000)]  cells=['r0c0', 'r0c1', 'r1c0', 'r1c1']
    

    the same holds for w:gridBefore, which names a row that starts late

    a normal table is unchanged, and a span that is wider than the declared grid is still honoured, as test_table_with_incomplete_grid expects. only the values above the limits move

    Checks:

  • pytest tests/test_backend_msword.py -> 125 passed, 14 failed, 13 errors. the 14 failures and the 13 errors are the ones master gives in this sandbox as well, they need LibreOffice, which is not installed here

  • ruff format --check and ruff check on both files -> clean

  • with the source change reverted, both new tests fail (len(doc.tables) == 0) and they pass with it
  • note: 26 open PRs touch docling/backend/msword_backend.py or tests/test_backend_msword.py, and #4716, #4587 and #4369 are within 50 added lines of this change. none of them fixes a declared table span, so the overlap is in file position only

    Diff: 315 lines (+236 / -79) across 3 files Reviewer: 1AbdullahButt Review duration: 451m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.40) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 315 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.344
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #5702"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.4% (MEDIUM) · Higher = larger blast radius
    40.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 21.5% · Safe to merge
    21.5%