This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch cassandra-6.0
in repository https://gitbox.apache.org/repos/asf/cassandra.git
The following commit(s) were added to refs/heads/cassandra-6.0 by this push:
new 20310db64c Throw InvalidRequestException instead of crashing on
malformed IN marker values
20310db64c is described below
commit 20310db64c5a3ee67177058c3d398f412e031497
Author: nivy <[email protected]>
AuthorDate: Thu Sep 3 20:00:04 2026 -0700
Throw InvalidRequestException instead of crashing on malformed IN marker
values
patch by Nivy Kani; reviewed by Caleb Rackliffe and Francisco Guerrero for
CASSANDRA-21648
---
CHANGES.txt | 1 +
.../org/apache/cassandra/cql3/terms/InMarker.java | 11 +++-
.../apache/cassandra/cql3/terms/InMarkerTest.java | 64 ++++++++++++++++++++++
3 files changed, 75 insertions(+), 1 deletion(-)
diff --git a/CHANGES.txt b/CHANGES.txt
index b2ca9dd737..bb3db66447 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
6.0-alpha3
+ * Throw InvalidRequestException instead of crashing on malformed IN marker
values (CASSANDRA-21648)
* Avoid serialization and deserialization for coordinator-local single
partition data read (CASSANDRA-21354)
* Allow nodetool cms reconfigure to ignore nodes via --ignore, excluding them
from the new CMS (CASSANDRA-21627)
* Accord: Compute Dependencies Incrementally (CASSANDRA-21682)
diff --git a/src/java/org/apache/cassandra/cql3/terms/InMarker.java
b/src/java/org/apache/cassandra/cql3/terms/InMarker.java
index 7941acbfde..0dbfb67226 100644
--- a/src/java/org/apache/cassandra/cql3/terms/InMarker.java
+++ b/src/java/org/apache/cassandra/cql3/terms/InMarker.java
@@ -33,6 +33,7 @@ import org.apache.cassandra.db.marshal.ByteBufferAccessor;
import org.apache.cassandra.db.marshal.ListType;
import org.apache.cassandra.db.marshal.MultiElementType;
import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.serializers.MarshalException;
import org.apache.cassandra.utils.ByteBufferUtil;
/**
@@ -77,7 +78,15 @@ public final class InMarker extends Terms.NonTerminals
ListType<T> type,
java.util.function.Function<ByteBuffer,
Term.Terminal> terminalConverter)
{
- List<T> elements = type.getSerializer().deserialize(value,
ByteBufferAccessor.instance);
+ List<T> elements;
+ try
+ {
+ elements = type.getSerializer().deserialize(value,
ByteBufferAccessor.instance);
+ }
+ catch (MarshalException e)
+ {
+ throw new InvalidRequestException(e.getMessage(), e);
+ }
List<Term.Terminal> terminals = new ArrayList<>(elements.size());
for (T element : elements)
{
diff --git a/test/unit/org/apache/cassandra/cql3/terms/InMarkerTest.java
b/test/unit/org/apache/cassandra/cql3/terms/InMarkerTest.java
new file mode 100644
index 0000000000..abf07ac0e9
--- /dev/null
+++ b/test/unit/org/apache/cassandra/cql3/terms/InMarkerTest.java
@@ -0,0 +1,64 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.cassandra.cql3.terms;
+
+import java.nio.ByteBuffer;
+import java.util.Collections;
+
+import org.junit.Test;
+
+import org.apache.cassandra.cql3.CQLTester;
+import org.apache.cassandra.cql3.QueryOptions;
+import org.apache.cassandra.cql3.statements.SelectStatement;
+import org.apache.cassandra.exceptions.InvalidRequestException;
+import org.apache.cassandra.service.QueryState;
+
+import static org.junit.Assert.fail;
+
+public class InMarkerTest extends CQLTester
+{
+ @Test
+ public void testNotEnoughBytesThrowsInvalidRequest()
+ {
+ assertInMarkerRejectsMalformedValue(new byte[]{ 0, 0, 0, 1 });
+ }
+
+ @Test
+ public void testExtraneousBytesThrowsInvalidRequest()
+ {
+ assertInMarkerRejectsMalformedValue(new byte[]{ 0, 0, 0, 0, 9, 9 });
+ }
+
+ private void assertInMarkerRejectsMalformedValue(byte[] malformedListBytes)
+ {
+ createTable("CREATE TABLE %s (pk int PRIMARY KEY, v int)");
+ SelectStatement select = (SelectStatement) parseStatement("SELECT *
FROM " + KEYSPACE + '.' + currentTable() + " WHERE pk IN ?");
+
+ QueryOptions options =
QueryOptions.forInternalCalls(Collections.singletonList(ByteBuffer.wrap(malformedListBytes)));
+ try
+ {
+ select.getQuery(options,
QueryState.forInternalCalls().getNowInSeconds());
+ fail("Expected InvalidRequestException to be thrown for a
malformed IN marker value");
+ }
+ catch (InvalidRequestException e)
+ {
+ // expected
+ }
+ }
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]