Fix that chunk bug
This commit is contained in:
+22
-5
@@ -43,7 +43,12 @@ namespace uWS {
|
|||||||
digit -= ('a' - '9') - 1;
|
digit -= ('a' - '9') - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
state = state * 16u + ((unsigned int) digit - (unsigned int) '0');
|
// extract state bits
|
||||||
|
unsigned int bits = /*state &*/ STATE_IS_CHUNKED;
|
||||||
|
|
||||||
|
state = (state & STATE_SIZE_MASK) * 16u + ((unsigned int) digit - (unsigned int) '0');
|
||||||
|
|
||||||
|
state |= bits;
|
||||||
data.remove_prefix(1);
|
data.remove_prefix(1);
|
||||||
}
|
}
|
||||||
/* Consume everything not /n */
|
/* Consume everything not /n */
|
||||||
@@ -53,7 +58,7 @@ namespace uWS {
|
|||||||
/* Now we stand on \n so consume it and enable size */
|
/* Now we stand on \n so consume it and enable size */
|
||||||
if (data.length()) {
|
if (data.length()) {
|
||||||
state += 2; // include the two last /r/n
|
state += 2; // include the two last /r/n
|
||||||
state |= STATE_HAS_SIZE;
|
state |= STATE_HAS_SIZE | STATE_IS_CHUNKED;
|
||||||
data.remove_prefix(1);
|
data.remove_prefix(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +68,12 @@ namespace uWS {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void decChunkSize(unsigned int &state, unsigned int by) {
|
void decChunkSize(unsigned int &state, unsigned int by) {
|
||||||
|
|
||||||
|
//unsigned int bits = state & STATE_IS_CHUNKED;
|
||||||
|
|
||||||
state = (state & ~STATE_SIZE_MASK) | (chunkSize(state) - by);
|
state = (state & ~STATE_SIZE_MASK) | (chunkSize(state) - by);
|
||||||
|
|
||||||
|
//state |= bits;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasChunkSize(unsigned int state) {
|
bool hasChunkSize(unsigned int state) {
|
||||||
@@ -76,13 +86,17 @@ namespace uWS {
|
|||||||
while (data.length()) {
|
while (data.length()) {
|
||||||
|
|
||||||
// if in "drop trailer mode", just drop up to what we have as size
|
// if in "drop trailer mode", just drop up to what we have as size
|
||||||
if ((state & STATE_IS_CHUNKED) && hasChunkSize(state) && chunkSize(state)) {
|
if (((state & STATE_IS_CHUNKED) == 0) && hasChunkSize(state) && chunkSize(state)) {
|
||||||
|
|
||||||
|
//printf("Parsing trailer now\n");
|
||||||
|
|
||||||
while(data.length() && chunkSize(state)) {
|
while(data.length() && chunkSize(state)) {
|
||||||
data.remove_prefix(1);
|
data.remove_prefix(1);
|
||||||
decChunkSize(state, 1);
|
decChunkSize(state, 1);
|
||||||
|
|
||||||
if (chunkSize(state) == 0) {
|
if (chunkSize(state) == 0) {
|
||||||
|
|
||||||
|
/* This is an actual place where we need 0 as state */
|
||||||
state = 0;
|
state = 0;
|
||||||
|
|
||||||
/* The parser MUST stop consuming here */
|
/* The parser MUST stop consuming here */
|
||||||
@@ -96,8 +110,10 @@ namespace uWS {
|
|||||||
consumeHexNumber(data, state);
|
consumeHexNumber(data, state);
|
||||||
if (hasChunkSize(state) && chunkSize(state) == 2) {
|
if (hasChunkSize(state) && chunkSize(state) == 2) {
|
||||||
|
|
||||||
|
//printf("Setting state to trailer-parsing and emitting empty chunk\n");
|
||||||
|
|
||||||
// set trailer state and increase size to 4
|
// set trailer state and increase size to 4
|
||||||
state = 4 | STATE_IS_CHUNKED | STATE_HAS_SIZE;
|
state = 4 /*| STATE_IS_CHUNKED*/ | STATE_HAS_SIZE;
|
||||||
|
|
||||||
return std::string_view(nullptr, 0);
|
return std::string_view(nullptr, 0);
|
||||||
}
|
}
|
||||||
@@ -115,7 +131,7 @@ namespace uWS {
|
|||||||
shouldEmit = true;
|
shouldEmit = true;
|
||||||
}
|
}
|
||||||
data.remove_prefix(chunkSize(state));
|
data.remove_prefix(chunkSize(state));
|
||||||
state = 0;
|
state = STATE_IS_CHUNKED;
|
||||||
if (shouldEmit) {
|
if (shouldEmit) {
|
||||||
return emitSoon;
|
return emitSoon;
|
||||||
}
|
}
|
||||||
@@ -133,6 +149,7 @@ namespace uWS {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
decChunkSize(state, data.length());
|
decChunkSize(state, data.length());
|
||||||
|
state |= STATE_IS_CHUNKED;
|
||||||
// new: decrease data by its size (bug)
|
// new: decrease data by its size (bug)
|
||||||
data.remove_prefix(data.length()); // ny bug fix för getNextChunk
|
data.remove_prefix(data.length()); // ny bug fix för getNextChunk
|
||||||
if (emitSoon.length()) {
|
if (emitSoon.length()) {
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ void runTest(unsigned int maxConsume) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
//for (int i = 1; i < 1000; i++) {
|
for (int i = 1; i < 1000; i++) {
|
||||||
runTest(1);
|
runTest(i);
|
||||||
//}
|
}
|
||||||
|
|
||||||
std::cout << "ALL BRUTEFORCE DONE" << std::endl;
|
std::cout << "ALL BRUTEFORCE DONE" << std::endl;
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user