diff --git a/scripts/sync_vendor.py b/scripts/sync_vendor.py index 467a06608..274b06440 100755 --- a/scripts/sync_vendor.py +++ b/scripts/sync_vendor.py @@ -5,7 +5,7 @@ import os import sys import subprocess -HTTPLIB_VERSION = "refs/tags/v0.43.3" +HTTPLIB_VERSION = "refs/tags/v0.43.4" vendor = { "https://github.com/nlohmann/json/releases/latest/download/json.hpp": "vendor/nlohmann/json.hpp", diff --git a/vendor/cpp-httplib/httplib.cpp b/vendor/cpp-httplib/httplib.cpp index cb8ea9742..024e9a3d5 100644 --- a/vendor/cpp-httplib/httplib.cpp +++ b/vendor/cpp-httplib/httplib.cpp @@ -8980,10 +8980,22 @@ ssize_t ChunkedDecoder::read_payload(char *buf, size_t len, stream_line_reader lr(strm, line_buf, sizeof(line_buf)); if (!lr.getline()) { return -1; } - char *endptr = nullptr; - unsigned long chunk_len = std::strtoul(lr.ptr(), &endptr, 16); - if (endptr == lr.ptr()) { return -1; } - if (chunk_len == ULONG_MAX) { return -1; } + // RFC 9112 ยง7.1: chunk-size = 1*HEXDIG + const char *p = lr.ptr(); + int v = 0; + if (!is_hex(*p, v)) { return -1; } + + size_t chunk_len = 0; + constexpr size_t chunk_len_max = (std::numeric_limits::max)(); + for (; is_hex(*p, v); ++p) { + if (chunk_len > (chunk_len_max >> 4)) { return -1; } + chunk_len = (chunk_len << 4) | static_cast(v); + } + + while (is_space_or_tab(*p)) { + ++p; + } + if (*p != '\0' && *p != ';' && *p != '\r' && *p != '\n') { return -1; } if (chunk_len == 0) { chunk_remaining = 0; @@ -8993,7 +9005,7 @@ ssize_t ChunkedDecoder::read_payload(char *buf, size_t len, return 0; } - chunk_remaining = static_cast(chunk_len); + chunk_remaining = chunk_len; last_chunk_total = chunk_remaining; last_chunk_offset = 0; } diff --git a/vendor/cpp-httplib/httplib.h b/vendor/cpp-httplib/httplib.h index 8d3c4c2c5..25dc7fee7 100644 --- a/vendor/cpp-httplib/httplib.h +++ b/vendor/cpp-httplib/httplib.h @@ -8,8 +8,8 @@ #ifndef CPPHTTPLIB_HTTPLIB_H #define CPPHTTPLIB_HTTPLIB_H -#define CPPHTTPLIB_VERSION "0.43.3" -#define CPPHTTPLIB_VERSION_NUM "0x002b03" +#define CPPHTTPLIB_VERSION "0.43.4" +#define CPPHTTPLIB_VERSION_NUM "0x002b04" #ifdef _WIN32 #if defined(_WIN32_WINNT) && _WIN32_WINNT < 0x0A00