File tree Expand file tree Collapse file tree 1 file changed +19
-13
lines changed
Expand file tree Collapse file tree 1 file changed +19
-13
lines changed Original file line number Diff line number Diff line change @@ -540,21 +540,27 @@ void AsyncWebSocketClient::_onData(void *pbuf, size_t plen) {
540540 }
541541
542542 if (_pinfo.masked > 0 && _pinfo.masked < 5 ) {
543- // Handle fragmented mask data - Safari may split the 4-byte mask across multiple packets
544- int mask_bytes_read = _pinfo.masked - 1 ;
545- while (mask_bytes_read < 4 ) {
546- if (plen == 0 ) {
547- // wait for more data
548- _pinfo.masked = mask_bytes_read + 1 ;
549- _pstate = 1 ;
550- return ;
543+ // Handle Safari edge case: close frame with plen 0, mask bit set, but no mask bytes
544+ if (_pinfo.len == 0 && plen == 0 ) {
545+ // Malformed frame (Safari bug): treat as unmasked for compatibility
546+ _pinfo.masked = 0 ;
547+ } else {
548+ // Handle fragmented mask data - Safari may split the 4-byte mask across multiple packets
549+ int mask_bytes_read = _pinfo.masked - 1 ;
550+ while (mask_bytes_read < 4 ) {
551+ if (plen == 0 ) {
552+ // wait for more data
553+ _pinfo.masked = mask_bytes_read + 1 ;
554+ _pstate = 1 ;
555+ return ;
556+ }
557+ _pinfo.mask [mask_bytes_read] = data[0 ];
558+ data += 1 ;
559+ plen -= 1 ;
560+ mask_bytes_read++;
551561 }
552- _pinfo.mask [mask_bytes_read] = data[0 ];
553- data += 1 ;
554- plen -= 1 ;
555- mask_bytes_read++;
562+ _pinfo.masked = 1 ; // restore boolean semantics: mask fully read
556563 }
557- _pinfo.masked = 1 ; // restore boolean semantics: mask fully read
558564 }
559565
560566 const size_t datalen = std::min ((size_t )(_pinfo.len - _pinfo.index ), plen);
You can’t perform that action at this time.
0 commit comments