Skip to content

Commit

Permalink
Allow huge content-lengths
Browse files Browse the repository at this point in the history
  • Loading branch information
uNetworkingAB committed Dec 26, 2023
1 parent e039428 commit 05fe5bc
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/HttpParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,19 @@ struct HttpParser {
uint64_t remainingStreamingBytes = 0;

/* Returns UINT_MAX on error. Maximum 999999999 is allowed. */
static unsigned int toUnsignedInteger(std::string_view str) {
/* We assume at least 32-bit integer giving us safely 999999999 (9 number of 9s) */
if (str.length() > 9) {
static uint64_t toUnsignedInteger(std::string_view str) {
/* We assume at least 64-bit integer giving us safely 999999999999999999 (18 number of 9s) */
if (str.length() > 18) {
return UINT_MAX;
}

unsigned int unsignedIntegerValue = 0;
uint64_t unsignedIntegerValue = 0;
for (char c : str) {
/* As long as the letter is 0-9 we cannot overflow. */
if (c < '0' || c > '9') {
return UINT_MAX;
}
unsignedIntegerValue = unsignedIntegerValue * 10u + ((unsigned int) c - (unsigned int) '0');
unsignedIntegerValue = unsignedIntegerValue * 10ull + ((unsigned int) c - (unsigned int) '0');
}
return unsignedIntegerValue;
}
Expand Down

0 comments on commit 05fe5bc

Please sign in to comment.