diff options
author | 2023-10-15 18:51:09 -0300 | |
---|---|---|
committer | 2023-10-15 18:51:09 -0300 | |
commit | 0cf68e5eab13b31a67ffb241497c36b04479b516 (patch) | |
tree | cc0d377305f013d3f69db1a7db224bc19b3ff018 /packages/bun-uws/src/ChunkedEncoding.h | |
parent | a87aa2fafe05c358455173ea65877be5eefcbd63 (diff) | |
download | bun-ciro/fix-maxRequestBodySize.tar.gz bun-ciro/fix-maxRequestBodySize.tar.zst bun-ciro/fix-maxRequestBodySize.zip |
Diffstat (limited to 'packages/bun-uws/src/ChunkedEncoding.h')
-rw-r--r-- | packages/bun-uws/src/ChunkedEncoding.h | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/packages/bun-uws/src/ChunkedEncoding.h b/packages/bun-uws/src/ChunkedEncoding.h index 55d61b94f..0e0ba437a 100644 --- a/packages/bun-uws/src/ChunkedEncoding.h +++ b/packages/bun-uws/src/ChunkedEncoding.h @@ -29,18 +29,18 @@ namespace uWS { - constexpr uint32_t STATE_HAS_SIZE = 0x80000000; - constexpr uint32_t STATE_IS_CHUNKED = 0x40000000; - constexpr uint32_t STATE_SIZE_MASK = 0x3FFFFFFF; - constexpr uint32_t STATE_IS_ERROR = 0xFFFFFFFF; - constexpr uint32_t STATE_SIZE_OVERFLOW = 0x0F000000; + constexpr uint64_t STATE_HAS_SIZE = 0x8000000000000000; + constexpr uint64_t STATE_IS_CHUNKED = 0x4000000000000000; + constexpr uint64_t STATE_SIZE_MASK = 0x3FFFFFFFFFFFFFFF; + constexpr uint64_t STATE_IS_ERROR = 0xFFFFFFFFFFFFFFFF; + constexpr uint64_t STATE_SIZE_OVERFLOW = 0x0F00000000000000; - inline unsigned int chunkSize(unsigned int state) { + inline uint64_t chunkSize(uint64_t state) { return state & STATE_SIZE_MASK; } /* Reads hex number until CR or out of data to consume. Updates state. Returns bytes consumed. */ - inline void consumeHexNumber(std::string_view &data, unsigned int &state) { + inline void consumeHexNumber(std::string_view &data, uint64_t &state) { /* Consume everything higher than 32 */ while (data.length() && data.data()[0] > 32) { @@ -51,7 +51,7 @@ namespace uWS { digit = (unsigned char) (digit - ('A' - ':')); } - unsigned int number = ((unsigned int) digit - (unsigned int) '0'); + uint64_t number = ((uint64_t) digit - (uint64_t) '0'); if (number > 16 || (chunkSize(state) & STATE_SIZE_OVERFLOW)) { state = STATE_IS_ERROR; @@ -59,7 +59,7 @@ namespace uWS { } // extract state bits - unsigned int bits = /*state &*/ STATE_IS_CHUNKED; + uint64_t bits = /*state &*/ STATE_IS_CHUNKED; state = (state & STATE_SIZE_MASK) * 16u + number; @@ -78,30 +78,30 @@ namespace uWS { } } - inline void decChunkSize(unsigned int &state, unsigned int by) { + inline void decChunkSize(uint64_t &state, uint64_t by) { - //unsigned int bits = state & STATE_IS_CHUNKED; + //uint64_t bits = state & STATE_IS_CHUNKED; state = (state & ~STATE_SIZE_MASK) | (chunkSize(state) - by); //state |= bits; } - inline bool hasChunkSize(unsigned int state) { + inline bool hasChunkSize(uint64_t state) { return state & STATE_HAS_SIZE; } /* Are we in the middle of parsing chunked encoding? */ - inline bool isParsingChunkedEncoding(unsigned int state) { + inline bool isParsingChunkedEncoding(uint64_t state) { return state & ~STATE_SIZE_MASK; } - inline bool isParsingInvalidChunkedEncoding(unsigned int state) { + inline bool isParsingInvalidChunkedEncoding(uint64_t state) { return state == STATE_IS_ERROR; } /* Returns next chunk (empty or not), or if all data was consumed, nullopt is returned. */ - static std::optional<std::string_view> getNextChunk(std::string_view &data, unsigned int &state, bool trailer = false) { + static std::optional<std::string_view> getNextChunk(std::string_view &data, uint64_t &state, bool trailer = false) { while (data.length()) { // if in "drop trailer mode", just drop up to what we have as size @@ -166,7 +166,7 @@ namespace uWS { /* We will consume all our input data */ std::string_view emitSoon; if (chunkSize(state) > 2) { - unsigned int maximalAppEmit = chunkSize(state) - 2; + uint64_t maximalAppEmit = chunkSize(state) - 2; if (data.length() > maximalAppEmit) { emitSoon = data.substr(0, maximalAppEmit); } else { @@ -174,7 +174,7 @@ namespace uWS { emitSoon = data; } } - decChunkSize(state, (unsigned int) data.length()); + decChunkSize(state, (uint64_t) data.length()); state |= STATE_IS_CHUNKED; // new: decrease data by its size (bug) data.remove_prefix(data.length()); // ny bug fix för getNextChunk @@ -194,10 +194,10 @@ namespace uWS { std::string_view *data; std::optional<std::string_view> chunk; - unsigned int *state; + uint64_t *state; bool trailer; - ChunkIterator(std::string_view *data, unsigned int *state, bool trailer = false) : data(data), state(state), trailer(trailer) { + ChunkIterator(std::string_view *data, uint64_t *state, bool trailer = false) : data(data), state(state), trailer(trailer) { chunk = uWS::getNextChunk(*data, *state, trailer); } |