From 8206524ac2d1fa4a42d41c54ce59bdd07ccf8741 Mon Sep 17 00:00:00 2001 From: Eike Stepper Date: Wed, 10 Jan 2007 08:30:42 +0000 Subject: Fixed HeapOverflowException in ExtendedDataInputStream.readByteArray --- plugins/org.eclipse.net4j/.options | 2 +- .../internal/net4j/transport/AbstractConnector.java | 3 ++- .../internal/net4j/transport/BufferImpl.java | 2 +- .../src/org/eclipse/net4j/transport/Connector.java | 21 +++++++++++---------- .../net4j/util/stream/ExtendedDataInputStream.java | 18 ++++++++++++++++-- 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/plugins/org.eclipse.net4j/.options b/plugins/org.eclipse.net4j/.options index 2aa722539a..d4803f3631 100644 --- a/plugins/org.eclipse.net4j/.options +++ b/plugins/org.eclipse.net4j/.options @@ -7,7 +7,7 @@ org.eclipse.net4j/debug.registry = true org.eclipse.net4j/debug.om = true org.eclipse.net4j/debug.buffer = true -org.eclipse.net4j/debug.buffer.stream = true +org.eclipse.net4j/debug.buffer.stream = false org.eclipse.net4j/debug.channel = true org.eclipse.net4j/debug.selector = true org.eclipse.net4j/debug.acceptor = true diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java index ac9ac92d00..acdc13cf25 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/AbstractConnector.java @@ -616,7 +616,8 @@ public abstract class AbstractConnector extends AbstractLifecycle implements Con super.onDeactivate(); } - protected abstract void registerChannelWithPeer(short channelIndex, String protocolID) throws ConnectorException; + protected abstract void registerChannelWithPeer(short channelIndex, String protocolID) + throws ConnectorException; private static int getNextConnectorID() { diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java index bf06963a67..9f615139eb 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/transport/BufferImpl.java @@ -296,7 +296,7 @@ public class BufferImpl implements Buffer { byteBuffer.flip(); } - + if (state == State.PUTTING) { byteBuffer.position(HEADER_SIZE); diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java index 28bf96d5b2..b21e3bdf93 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/transport/Connector.java @@ -22,15 +22,14 @@ import java.util.concurrent.ExecutorService; * One endpoint of a physical connection of arbitrary nature between two * communicating parties. A {@link Connector} encapsulates the process of * establishing and closing such connections and has a {@link Type} of - * {@link Type#CLIENT} or {@link Type#SERVER} with - * respect to this process. Once a connection is established either party can - * use its connector to open multiple {@link Channel}s to - * asynchronously exchange {@link Buffer}s. + * {@link Type#CLIENT} or {@link Type#SERVER} with respect to this process. Once + * a connection is established either party can use its connector to open + * multiple {@link Channel}s to asynchronously exchange {@link Buffer}s. *

- * This interface is not intended to be implemented by clients. Providers of - * connectors for new physical connection types have to subclass {@link AbstractConnector} - * (see {@link ChannelImpl#setConnector(AbstractConnector)}. - * + * This interface is not intended to be implemented by clients. + * Providers of connectors for new physical connection types have to subclass + * {@link AbstractConnector} (see + * {@link ChannelImpl#setConnector(AbstractConnector)}. *

* * @author Eike Stepper @@ -67,7 +66,8 @@ public interface Connector public void connectAsync() throws ConnectorException; /** - * Blocks until {@link #isConnected()} == true or the given timeout expired. + * Blocks until {@link #isConnected()} == true or the given + * timeout expired. *

* * @throws ConnectorException @@ -76,7 +76,8 @@ public interface Connector /** * Synchronous connect. Blocks until {@link #isConnected()} == - * true or the given timeout expired. + * true + * or the given timeout expired. *

*/ public boolean connect(long timeout) throws ConnectorException; diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java index 9814e3c4fc..f2e5670da4 100644 --- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java +++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/util/stream/ExtendedDataInputStream.java @@ -32,8 +32,22 @@ public class ExtendedDataInputStream extends DataInputStream implements Extended throw new IndexOutOfBoundsException(); } - byte[] b = new byte[length]; - read(b); + byte[] b; + try + { + b = new byte[length]; + } + catch (Throwable t) + { + throw new IOException("Unable to allocate " + length + " bytes"); + } + + int bytes = read(b); + if (bytes != length) + { + throw new IOException("Unable to read " + length + " bytes (after " + bytes + " bytes)"); + } + return b; } -- cgit v1.2.3