[webkit-reviews] review denied: [Bug 64522] WebSocket: Implement hybi framing : [Attachment 100803] Patch

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Jul 14 23:02:18 PDT 2011


Kent Tamura <tkent at chromium.org> has denied Yuta Kitamura
<yutak at chromium.org>'s request for review:
Bug 64522: WebSocket: Implement hybi framing
https://bugs.webkit.org/show_bug.cgi?id=64522

Attachment 100803: Patch
https://bugs.webkit.org/attachment.cgi?id=100803&action=review

------- Additional Comments from Kent Tamura <tkent at chromium.org>
View in context: https://bugs.webkit.org/attachment.cgi?id=100803&action=review


> Source/WebCore/websockets/WebSocketChannel.cpp:412
> +const WebSocketChannel::OpCode WebSocketChannel::OpCodeContinuation = 0x0;
> +const WebSocketChannel::OpCode WebSocketChannel::OpCodeText = 0x1;
> +const WebSocketChannel::OpCode WebSocketChannel::OpCodeBinary = 0x2;
> +const WebSocketChannel::OpCode WebSocketChannel::OpCodeClose = 0x8;
> +const WebSocketChannel::OpCode WebSocketChannel::OpCodePing = 0x9;
> +const WebSocketChannel::OpCode WebSocketChannel::OpCodePong = 0xA;
> +

I think we had better move them to the upper place of this file.
These symbols are used before here, and I'm afraid defining them here prevents
constant value folding optimization.

> Source/WebCore/websockets/WebSocketChannel.cpp:413
> +bool WebSocketChannel::processFrame()

This function is too large.  Please consider splitting it.

> Source/WebCore/websockets/WebSocketChannel.cpp:417
> +    char* p = m_buffer;
> +    char* end = m_buffer + m_bufferSize;

'p' and 'end' should be 'const char*'.
Use another non-const variable or const_cast<> when we unmask the payload.

'end' should be 'bufferEnd' to avoid confusion with frameEnd'.

> Source/WebCore/websockets/WebSocketChannel.cpp:420
> +    if (m_bufferSize < 2) // Frame incomplete.
> +	   return false;

The comment should be a complete sentence as possible.	Probably "The frame is
incomplete."

> Source/WebCore/websockets/WebSocketChannel.cpp:434
> +    if (payloadLength64 >= 126) {
> +	   int extendedPayloadLengthSize = payloadLength64 == 126 ? 2 : 8;

126 is a magic number.
Please introduce a meaningful name.

> Source/WebCore/websockets/WebSocketChannel.cpp:448
> +#if OS(WINDOWS)
> +    static const uint64_t maxPayloadLength = 0x7FFFFFFFFFFFFFFFui64;
> +#else
> +    static const uint64_t maxPayloadLength = 0x7FFFFFFFFFFFFFFFull;
> +#endif

It's not OS-dependent but compiler-dependent.

You assume uint64_t is available on any platforms.  So can you use
UINT64_C(0x7FFFFFFFFFFFFFFF) ?

> Source/WebCore/websockets/WebSocketChannel.cpp:449
> +    size_t maskingKeyLength = masked ? 4 : 0;

4 is a magic number.

> Source/WebCore/websockets/WebSocketChannel.cpp:464
> +    char* payload = p + maskingKeyLength;
> +    char* frameEnd = p + maskingKeyLength + payloadLength;

They should be const char*.

> Source/WebCore/websockets/WebSocketChannel.cpp:677
> +    frame.append(0x80 | opCode); // 0x80 is for "fin" bit; we do not
fragment a frame on sending.
> +    if (dataLength < 126)
> +	   frame.append(0x80 | dataLength); // 0x80 is for "MASK" bit; a client
must mask frames so it is always on.

So we should have FinBit = 0x80 and MaskBit = 0x80, or something like them.

> Source/WebCore/websockets/WebSocketChannel.cpp:703
> +    frame.append("....", 4); // Four-byte placeholder for masking key. Will
be overwritten.
> +    size_t payloadStart = frame.size();
> +    frame.append(data, dataLength);
> +
> +    cryptographicallyRandomValues(frame.data() + maskingKeyStart, 4);
> +    for (size_t i = 0; i < dataLength; ++i)
> +	   frame[payloadStart + i] ^= frame[maskingKeyStart + i % 4];

4 is a magic number.


More information about the webkit-reviews mailing list