Skip to content

use precise mask to fix bug for part parse lead frame message error #1867

Closed
gubaojian wants to merge 3 commits intouNetworking:masterfrom
gubaojian:feature_unmaskPreciseCopyMask
Closed

use precise mask to fix bug for part parse lead frame message error #1867
gubaojian wants to merge 3 commits intouNetworking:masterfrom
gubaojian:feature_unmaskPreciseCopyMask

Conversation

@gubaojian
Copy link
Contributor

@gubaojian gubaojian commented Jun 23, 2025

use precise mask to fix bug for part parse lead frame message error.
here is the test code, you can use the code and the data in zip file to Reproduce the bug :
one_frame.dat.zip

`

int main() {
   std::string framedata =   FileUtils::readFile("/Users/baojian/code/ServerTechTest/jwt/cplus/MaskTest/CopyTest/one_frame.dat", true);

std::string two;
two.append(framedata);
two.append(framedata);

uWS::WebSocketProtocol<true, Impl> protocol;
uWS::WebSocketState<true> state;

char* src = (char*)framedata.data();


//part parse
protocol.consume(src, 20, &state, nullptr);
protocol.consume(src + 20, 20, &state, nullptr);
protocol.consume(src + 40, framedata.size() - 40, &state, nullptr);


//parse two message
protocol.consume(two.data(), two.size(), &state, nullptr);

}

`

@gubaojian gubaojian changed the title use precise mask to fix bug for part parse lead frame error use precise mask to fix bug for part parse lead frame message error Jun 23, 2025
@gubaojian
Copy link
Contributor Author

gubaojian commented Jun 23, 2025

`

     unmaskImprecise8<0>(src + MESSAGE_HEADER, mask, length); 

    unmaskInplace(src, src + ((length >> 2) + 1) * 4, wState->mask);

`
above the line code may lead to overflow visit of the src buffer.

@uNetworkingAB
Copy link
Contributor

std::string two;
two.append(framedata);
two.append(framedata);

You need to pre-pad, post-pad your buffer with at least 32 bytes. All parsers in uWS build on relaxed boundary cehcks due to how all buffers are pre and post padded.

@gubaojian
Copy link
Contributor Author

std::string two; two.append(framedata); two.append(framedata);

You need to pre-pad, post-pad your buffer with at least 32 bytes. All parsers in uWS build on relaxed boundary cehcks due to how all buffers are pre and post padded.

thanks for your reply, seems it works well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants