[#1878] Fix leak of ByteBuf when masked payload is used

This commit is contained in:
Norman Maurer 2013-10-01 07:18:16 +02:00
parent 328f67fdfe
commit aaafdf909d

View File

@ -91,7 +91,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
private long framePayloadLength; private long framePayloadLength;
private ByteBuf framePayload; private ByteBuf framePayload;
private int framePayloadBytesRead; private int framePayloadBytesRead;
private ByteBuf maskingKey; private byte[] maskingKey;
private ByteBuf payloadBuffer; private ByteBuf payloadBuffer;
private final boolean allowExtensions; private final boolean allowExtensions;
@ -244,7 +244,10 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
checkpoint(State.MASKING_KEY); checkpoint(State.MASKING_KEY);
case MASKING_KEY: case MASKING_KEY:
if (maskedPayload) { if (maskedPayload) {
maskingKey = in.readBytes(4); if (maskingKey == null) {
maskingKey = new byte[4];
}
in.readBytes(maskingKey);
} }
checkpoint(State.PAYLOAD); checkpoint(State.PAYLOAD);
case PAYLOAD: case PAYLOAD:
@ -405,7 +408,7 @@ public class WebSocket08FrameDecoder extends ReplayingDecoder<WebSocket08FrameDe
private void unmask(ByteBuf frame) { private void unmask(ByteBuf frame) {
for (int i = frame.readerIndex(); i < frame.writerIndex(); i++) { for (int i = frame.readerIndex(); i < frame.writerIndex(); i++) {
frame.setByte(i, frame.getByte(i) ^ maskingKey.getByte(i % 4)); frame.setByte(i, frame.getByte(i) ^ maskingKey[i % 4]);
} }
} }