flag out-of-range Content-Length in get_header_value_u64

This commit is contained in:
Sayed Kaif authored and yhirose committed 2026-07-18 18:29:16 -04:00
1 parent 255c075b82
commit 982235c0a9
2 files changed
+32 -1

No files matched your search

+12 -1
View File
@@ -2957,7 +2957,18 @@ inline size_t get_header_value_u64(const Headers &headers,
std::advance(it, static_cast<ssize_t>(id));
if (it != rng.second) {
if (is_numeric(it->second)) {
return static_cast<size_t>(std::strtoull(it->second.data(), nullptr, 10));
errno = 0;
auto val = std::strtoull(it->second.data(), nullptr, 10);
auto result = static_cast<size_t>(val);
// strtoull saturates to ULLONG_MAX on overflow, and the size_t cast
// truncates a value that doesn't fit (a Content-Length above 2^32 wraps
// to a small length on 32-bit builds). Either way the framing length
// would be wrong, so flag it rather than return a bogus size.
if (errno == ERANGE || static_cast<unsigned long long>(result) != val) {
is_invalid_value = true;
return (std::numeric_limits<size_t>::max)();
}
return result;
} else {
is_invalid_value = true;
}