Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1726,7 +1726,7 @@ fromData,1
toData,1

org/apache/geode/internal/cache/tier/sockets/ClientProxyMembershipID,2
fromData,19
fromData,63
toData,19

org/apache/geode/internal/cache/tier/sockets/ClientReAuthenticateMessage,2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.apache.geode.internal.serialization.DeserializationContext;
import org.apache.geode.internal.serialization.KnownVersion;
import org.apache.geode.internal.serialization.SerializationContext;
import org.apache.geode.internal.serialization.StaticSerialization;
import org.apache.geode.internal.serialization.Versioning;
import org.apache.geode.logging.internal.log4j.api.LogService;
import org.apache.geode.util.internal.GeodeGlossary;
Expand Down Expand Up @@ -304,7 +305,16 @@ public void toData(final DataOutput out, final SerializationContext context) thr
@Override
public void fromData(final DataInput in, final DeserializationContext context)
throws IOException, ClassNotFoundException {
identity = DataSerializer.readByteArray(in);
final int identityLength = StaticSerialization.readArrayLength(in);
if (identityLength > Short.MAX_VALUE) {
throw new IOException("HandShake identity length is too big");
}
if (identityLength == -1) {
identity = null;
} else {
identity = new byte[identityLength];
in.readFully(identity);
}
uniqueId = in.readInt();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.geode.internal.NullDataOutputStream;
import org.apache.geode.internal.serialization.ByteArrayDataInput;
import org.apache.geode.internal.serialization.DSCODE;
import org.apache.geode.internal.serialization.StaticSerialization;

public class ClientProxyMembershipIDTest {

Expand Down Expand Up @@ -102,6 +103,24 @@ public void readCanonicalizedReadsFixedIdForm() throws Exception {
assertThat(ClientProxyMembershipID.readCanonicalized(in)).isNotNull();
}

@Test
public void fromDataRejectsIdentityLengthThatExceedsMaximum() throws IOException {
// A well-formed identity is always small: writeExternal caps it at Short.MAX_VALUE.
// fromData applies the same upper bound when reading, so the fixed-id and Externalizable
// paths agree on the maximum identity length a client may send.
final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
final DataOutputStream out = new DataOutputStream(bytes);
out.writeByte(StaticSerialization.INT_ARRAY_LEN);
out.writeInt(Short.MAX_VALUE + 1);
out.close();
final ByteArrayDataInput in = new ByteArrayDataInput(bytes.toByteArray());
final ClientProxyMembershipID clientProxyMembershipID = new ClientProxyMembershipID();

assertThatThrownBy(() -> clientProxyMembershipID.fromData(in, null))
.isInstanceOf(IOException.class)
.hasMessageContaining("identity length is too big");
}

public static class ProbeObject implements Serializable {
static boolean deserialized;

Expand Down
Loading