Skip to content

Fix bounds check in CacheVC::scanObject#13263

Open
traeak wants to merge 1 commit into
apache:masterfrom
traeak:cache_scan_doc_hlen
Open

Fix bounds check in CacheVC::scanObject#13263
traeak wants to merge 1 commit into
apache:masterfrom
traeak:cache_scan_doc_hlen

Conversation

@traeak

@traeak traeak commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Fix bounds check in CacheVC::scanObject, requires on disk corruption.

The prior check compared doc->data() - buf->data() against io.aiocb.aio_nbytes cast to int. The pointer arithmetic could wrap when doc->hlen (read from disk) was very large, and the int cast truncated size_t buffer sizes, so the check could pass while doc->hdr() and the subsequent HTTPInfo::unmarshal walked memory past the I/O buffer.

Re-express the check in the unsigned size_t domain and validate doc->hlen directly against the bytes remaining after the Doc header, guarding each subtraction so it cannot underflow.

Copilot AI review requested due to automatic review settings June 12, 2026 15:30
@traeak traeak self-assigned this Jun 12, 2026
@traeak traeak added the Cache label Jun 12, 2026

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.

Pull request overview

This PR hardens cache object scanning in CacheVC::scanObject by rewriting a bounds check to avoid signed overflow/truncation and ensuring doc->hdr() / HTTPInfo::unmarshal cannot walk past the end of the AIO read buffer when doc->hlen is corrupt or maliciously large.

Changes:

  • Replace the prior pointer-difference/int-cast bounds check with size_t-domain validation.
  • Add guarded subtractions to ensure Doc header and doc->hlen fit within the bytes remaining in the read buffer before unmarshalling.

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants