Repository navigation
fix: clamp page_range bounds to sys.maxsize - #4980
Conversation
A page_range end above int64 max, e.g. (1, 2**63) which is what the default (1, sys.maxsize) becomes after a JavaScript JSON round-trip, passed validation and then crashed the docling-parse backend with 'TypeError: incompatible function arguments' from the native binding. Clamp both bounds in the PageRange validator and, as defense in depth, at the docling-parse load call. 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 The PR clamps Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
The |
There was a problem hiding this comment.
AI first review (advisory): no blocker found
This review covers the full diff at 4d96c9c096. It read the code and did not run it.
The change correctly clamps page range bounds to sys.maxsize in PageRange validation and in the docling-parse backend load call, with full test coverage.
A maintainer makes the merge decision. This review never approves the pull request.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Problem
_validate_page_rangeonly checksstart >= 1andend >= start, so a request withpage_range=[1, 9223372036854776000]passes validation. That value is the default(1, sys.maxsize)after a JavaScript JSON round-trip (Swagger UI, Node clients), and it equals 2^63, one above int64 max. The docling-parse backend then hands it toDoclingThreadedPdfParser.load(), and the nanobind binding rejects it:This was seen in docling-serve. Short documents are converted with the request's raw
page_rangeand fail on every attempt. Longer documents get sliced and clamped to the page count, so they happen to work.Fix
PageRangevalidator indocling/datamodel/settings.pynow clamps both bounds tosys.maxsize. The existing checks are unchanged.ThreadedDoclingParseDocumentBackendload call also clamps, for callers that buildDocumentLimitswithout validation (e.g.model_construct).Tests
tests/test_settings_load.py::test_page_range_clamped_to_maxsize:(1, 2**63)becomes(1, sys.maxsize); normal ranges are unchanged; invalid ranges are still rejected.tests/test_options.py::test_page_range_beyond_int64: a 1-page PDF converted throughDocumentConverterwith the docling-parse backend andpage_range=(1, 2**63)succeeds.Both tests fail on
main(the second with theTypeErrorabove) and pass with this change.