From b7c2f043188ecb544718a849bb2ab634ee241164 Mon Sep 17 00:00:00 2001 From: yhirose Date: Thu, 25 Dec 2025 22:19:37 -0500 Subject: [PATCH] Fix potential arithmatic overflow problem --- httplib.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/httplib.h b/httplib.h index 92a4369..c3e768f 100644 --- a/httplib.h +++ b/httplib.h @@ -8957,7 +8957,16 @@ inline bool Server::read_content(Stream &strm, Request &req, Response &res) { strm, req, res, // Regular [&](const char *buf, size_t n) { - if (req.body.size() + n > req.body.max_size()) { return false; } + // Prevent arithmetic overflow when checking sizes. + // Avoid computing (req.body.size() + n) directly because + // adding two unsigned `size_t` values can wrap around and + // produce a small result instead of indicating overflow. + // Instead, check using subtraction: ensure `n` does not + // exceed the remaining capacity `max_size() - size()`. + if (req.body.size() >= req.body.max_size() || + n > req.body.max_size() - req.body.size()) { + return false; + } req.body.append(buf, n); return true; },