Skip to content
Browse files
Fix data corruption in AbstractCompositeType due to static boolean by…
…te buffers

patch by Stefania Alborghetti and Marcus Eriksson; reviewed by Marcus Eriksson, Benjamin Lerer and Ekaterina Dimitrova for CASSANDRA-14752

Co-authored-by: Stefania Alborghetti <>
Co-authored-by: Marcuse Eriksson <marcuse@apache.orgp>
  • Loading branch information
3 people committed Apr 17, 2022
1 parent 84bc0e8 commit fb66800a00aeaa8046cb3e6b1401fdc4f81848d5
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
@@ -1,4 +1,5 @@
* Fix data corruption in AbstractCompositeType due to static boolean byte buffers (CASSANDRA-14752)
* Add procps dependency to RPM/Debian packages (CASSANDRA-17516)
* Suppress CVE-2021-44521 (CASSANDRA-17492)
* ConnectionLimitHandler may leaks connection count if remote connection drops (CASSANDRA-17252)
@@ -190,8 +190,8 @@ public String getString(ByteBuffer bytes)
public ByteBuffer fromString(String source)
List<String> parts = split(source);
List<ByteBuffer> components = new ArrayList<ByteBuffer>(parts.size());
List<ParsedComparator> comparators = new ArrayList<ParsedComparator>(parts.size());
List<ByteBuffer> components = new ArrayList<>(parts.size());
List<ParsedComparator> comparators = new ArrayList<>(parts.size());
int totalLength = 0, i = 0;
boolean lastByteIsOne = false;
boolean lastByteIsMinusOne = false;
@@ -226,7 +226,7 @@ else if (part.equals("_"))
ByteBufferUtil.writeShortLength(bb, component.remaining());
bb.put(component); // it's ok to consume component as we won't use it anymore
bb.put(component.duplicate()); // it's not ok to consume component as we did not create it (CASSANDRA-14752)
@@ -0,0 +1,45 @@
* 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
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.

package org.apache.cassandra.distributed.test;

import org.junit.Assert;
import org.junit.Test;

import org.apache.cassandra.distributed.Cluster;
import org.apache.cassandra.distributed.api.ConsistencyLevel;
import org.apache.cassandra.serializers.BooleanSerializer;

public class BooleanTest extends TestBaseImpl
public void booleanTest() throws Throwable
try(Cluster cluster = init(
cluster.schemaChange("create table " + KEYSPACE + ".tbl (id int, ck boolean, t int, primary key ((id, ck)))");
for (int i = 0; i < 10; i++)
cluster.coordinator(1).execute(withKeyspace("insert into %s.tbl (id, ck, t) values (?, true, ?)"), ConsistencyLevel.ALL, i, i);
cluster.get(1).nodetoolResult("getsstables", KEYSPACE, "tbl", "1:true");
cluster.forEach(i -> i.runOnInstance(() -> {
Assert.assertEquals(0, BooleanSerializer.instance.serialize(true).position());
Assert.assertEquals(0, BooleanSerializer.instance.serialize(false).position());
@@ -674,4 +674,22 @@ public void superColumnFamilyTest() throws Throwable
"\tWITH ID = " + cfs.metadata.cfId + "\n" +

public void testBooleanCompositeKey() throws Throwable
createTable("CREATE TABLE %s (t_id boolean, id boolean, ck boolean, nk boolean, PRIMARY KEY ((t_id, id), ck))");

execute("insert into %s (t_id, id, ck, nk) VALUES (true, false, false, true)");
assertRows(execute("select * from %s"), row(true, false, false, true));

// CASSANDRA-14752 -
// a problem with composite boolean types meant that calling this would
// prevent any boolean values to be inserted afterwards
ColumnFamilyStore cfs = getCurrentColumnFamilyStore();

execute("insert into %s (t_id, id, ck, nk) VALUES (true, true, false, true)");
assertRows(execute("select t_id, id, ck, nk from %s"), row(true, true, false, true), row(true, false, false, true));

0 comments on commit fb66800

Please sign in to comment.