You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by "Yifan Cai (Jira)" <ji...@apache.org> on 2024/11/12 20:07:00 UTC

[jira] [Commented] (CASSANDRA-18526) TupleType getString and fromString are not safe with string types

    [ https://issues.apache.org/jira/browse/CASSANDRA-18526?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17897727#comment-17897727 ] 

Yifan Cai commented on CASSANDRA-18526:
---------------------------------------

Adding another case when parsing from string fails. For string "\:\:\:", it can be produced from both tuples ("\", "::") and (":\", ":"). In other words, it is ambiguous to parse, and not split point can be determined from the string itself. 

{code:java}
    @Test
    public void testAmbiguousInputToSplit()
    {
        List<FieldIdentifier> fieldNames = Arrays.asList(new FieldIdentifier(ByteBufferUtil.bytes("a")),
                                                         new FieldIdentifier(ByteBufferUtil.bytes("b")));
        List<AbstractType<?>> fieldTypes = Arrays.asList(UTF8Type.instance, UTF8Type.instance);
        UserType type = new UserType("keyspace", UTF8Type.instance.decompose("name"), fieldNames, fieldTypes, false);
        ByteBuffer bb = type.fromString("\\:\\:\\:");
        ByteBuffer[] split = type.split(ByteBufferAccessor.instance, bb);
        assertThat(split).hasSize(2); // it fails; split has size of 1
        System.out.println(UTF8Type.instance.compose(split[0])); // prints ":::"
    }
{code}


> TupleType getString and fromString are not safe with string types
> -----------------------------------------------------------------
>
>                 Key: CASSANDRA-18526
>                 URL: https://issues.apache.org/jira/browse/CASSANDRA-18526
>             Project: Cassandra
>          Issue Type: Bug
>          Components: CQL/Interpreter
>            Reporter: David Capwell
>            Assignee: Raymond Welgosh
>            Priority: Normal
>             Fix For: 5.x
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> In adding property tests for our type system in CASSANDRA-18504, I found that tuples have issues with strings as its escaping doesn’t work in all cases… below is a simple example where it fails
> {code}
> package org.apache.cassandra.db.marshal;
> import java.nio.ByteBuffer;
> import java.util.Arrays;
> import java.util.List;
> import java.util.UUID;
> import org.junit.Test;
> import org.apache.cassandra.cql3.FieldIdentifier;
> import org.apache.cassandra.utils.ByteBufferUtil;
> import static org.assertj.core.api.Assertions.assertThat;
> public class UserTypeTest
> {
>     @Test
>     public void test()
>     {
>         // tuple parsing checks for : and looks to see if a \\ is before it (escaped :), so when the string ends with this escape... we fail to parse
>         String str = "thiswillbreakthings\\";
>         UUID uuid = UUIDType.instance.compose(UUIDType.instance.fromString("00000000-0000-4800-9100-000000000000"));
>         List<FieldIdentifier> fieldNames = Arrays.asList(new FieldIdentifier(ByteBufferUtil.bytes("a")),
>                                                          new FieldIdentifier(ByteBufferUtil.bytes("b")));
>         List<AbstractType<?>> fieldTypes = Arrays.asList(UTF8Type.instance, UUIDType.instance);
>         UserType type = new UserType("--dummy--", UTF8Type.instance.decompose("name"), fieldNames, fieldTypes, false);
>         ByteBuffer original = TupleType.buildValue(UTF8Type.instance.decompose(str), UUIDType.instance.decompose(uuid));
>         String source = type.getString(original);
>         ByteBuffer bb = type.fromString(source);
>         ByteBuffer[] split = type.split(ByteBufferAccessor.instance, bb);
>         assertThat(split).hasSize(2);
>         assertThat(split[1]).isEqualTo(uuid);
>     }
> }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cassandra.apache.org
For additional commands, e-mail: commits-help@cassandra.apache.org