From ea00c0af50a1311a1e13959e0d2100e8e84c963b Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Tue, 13 Nov 2012 20:39:29 +0000 Subject: [PATCH] * SSU: Fix bug that would drop 512 byte messages The bug has been there forever but never happened before 0.9.3 because the buffers were all 32KB and the largest fragment was about 1500 bytes. In 0.9.3, there are multiple buffer sizes, the smallest is 512 bytes, and a packet of exactly 512 bytes would be silently dropped. Thanks zab for finding it. --- .../router/transport/udp/OutboundMessageState.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java b/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java index 276ec13c30..600ad3c4fd 100644 --- a/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java +++ b/router/java/src/net/i2p/router/transport/udp/OutboundMessageState.java @@ -402,16 +402,21 @@ class OutboundMessageState implements CDPQEntry { int end = start + fragmentSize(fragmentNum); int toSend = end - start; byte buf[] = _messageBuf.getData(); - if ( (buf != null) && (start + toSend < buf.length) && (out != null) && (outOffset + toSend < out.length) ) { - System.arraycopy(_messageBuf.getData(), start, out, outOffset, toSend); + if ( (buf != null) && (start + toSend <= buf.length) && (outOffset + toSend <= out.length) ) { + System.arraycopy(buf, start, out, outOffset, toSend); if (_log.shouldLog(Log.DEBUG)) _log.debug("Raw fragment[" + fragmentNum + "] for " + _messageId + "[" + start + "-" + (start+toSend) + "/" + _totalSize + "/" + _fragmentSize + "]: " + Base64.encode(out, outOffset, toSend)); return toSend; + } else if (buf == null) { + if (_log.shouldLog(Log.WARN)) + _log.warn("Error: null buf"); } else { - return -1; + if (_log.shouldLog(Log.WARN)) + _log.warn("Error: " + start + '/' + end + '/' + outOffset + '/' + out.length); } + return -1; } /** -- GitLab