From 962b6cc2c2b2b0e152c7e99c2d77c0858047d794 Mon Sep 17 00:00:00 2001 From: Brian Olsen Date: Fri, 12 Jun 2026 09:26:43 -0600 Subject: [PATCH] Fix bounds check in CacheVC::scanObject --- src/iocore/cache/CacheVC.cc | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/iocore/cache/CacheVC.cc b/src/iocore/cache/CacheVC.cc index 821dce534a3..83bc9ea8d6a 100644 --- a/src/iocore/cache/CacheVC.cc +++ b/src/iocore/cache/CacheVC.cc @@ -766,9 +766,17 @@ CacheVC::scanObject(int /* event ATS_UNUSED */, Event * /* e ATS_UNUSED */) } break; } - if (doc->data() - buf->data() > static_cast(io.aiocb.aio_nbytes)) { - might_need_overlap_read = true; - goto Lskip; + { + size_t const doc_off = reinterpret_cast(doc) - buf->data(); + // Bounds-check in unsigned domain: doc must lie within the + // buffer, with room for the Doc header, and doc->hlen must + // fit in the remaining bytes before doc->hdr() and + // HTTPInfo::unmarshal walk it. + if (io.aiocb.aio_nbytes < doc_off || (io.aiocb.aio_nbytes - doc_off) < sizeof(Doc) || + (io.aiocb.aio_nbytes - doc_off - sizeof(Doc)) < doc->hlen) { + might_need_overlap_read = true; + goto Lskip; + } } { char *tmp = doc->hdr();