From b76f9abfc96885126e69f9baa148a70740e8ddde Mon Sep 17 00:00:00 2001 From: Etienne CHAMPETIER Date: Mon, 25 Apr 2016 12:27:51 +0200 Subject: [PATCH] ChannelData: fix decode() I haven't found any user of this method. This method was only working if offset == 0 and binMessage isn't a padded message. arrayLen is useless as we have msgLen, so remove it, and introduce a deprecated decode() to keep same api Signed-off-by: Etienne CHAMPETIER --- .../java/org/ice4j/message/ChannelData.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ice4j/message/ChannelData.java b/src/main/java/org/ice4j/message/ChannelData.java index c3b3bb3..5c5a2e7 100644 --- a/src/main/java/org/ice4j/message/ChannelData.java +++ b/src/main/java/org/ice4j/message/ChannelData.java @@ -188,15 +188,29 @@ public class ChannelData * @return a Message object constructed from the binMessage array * @throws StunException ILLEGAL_ARGUMENT if one or more of the arguments * have invalid values. + * @deprecated */ public static ChannelData decode(byte binMessage[], char offset, char arrayLen) throws StunException + { + return decode(binMessage, offset); + } + + /** + * Constructs a message from its binary representation. + * @param binMessage the binary array that contains the encoded message + * @param offset the index where the message starts. + * @return a Message object constructed from the binMessage array + * @throws StunException ILLEGAL_ARGUMENT if one or more of the arguments + * have invalid values. + */ + public static ChannelData decode(byte binMessage[], char offset) throws StunException { char msgLen = 0; char channelNumber = 0; ChannelData channelData = null; byte data[] = null; - if(arrayLen < 4) + if((binMessage.length - offset) < HEADER_LENGTH) { throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size too short"); } @@ -209,7 +223,7 @@ public class ChannelData } msgLen = (char)((binMessage[offset++]<<8) | (binMessage[offset++]&0xFF)); - if(msgLen != (binMessage.length - 4)) + if (msgLen > (binMessage.length - offset)) { throw new StunException(StunException.ILLEGAL_ARGUMENT, "Size mismatch"); }