mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 17:28:29 +00:00
BUGFIX: crash when "content-length" > max_int
This commit is contained in:
parent
5d082f1da4
commit
07ed076499
1 changed files with 10 additions and 1 deletions
11
httplib.h
11
httplib.h
|
@ -788,6 +788,15 @@ inline int get_header_value_int(const Headers &headers, const char *key,
|
||||||
return def;
|
return def;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline unsigned long long get_header_value_uint64(const Headers &headers, const char *key,
|
||||||
|
int def = 0) {
|
||||||
|
auto it = headers.find(key);
|
||||||
|
if (it != headers.end()) {
|
||||||
|
return std::strtoull(it->second.data(), nullptr, 10);
|
||||||
|
}
|
||||||
|
return def;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool read_headers(Stream &strm, Headers &headers) {
|
inline bool read_headers(Stream &strm, Headers &headers) {
|
||||||
static std::regex re(R"((.+?):\s*(.+?)\s*\r\n)");
|
static std::regex re(R"((.+?):\s*(.+?)\s*\r\n)");
|
||||||
|
|
||||||
|
@ -881,7 +890,7 @@ inline bool read_content_chunked(Stream &strm, std::string &out) {
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool read_content(Stream &strm, T &x, Progress progress = Progress()) {
|
bool read_content(Stream &strm, T &x, Progress progress = Progress()) {
|
||||||
if (has_header(x.headers, "Content-Length")) {
|
if (has_header(x.headers, "Content-Length")) {
|
||||||
auto len = get_header_value_int(x.headers, "Content-Length", 0);
|
auto len = get_header_value_uint64(x.headers, "Content-Length", 0);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
const auto &encoding =
|
const auto &encoding =
|
||||||
get_header_value(x.headers, "Transfer-Encoding", 0, "");
|
get_header_value(x.headers, "Transfer-Encoding", 0, "");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue