Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2012-08-02 13:31:37 -0400
committerJoakim Erdfelt2012-08-02 13:31:37 -0400
commit01c40b529087f20110116c23772fee735cd30987 (patch)
tree09a70ea7db065cd3a5d1a797ca830326aebdb067 /jetty-websocket
parente2dd62a3af198fbcfaf49e566dda6aff96514774 (diff)
downloadorg.eclipse.jetty.project-01c40b529087f20110116c23772fee735cd30987.tar.gz
org.eclipse.jetty.project-01c40b529087f20110116c23772fee735cd30987.tar.xz
org.eclipse.jetty.project-01c40b529087f20110116c23772fee735cd30987.zip
Fixing Parsing of masking bytes on slow testcase (would read in reverse order under certain conditions)
Diffstat (limited to 'jetty-websocket')
-rw-r--r--jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/Parser.java11
-rw-r--r--jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/protocol/GeneratorTest.java18
-rw-r--r--jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties3
3 files changed, 22 insertions, 10 deletions
diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/Parser.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/Parser.java
index fa49a5e705..46a2b91602 100644
--- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/Parser.java
+++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/protocol/Parser.java
@@ -392,8 +392,8 @@ public class Parser
case MASK_BYTES:
{
byte b = buffer.get();
+ frame.getMask()[4 - cursor] = b;
--cursor;
- frame.getMask()[cursor] = b;
if (cursor == 0)
{
// special case for empty payloads (no more bytes left in buffer)
@@ -449,6 +449,7 @@ public class Parser
getPolicy().assertValidPayloadLength(payloadLength);
frame.assertValid();
payload = ByteBuffer.allocate(payloadLength);
+ BufferUtil.clearToFill(payload);
}
BufferUtil.put(buffer,payload);
@@ -457,14 +458,18 @@ public class Parser
{
BufferUtil.flipToFlush(payload,0);
+ LOG.debug("PreMask: {}",BufferUtil.toDetailString(payload));
// demask (if needed)
if (frame.isMasked())
{
byte mask[] = frame.getMask();
+ int offset;
+ int start = payload.position();
int end = payload.limit();
- for (int i = payload.position(); i < end; i++)
+ for (int i = start; i < end; i++)
{
- payload.put(i,(byte)(payload.get(i) ^ mask[i % 4]));
+ offset = (i - start);
+ payload.put(i,(byte)(payload.get(i) ^ mask[offset % 4]));
}
}
diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/protocol/GeneratorTest.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/protocol/GeneratorTest.java
index 3b1b0e60c8..38d68a74aa 100644
--- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/protocol/GeneratorTest.java
+++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/protocol/GeneratorTest.java
@@ -17,6 +17,14 @@ import org.junit.Test;
public class GeneratorTest
{
+ private void parsePartial(Parser parser, ByteBuffer buf, int numBytes)
+ {
+ int len = Math.min(numBytes,buf.remaining());
+ byte arr[] = new byte[len];
+ buf.get(arr,0,len);
+ parser.parse(ByteBuffer.wrap(arr));
+ }
+
/**
* Prevent regression of masking of many packets.
*/
@@ -25,7 +33,7 @@ public class GeneratorTest
{
byte[] MASK =
{ 0x11, 0x22, 0x33, 0x44 };
- int pingCount = 1000;
+ int pingCount = 10;
// the generator
Generator generator = new UnitGenerator();
@@ -67,13 +75,11 @@ public class GeneratorTest
int segmentSize = 5;
while (completeBuf.remaining() > 0)
{
- ByteBuffer part = completeBuf.slice();
- int len = Math.min(segmentSize,part.remaining());
- part.limit(part.position() + len);
- parser.parse(part);
- completeBuf.position(completeBuf.position() + len);
+ parsePartial(parser,completeBuf,segmentSize);
}
+ capture.dump();
+
// Assert validity of frame
int frameCount = send.size();
capture.assertFrameCount(frameCount);
diff --git a/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties
index fbf6944551..c100df43af 100644
--- a/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties
+++ b/jetty-websocket/websocket-core/src/test/resources/jetty-logging.properties
@@ -1,2 +1,3 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
-org.eclipse.jetty.websocket.LEVEL=WARN \ No newline at end of file
+org.eclipse.jetty.websocket.LEVEL=WARN
+# org.eclipse.jetty.websocket.protocol.Parser.LEVEL=DEBUG \ No newline at end of file

Back to the top