From ab715a94a7a1ea6d103cfc2ed59c03d4a4f7018c Mon Sep 17 00:00:00 2001 From: zzz Date: Wed, 5 Aug 2026 16:06:08 -0400 Subject: [PATCH] NTCP: Catch unchecked BufferOverflowException on read() call, unknown cause reported 2x by: postman --- .../net/i2p/router/transport/ntcp/EventPumper.java | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java index 99ea83572..6d441ea2e 100644 --- a/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java +++ b/router/java/src/net/i2p/router/transport/ntcp/EventPumper.java @@ -6,6 +6,7 @@ import java.net.Inet6Address; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.Buffer; +import java.nio.BufferOverflowException; import java.nio.channels.CancelledKeyException; import java.nio.channels.ClosedChannelException; import java.nio.channels.ClosedSelectorException; @@ -782,6 +783,16 @@ class EventPumper implements Runnable { clearInterest(key, SelectionKey.OP_READ); if (_log.shouldLog(Log.WARN)) _log.warn("error reading on " + con, nyce); + } catch (BufferOverflowException boe) { + // Rare unchecked exception on read() call, unknown cause + // Not even listed on SocketChannel.read() javadoc + // Do not release the buf, maybe it was in the pool twice? + // We assume this is fatal for the con so we close it. + clearInterest(key, SelectionKey.OP_READ); + con.close(); + _context.statManager().addRateData("ntcp.readError", 1); + if (_log.shouldWarn()) + _log.warn("error reading on " + con, boe); } }