Skip to content

Enforce size limit when paged searches are enabled - #445

Merged
HarlemSquirrel merged 4 commits into
ruby-ldap:masterfrom
arianf:fix-paged-search-size-limit
Nov 18, 2026
Merged

HarlemSquirrel merged 4 commits into
ruby-ldap:masterfrom
arianf:fix-paged-search-size-limit

Conversation

@arianf

@arianf arianf commented Jan 31, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the :size option being ignored when paged searches are enabled and the requested size is larger than the page size of 126.

Problem

Each page request carries a sizelimit of 0 (no limit) while 126 or more entries remain, and the exact remainder after that. When the results reach :size exactly at the end of a page, nothing remains, so the next request goes out with a sizelimit of 0 and the server returns everything that's left.

Later page requests also send a different sizelimit from the first one, which RFC 2696 (section 3) says they must not. A server that keeps the first request's limit can return a full page past :size, and the client returned all of it.

Changes

  • Stop requesting pages once :size is reached
  • Stop returning entries once :size is reached, while still reading the rest of the page so the connection stays in sync
  • Moved the per-page sizelimit calculation into a private helper, search_query_limit, as the existing comment suggested
  • Added tests for a size limit that ends on a page boundary and for a server that ignores the smaller sizelimit on the last page

Related: #437, #36

arianf and others added 2 commits January 30, 2026 16:38
When paging is enabled and the requested size exceeds 126, the client now
correctly stops fetching additional pages once the size limit is reached.

Copilot AI 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.

🟡 Changes recommended

Entries can still exceed the documented maximum because the limit is checked only after yielding a complete page.

3 open findings
What changed in this PR

Adds client-side termination for size-limited paged LDAP searches.

Changes:

  • Stops paging after reaching the requested size.
  • Adds a regression test.
  • Updates release history.
File Description
lib/​net/​ldap/​connection.rb Adds paging termination logic.
test/​test_ldap_connection.rb Tests size-limited paging.
History.rdoc Documents the fix.

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread lib/net/ldap/connection.rb Resolved
Comment thread test/test_ldap_connection.rb Resolved
Comment thread lib/net/ldap/connection.rb Resolved
Later page requests send a different sizelimit from the first one, which
RFC 2696 says they must not, so a server can send a full page past the
caller's :size. Also moves the per-page sizelimit calculation into a helper
so search stays within the project's RuboCop metrics.

- Moved the per-page sizelimit calculation into search_query_limit
- Stopped returning entries once :size is reached, still reading the rest of the page
- Replaced the test with page-boundary and over-full last page cases
@arianf

arianf commented Nov 17, 2026

Copy link
Copy Markdown
Contributor Author

@HarlemSquirrel thanks for merging master in. I've pushed afd10f6, which addresses the Copilot review and the RuboCop failures from the last run

@HarlemSquirrel HarlemSquirrel 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.

Thanks!

@HarlemSquirrel
HarlemSquirrel enabled auto-merge (squash) November 18, 2026 01:24
@HarlemSquirrel
HarlemSquirrel merged commit a37704e into ruby-ldap:master Nov 18, 2026
8 checks passed
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