Repository navigation
fix(nemotron-parse): bound work on untrusted model output - #4923
Conversation
- Cap \multicolumn and \multirow spans before the span grid is built. A span of 10^7 took 13 s and 1.2 GB; larger values exhaust memory. - Read a code span's opening backtick run atomically in _MARKDOWN_ESCAPE_PATTERN. An unclosed run took cubic time (2000 backticks: 15 s) in the Nemotron 3.5 and dots mappers. - Escape LaTeX table cell text before the HTML table is built, and keep only inline formatting tags. Cell text could add rows, cells and spans to the table. Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
|
✅ DCO Check Passed Thanks @dolfim-ibm, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit Warning The AI analysis did not finish. Only the deterministic checks are shown. CI safety: not assessed. Possibly related pull requests
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 47d058e974. It read the code and did not run it.
I found no defect that should stop the merge. I read the span cap, the cell escaping, and the atomic backtick regex against the base helpers _add_html_table and _markdown_inline_html, and they hold. The span cap of 1001 always trips the existing grid check in docling/utils/chandra_utils.py. A raw & always splits the cell first, so the new escaping cannot double-escape an entity.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…trusted-output Signed-off-by: Michele Dolfi <dol@zurich.ibm.com>
- Map LaTeX text commands and escape cell text in one pass.
\textless{}b\textgreater{} became a <b> tag, because the commands
became raw < and > before the escape.
- Keep <code> as an inline cell tag.
- Stop a row above _MAX_TABLE_GRID_CELLS columns before the span grid
is built. 2000 spans of 1000 columns used 511 MB.
Signed-off-by: Christoph Auer <cau@zurich.ibm.com>
|
I pushed ab7c550 with three fixes on top of this PR:
One limit remains: in a cell that also has |
Follow-up to #4897. The mapper reads model output, which document content can steer, and which a remote server sends when the API engine is used. Three inputs used too much time or memory, or changed the table structure.
Changes
nemotron_parse_v3_5_utils._span):\multicolumnand\multirowspans are capped at_MAX_TABLE_GRID_CELLS + 1before the span grid is built. Before this fix,\multicolumn{10000000}{c}{x}(about 100 characters) took 13 s and 1.2 GB, and larger values exhaust memory. A table above the limit becomes an empty table, as before.dots_utils._MARKDOWN_ESCAPE_PATTERN): the regex now reads the opening backtick run of a code span atomically ((?=(+))\1`, Python 3.10-compatible) and only at the start of a run. Before this fix, an unclosed run took cubic time: 2000 backticks took 15 s in both the Nemotron 3.5 and dots mappers. Now 20000 backticks take about 1 ms.latex_tabular_to_html): cell text is HTML-escaped before the table HTML is built. Only inline formatting tags (b,br,em,i,strong,sub,sup,u) stay as markup. Before this fix, a cell such asa</td></tr><tr><td colspan="9">badded a row and a span to the table.Checklist:
Review evidence:
test_table_with_oversized_span_is_rejected_without_building_it,test_table_cell_markup_stays_cell_text, and twotest_literal_markers_stay_literalcases (a nested code span and a 5000-backtick unclosed run).test_table_cell_markup_stays_cell_textfails onmain((2, 10) != (1, 2)). I did not run the span test onmain, because it exhausts memory there.tests/test_nemotron_parse_v3_5.py,tests/test_dots_parser.py,tests/test_chandra_vlm.py: 107 passed.make validatepasses.Limits (not changed here):
_LITERAL_INLINE_PATTERNis still quadratic on many unclosed\(: 20000 of them take about 3 s. This pattern was there before feat: addnvidia/Nemotron-3.5-Parseas supported VLM model #4897.<a href>scheme, includingjavascript:, andexport_to_html()writes it unchanged. This was there before feat: addnvidia/Nemotron-3.5-Parseas supported VLM model #4897; a scheme allowlist belongs in a separate fix.