StarRocks / starrocks

StarRocks, a Linux Foundation project, is a next-generation sub-second MPP OLAP database for full analytics scenarios, including multi-dimensional analytics, real-time analytics, and ad-hoc queries.
https://starrocks.io
Apache License 2.0
8.55k stars 1.73k forks source link

In special cases, using non-VARCHAR type parameters to call substring will cause BE to crash. #48141

Closed chenminghua8 closed 1 month ago

chenminghua8 commented 1 month ago

Steps to reproduce the behavior (Required)

  1. CREATE TABLE t ( day datetime ) ENGINE=OLAP PRIMARY KEY(day) PARTITION BY RANGE(cast(substr(day, 1, 10) as datetime)) ( PARTITION p201704 VALUES LESS THAN ("20170501"), PARTITION p201705 VALUES LESS THAN ("20170601"), PARTITION p201706 VALUES LESS THAN ("20170701") ) DISTRIBUTED BY HASH(day) BUCKETS 10 PROPERTIES ( "replication_num"="1", "in_memory" = "false", "storage_format" = "DEFAULT" );
  2. INSERT INTO t VALUES("20170601");

Expected behavior (Required)

Returns an error when calling the substr function with the wrong argument type.

Real behavior (Required)

BE service process crashes.

StarRocks version (Required)

2.5 3.0 3.1 3.2 3.3

chenminghua8 commented 1 month ago

I want to add a check that columns[0] must be a BinaryColumn in the StringFunctions::substring method. This will prevent BE crashes when passing exception types to the StringFunctions::substring method.

Astralidea commented 1 month ago

Thanks for your feedback. I think you can just restrict this type of table creation from being supported on FE.

chenminghua8 commented 1 month ago

One problem is to validate such illegal table statements. Another problem is that StringFunctions::substring allows non-BinaryColumn to be passed in without validation, causing BE to crash. This case is just one of the abnormal calls to substring. There are other abnormal calls to substring method, so substring method should be validated to avoid BE crash.

chenminghua8 commented 1 month ago

@Astralidea Assign the task to me. I will restrict the creation of such tables on FE.

chenminghua8 commented 1 month ago

@Astralidea Please help review the code.