From 8d63b89515afdc8f41eb2f62a25a1b900f270ad2 Mon Sep 17 00:00:00 2001 From: Nikita Date: Wed, 25 May 2016 13:17:53 +0300 Subject: [PATCH] IndexOutOfBoundsException fixed. #349 --- .../com/corundumstudio/socketio/protocol/PacketDecoder.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java b/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java index 1be5e58..f6a0f89 100644 --- a/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java +++ b/src/main/java/com/corundumstudio/socketio/protocol/PacketDecoder.java @@ -119,9 +119,10 @@ public class PacketDecoder { public Packet decodePackets(ByteBuf buffer, ClientHead client) throws IOException { if (isStringPacket(buffer)) { // TODO refactor - int headEndIndex = buffer.bytesBefore(10, (byte)-1); + int maxLength = Math.min(buffer.readableBytes(), 10); + int headEndIndex = buffer.bytesBefore(maxLength, (byte)-1); if (headEndIndex == -1) { - headEndIndex = buffer.bytesBefore(10, (byte)0x3f); + headEndIndex = buffer.bytesBefore(maxLength, (byte)0x3f); } int len = (int) readLong(buffer, headEndIndex);