Skip to content
Open
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
11 changes: 10 additions & 1 deletion src/java/org/apache/cassandra/cql3/terms/InMarker.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
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;

/**
Expand Down Expand Up @@ -77,7 +78,15 @@ private <T> Terminals toTerminals(ByteBuffer value,
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());
}
List<Term.Terminal> terminals = new ArrayList<>(elements.size());
for (T element : elements)
{
Expand Down
64 changes: 64 additions & 0 deletions test/unit/org/apache/cassandra/cql3/terms/InMarkerTest.java
Original file line number Diff line number Diff line change
@@ -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() throws Throwable
{
assertInMarkerRejectsMalformedValue(new byte[]{ 0, 0, 0, 1 });
}

@Test
public void testExtraneousBytesThrowsInvalidRequest() throws Throwable
{
assertInMarkerRejectsMalformedValue(new byte[]{ 0, 0, 0, 0, 9, 9 });
}

private void assertInMarkerRejectsMalformedValue(byte[] malformedListBytes) throws Throwable
{
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
}
}
}