Skip to content

fix: clamp page_range bounds to sys.maxsize - #4980

Merged
dolfim-ibm merged 1 commit into
mainfrom
fix/clamp-page-range-int64
Oct 23, 2026
Merged

dolfim-ibm merged 1 commit into
mainfrom
fix/clamp-page-range-int64

Conversation

@dolfim-ibm

@dolfim-ibm dolfim-ibm commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

Problem

_validate_page_range only checks start >= 1 and end >= start, so a request with page_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 to DoclingThreadedPdfParser.load(), and the nanobind binding rejects it:

TypeError: load_document_from_bytesio(): incompatible function arguments

This was seen in docling-serve. Short documents are converted with the request's raw page_range and fail on every attempt. Longer documents get sliced and clamped to the page count, so they happen to work.

Fix

  • The PageRange validator in docling/datamodel/settings.py now clamps both bounds to sys.maxsize. The existing checks are unchanged.
  • The ThreadedDoclingParseDocumentBackend load call also clamps, for callers that build DocumentLimits without 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 through DocumentConverter with the docling-parse backend and page_range=(1, 2**63) succeeds.

Both tests fail on main (the second with the TypeError above) and pass with this change.

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>
@github-actions

Copy link
Copy Markdown
Contributor

✅ DCO Check Passed

Thanks @dolfim-ibm, all your commits are properly signed off. 🎉

@mergify

mergify Bot commented Oct 22, 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)(?:\(.+\))?(!)?:

@github-actions github-actions Bot added ai:ci-safe AI triage found no CI-safety concern (advisory) bug Something isn't working pdf parsing PDF issue related to docling-parse labels Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

AI triage (advisory)

Checked commit 4d96c9c096. The analysis read the diff only. It did not run code from this pull request.

The PR clamps page_range bounds to sys.maxsize in the PageRange validator and in the ThreadedDoclingParseDocumentBackend load call. This stops the native binding from rejecting values such as 2**63. It adds two tests.

Topic labels added: bug, pdf parsing.

CI safety: no concern found. A maintainer must still approve CI.

1 related pull request(s) in the same code
PR State Signal Assessment
#4833 open changes the same code related: Both PRs edit the ThreadedDoclingParseDocumentBackend load code in docling_parse_backend.py. PR 4833 adds password-error detection in the failure path. This PR clamps page_range in the load call. The two changes solve different problems.

The ai:* labels are advisory. They do not approve CI and they do not add tests:full. A new push runs this check again.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@github-actions github-actions Bot added the ai:review-lgtm AI first review found no blocker or major issue (advisory) label Oct 22, 2026
@codecov

codecov Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@dolfim-ibm
dolfim-ibm merged commit 0db3aea into main Oct 23, 2026
33 checks passed
@dolfim-ibm
dolfim-ibm deleted the fix/clamp-page-range-int64 branch October 23, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai:ci-safe AI triage found no CI-safety concern (advisory) ai:review-lgtm AI first review found no blocker or major issue (advisory) bug Something isn't working pdf parsing PDF issue related to docling-parse

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants