From 47c3d1a2db6245ed4bb234ce1b815c74f7211a64 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 15 Aug 2026 23:38:19 +0000 Subject: [PATCH] Revert "Try fix for consumeHexNumber to improve hex parsing" This reverts commit b9a7c4da61311b96aa04c462a2c9e3f89a4b9ba2. Co-authored-by: uNetworkingAB <110806833+uNetworkingAB@users.noreply.github.com> --- src/ChunkedEncoding.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/src/ChunkedEncoding.h b/src/ChunkedEncoding.h index a83b216a6..5b959ad30 100644 --- a/src/ChunkedEncoding.h +++ b/src/ChunkedEncoding.h @@ -44,28 +44,26 @@ namespace uWS { inline void consumeHexNumber(std::string_view &data, uint64_t &state) { /* Consume everything higher than 32 */ while (data.length() && data.data()[0] > 32) { - + unsigned char digit = (unsigned char)data.data()[0]; - unsigned int number; - - if (digit >= '0' && digit <= '9') { - number = (unsigned int) (digit - '0'); - } else if (digit >= 'a' && digit <= 'f') { - number = (unsigned int) (digit - 'a') + 10; - } else if (digit >= 'A' && digit <= 'F') { - number = (unsigned int) (digit - 'A') + 10; - } else { - /* Not a hex digit: chunk-size token ends here (chunk-ext follows) */ - break; + if (digit >= 'a') { + digit = (unsigned char) (digit - ('a' - ':')); + } else if (digit >= 'A') { + digit = (unsigned char) (digit - ('A' - ':')); } - - if (chunkSize(state) & STATE_SIZE_OVERFLOW) { + + unsigned int number = ((unsigned int) digit - (unsigned int) '0'); + + if (number > 16 || (chunkSize(state) & STATE_SIZE_OVERFLOW)) { state = STATE_IS_ERROR; return; } - - uint64_t bits = STATE_IS_CHUNKED; + + // extract state bits + uint64_t bits = /*state &*/ STATE_IS_CHUNKED; + state = (state & STATE_SIZE_MASK) * 16ull + number; + state |= bits; data.remove_prefix(1); }