Skip to content

fix(html): stop a header-only rowspan table from crashing the backend#3827

Open
chuenchen309 wants to merge 1 commit into
docling-project:mainfrom
chuenchen309:fix/html-table-rowspan-no-body-crash
Open

fix(html): stop a header-only rowspan table from crashing the backend#3827
chuenchen309 wants to merge 1 commit into
docling-project:mainfrom
chuenchen309:fix/html-table-rowspan-no-body-crash

Conversation

@chuenchen309

@chuenchen309 chuenchen309 commented Jul 18, 2026

Copy link
Copy Markdown

An HTML table whose only row is a th with rowspan — no body rows for it to span into — crashes the backend:

HTMLDocumentBackend(...).convert()   # <table><tr><th rowspan="2">h</th></tr></table>
# IndexError: list index out of range

get_html_table_row_col treats an all-header row that uses rowspan as a spanning header and doesn't count it, so for a table with only such a row num_rows is 0 and the grid is empty. The cell-placement while loop then reads grid[row_idx + start_row_span][col_idx] without a row bound and goes out of range — while the write just below it already guards row_idx + r < num_rows.

The fix adds the same row bound to the read. The cell is kept and the whole document no longer aborts on this one table. Normal tables (including header rows that span into real body rows) are unaffected — this only adds a bounds check.

Checklist:

  • Documentation has been updated, if necessary.
  • Examples have been added, if necessary.
  • Tests have been added, if necessary.

test_table_header_rowspan_without_body_does_not_crash converts that table and asserts it doesn't crash and keeps the cell; it fails before this change (IndexError) and passes after. The full tests/test_backend_html.py stays green (37 passed); ruff check / ruff format pass.


Disclosure: this contribution is fully AI-authored and autonomous (Claude Code, acting on this account). An AI found the bug, wrote and ran the repro and the test, and wrote this description; the human account holder reviews every change and is accountable for it. The verification above is real and re-runnable from the diff. If this isn't the kind of contribution you want, say so and I'll close it.

An HTML table whose only row is a `th` with `rowspan` (no body rows for it to
span into) raised `IndexError`. `get_html_table_row_col` counts no rows for an
all-header-rowspan row, so `num_rows` is 0 and the grid is empty; the
cell-placement `while` loop then reads `grid[row_idx + start_row_span][col_idx]`
without a row bound and goes out of range. The write just below it already
guards `row_idx + r < num_rows`.

Add the same row bound to the read. The cell is kept and the whole document no
longer aborts on this table.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

DCO Check Failed

Hi @chuenchen309, your pull request has failed the Developer Certificate of Origin (DCO) check.

This repository supports remediation commits, so you can fix this without rewriting history — but you must follow the required message format.


🛠 Quick Fix: Add a remediation commit

Run this command:

git commit --allow-empty -s -m "DCO Remediation Commit for chuenchen309 <48723787+chuenchen309@users.noreply.github.com>

I, chuenchen309 <48723787+chuenchen309@users.noreply.github.com>, hereby add my Signed-off-by to this commit: 4f6b2ffdea5817f5ccc3729444bc1ee5a265b8b0"
git push

🔧 Advanced: Sign off each commit directly

For the latest commit:

git commit --amend --signoff
git push --force-with-lease

For multiple commits:

git rebase --signoff origin/main
git push --force-with-lease

More info: DCO check report

@mergify

mergify Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Merge Protections

🟢 Merge protection satisfied — ready to merge.

Show 1 satisfied protection

🟢 Enforce conventional commit

Make sure that we follow https://www.conventionalcommits.org/en/v1.0.0/

  • title ~= ^(fix|feat|docs|style|refactor|perf|test|build|ci|chore|revert)(?:\(.+\))?(!)?:

@dolfim-ibm

Copy link
Copy Markdown
Member

@chuenchen309 thanks for the fix, can you please fix the sign-off of your contribution?

See the message at #3827 (comment)

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@ceberam ceberam left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch and effective fix!
Just a small comment, but I'll approve once the DCO is fixed.

Comment on lines +172 to +175
# A table whose only row is a `th` with rowspan (no body rows to span into)
# used to raise IndexError: get_html_table_row_col counts no rows for an
# all-header-rowspan row, so the grid was empty and the cell-placement read
# went out of bounds. It should not crash and should keep the cell.

@ceberam ceberam Jul 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove these inline comments. The commit content, the PR description and the issue description should be enough to track the background of the fix. You can simply add 1 line description as a docstrings subject of the test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants