Skip to content

[fix](be) Fix auto_partition_name crash for invalid runtime arguments - #67218

Open
felixwluo wants to merge 3 commits into
apache:masterfrom
felixwluo:fix-auto-partition-name
Open

[fix](be) Fix auto_partition_name crash for invalid runtime arguments#67218
felixwluo wants to merge 3 commits into
apache:masterfrom
felixwluo:fix-auto-partition-name

Conversation

@felixwluo

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:
Executing select auto_partition_name('list', '10') could cause BE to core dump. The BE implementation of auto_partition_name relied on FE-side validation and did not validate runtime argument count or control arguments before dispatching. When the partition type was not handled as list, the code fell through to the range path and unconditionally accessed the third argument. For two-argument LIST calls, this could trigger an out-of-bounds vector access and abort the BE process.

This change fixes the issue at the BE function implementation layer by validating the argument count and partition type before dispatching, validating RANGE granularity explicitly, and reading string arguments through ColumnString::get_data_at() instead of manual chars/offsets indexing. It also disables the default constant-argument handling for this function so the function can preserve and validate its own constant control arguments. A BE unit test covers AUTO_PARTITION_NAME('LIST', '10') and malformed RANGE arguments.

Release note

Fix a BE crash when auto_partition_name receives invalid or mis-dispatched runtime arguments.

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

mrhhsg and others added 2 commits August 27, 2026 18:59
… segments in the rowset reader (apache#35484)

## Proposed changes

pick apache#35432 

## Further comments

If this is a relatively large or complex change, kick off the discussion
at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why
you chose the solution you did and what alternatives you considered,
etc...
@hello-stephen

Copy link
Copy Markdown
Contributor

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@felixwluo

Copy link
Copy Markdown
Member Author

/review

@felixwluo

Copy link
Copy Markdown
Member Author

run buildall

@felixwluo
felixwluo requested a review from Mryange August 27, 2026 12:00

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request changes.

Two blocking correctness issues are detailed inline: the function-wide constant override breaks the public constant-expression contract, and the nullable unwrapping leaves a materialized null map without an owner.

Critical checkpoint conclusions:

  • Goal and correctness: The new arity/control checks prevent the reported short-RANGE and invalid-dispatch out-of-bounds paths, and the ColumnString::get_data_at() rewrite preserves valid output bytes. The implementation is still unsafe because of the two inline blockers.
  • Tests: The added cases cover the numeric LIST reproducer and the new RANGE arity guard. They do not cover no-fold nesting/physical constness, and their Consted inputs construct the const-nullable ownership shape affected by the use-after-free. Focused no-fold and ASAN const-nullable coverage is required.
  • Scope and user focus: The PR changes only the BE implementation and its unit test; no additional user focus was supplied. The global constant-expression behavior and removal of the null-map lifetime keeper have effects broader than the intended validation hardening.
  • Control flow and parallel paths: LIST and RANGE dispatch, literal validation, all six RANGE granularities, const/vector/nullable/empty inputs, Unicode and long-name hashing, and date/datetime splitting were checked. No additional PR-introduced defect survived validation. The pre-existing RANGE-null payload behavior was excluded from this review.
  • Concurrency and lifecycle: No concurrency mechanism changes. Lifecycle/ownership is blocking at the second inline comment because later validation and row loops dereference the released null map.
  • Configuration and compatibility: No configuration, protocol, storage-format, or rolling-upgrade surface changed. The new BE argument checks align with the current FE legality rules.
  • Error handling and observability: Invalid new call shapes return a non-OK Status through the existing expression path. Existing errors are sufficient; no new logging or metrics are needed.
  • Persistence, transactions, and data writes: Not applicable to these scalar-expression changes.
  • Performance: The first blocker also changes literal-only evaluation from cached once to repeated work and allocation per input row when folding is skipped.
  • Validation status: Review-only run; no builds or tests were executed. The authoritative patch and relevant callers, wrappers, column ownership code, FE checks, and test harness were inspected. Round 2 converged with all three reviewers reporting no new valuable findings, so the review is complete with these two blockers.

size_t get_number_of_arguments() const override { return 0; }
bool is_variadic() const override { return true; }
bool use_default_implementation_for_nulls() const override { return false; }
bool use_default_implementation_for_constants() const override { return false; }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Preserve the constant-expression contract here

This override is also what VectorizedFnCall::is_constant() consults, so it does more than keep the control columns wrapped during execute_impl(). With folding skipped, auto_partition_name('list', 'x') now produces an ordinary ColumnString instead of a cached ColumnConst. For example, SELECT /*+SET_VAR(debug_skip_fold_constant=true)*/ trim('abc', auto_partition_name('list', 'x')) reaches FunctionTrim::get_arguments_that_are_always_constant() == {1} and is rejected by the generic constant-argument check, although the same deterministic nested expression was constant before this change. Literal-only projections also recompute and allocate the name once per input row (load planning is one path that explicitly skips folding). Please preserve VectorizedFnCall constness while validating the original control arguments through FunctionContext constant-column metadata or another decoupled mechanism, and add a no-fold nested regression.

@@ -122,40 +125,49 @@ class FunctionAutoPartitionName : public IFunction {
if (const auto* nullable =
check_and_get_column<const ColumnNullable>(*argument_columns[i])) {
null_list[i] = &nullable->get_null_map_data();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Keep the materialized null map alive

For a ColumnConst(ColumnNullable(...)), convert_to_full_column_if_const() creates a new full ColumnNullable with a freshly allocated null map. null_list[i] keeps only a raw pointer into that map, and the next assignment retains the nested string but releases the sole owner of the nullable parent and its null map. The later checks at lines 151/223/275 therefore read freed storage. The deleted argument_null_columns[i] = nullable->get_null_map_column_ptr() was the lifetime guard; the changed Consted tests build this exact const-nullable shape, as do supported LIST calls with NULL values. Please retain either the full materialized nullable column or its null-map ColumnPtr for the duration of execution, and cover both NULL and non-NULL const-nullable inputs under ASAN.

@felixwluo

Copy link
Copy Markdown
Member Author

run buildall

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 17030 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit a938fea52a1fbec08c8276483b06425f78c63b6b, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17562	3138	3135	3135
q2	2088	252	220	220
q3	10240	861	511	511
q4	4669	256	203	203
q5	7674	558	388	388
q6	138	112	93	93
q7	533	508	381	381
q8	9245	967	943	943
q9	3463	2431	2397	2397
q10	6512	883	710	710
q11	389	196	179	179
q12	616	258	197	197
q13	18128	1543	1172	1172
q14	158	153	138	138
q15	q16	428	393	372	372
q17	1343	923	884	884
q18	2990	2232	2219	2219
q19	1106	949	797	797
q20	370	288	206	206
q21	4809	1653	1890	1653
q22	323	275	232	232
Total cold run time: 92784 ms
Total hot run time: 17030 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3504	3442	3455	3442
q2	511	399	375	375
q3	2250	2332	2130	2130
q4	1193	1167	889	889
q5	2203	2115	2115	2115
q6	180	121	87	87
q7	1102	943	885	885
q8	1642	1430	1429	1429
q9	3168	3103	3136	3103
q10	1864	1826	1637	1637
q11	361	268	255	255
q12	449	429	353	353
q13	1481	1553	1151	1151
q14	164	171	169	169
q15	q16	393	398	356	356
q17	3621	3313	3210	3210
q18	4834	4434	4776	4434
q19	938	940	902	902
q20	973	962	847	847
q21	3869	3233	3236	3233
q22	405	345	330	330
Total cold run time: 35105 ms
Total hot run time: 31332 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 81897 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit a938fea52a1fbec08c8276483b06425f78c63b6b, data reload: false

query5	4291	418	332	332
query6	383	143	139	139
query7	4937	439	228	228
query8	295	125	121	121
query9	8685	2875	2895	2875
query10	394	220	183	183
query11	5372	1030	928	928
query12	117	75	70	70
query13	1200	440	330	330
query14	6098	2210	2085	2085
query14_1	2052	1968	1987	1968
query15	173	114	112	112
query16	921	386	368	368
query17	817	455	371	371
query18	2336	329	245	245
query19	160	137	115	115
query20	71	75	70	70
query21	207	104	88	88
query22	5355	5328	5304	5304
query23	6682	6051	5955	5955
query23_1	5945	6113	5984	5984
query24	7292	1094	786	786
query24_1	795	785	776	776
query25	429	314	256	256
query26	1250	225	129	129
query27	2802	408	253	253
query28	4704	1485	1501	1485
query29	928	440	381	381
query30	248	162	128	128
query31	817	403	322	322
query32	131	68	66	66
query33	446	215	176	176
query34	983	853	469	469
query35	393	404	336	336
query36	560	568	522	522
query37	119	79	68	68
query38	986	853	812	812
query39	493	481	474	474
query39_1	484	475	475	475
query40	215	93	73	73
query41	53	54	51	51
query42	77	78	71	71
query43	240	247	210	210
query44	1013	537	547	537
query45	111	106	95	95
query46	767	831	544	544
query47	755	772	688	688
query48	307	318	233	233
query49	523	243	176	176
query50	721	265	197	197
query51	8285	8148	8156	8148
query52	68	70	67	67
query53	189	199	146	146
query54	239	166	162	162
query55	78	63	56	56
query56	197	171	182	171
query57	686	641	661	641
query58	198	162	169	162
query59	1261	1219	1103	1103
query60	231	186	167	167
query61	134	111	116	111
query62	360	219	179	179
query63	169	142	145	142
query64	2755	697	614	614
query65	1655	1647	1561	1561
query66	1795	259	205	205
query67	9896	9543	9777	9543
query68	2975	1234	756	756
query69	347	212	195	195
query70	670	620	622	620
query71	246	165	167	165
query72	2333	1731	1588	1588
query73	635	562	318	318
query74	1997	1215	1121	1121
query75	1163	1101	951	951
query76	2369	715	536	536
query77	256	254	221	221
query78	3892	3544	3118	3118
query79	2780	807	597	597
query80	1661	322	282	282
query81	483	157	136	136
query82	619	126	96	96
query83	298	208	196	196
query84	296	115	86	86
query85	814	352	293	293
query86	393	169	172	169
query87	993	957	886	886
query88	2763	2095	2094	2094
query89	284	193	176	176
query90	1927	131	116	116
query91	130	121	100	100
query92	79	61	65	61
query93	1504	1167	670	670
query94	658	286	226	226
query95	510	259	297	259
query96	850	591	290	290
query97	1072	1038	1035	1035
query98	168	132	132	132
query99	414	340	310	310
Total cold run time: 178314 ms
Total hot run time: 81897 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.54 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit a938fea52a1fbec08c8276483b06425f78c63b6b, data reload: false

query1	0.01	0.01	0.00
query2	0.08	0.04	0.04
query3	0.24	0.11	0.11
query4	1.60	0.09	0.10
query5	0.17	0.17	0.16
query6	1.27	0.68	0.66
query7	0.03	0.01	0.00
query8	0.05	0.03	0.04
query9	0.29	0.22	0.21
query10	0.37	0.34	0.35
query11	0.16	0.11	0.12
query12	0.14	0.12	0.12
query13	0.32	0.30	0.30
query14	0.45	0.47	0.45
query15	0.36	0.34	0.34
query16	0.20	0.22	0.21
query17	0.68	0.63	0.67
query18	0.19	0.17	0.18
query19	1.21	1.10	1.16
query20	0.01	0.01	0.01
query21	15.46	0.15	0.12
query22	5.07	0.04	0.04
query23	16.19	0.26	0.10
query24	2.98	0.32	0.27
query25	0.10	0.04	0.04
query26	0.84	0.16	0.12
query27	0.03	0.04	0.02
query28	3.71	0.53	0.28
query29	12.47	3.18	2.53
query30	0.25	0.11	0.12
query31	2.75	0.36	0.17
query32	3.53	0.32	0.23
query33	1.46	1.56	1.45
query34	15.34	2.19	1.73
query35	1.76	1.73	1.72
query36	0.45	0.29	0.28
query37	0.06	0.04	0.04
query38	0.05	0.03	0.03
query39	0.03	0.03	0.02
query40	0.12	0.08	0.08
query41	0.08	0.03	0.03
query42	0.03	0.03	0.02
query43	0.04	0.03	0.03
Total cold run time: 90.63 s
Total hot run time: 14.54 s

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-H: Total hot run time: 17075 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpch-tools
Tpch sf100 test result on commit a938fea52a1fbec08c8276483b06425f78c63b6b, data reload: false

------ Round 1 ----------------------------------
============================================
q1	17571	3168	3110	3110
q2	2083	257	216	216
q3	10249	892	519	519
q4	4664	256	202	202
q5	7678	581	392	392
q6	138	135	101	101
q7	545	511	391	391
q8	9240	927	928	927
q9	3471	2403	2396	2396
q10	6504	844	714	714
q11	402	196	177	177
q12	612	266	204	204
q13	18114	1541	1182	1182
q14	159	150	140	140
q15	q16	427	394	367	367
q17	1405	812	855	812
q18	3060	2232	2226	2226
q19	1135	916	783	783
q20	352	285	197	197
q21	4845	1788	1797	1788
q22	335	271	231	231
Total cold run time: 92989 ms
Total hot run time: 17075 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	3489	3451	3411	3411
q2	518	391	371	371
q3	2231	2320	2156	2156
q4	1208	1184	913	913
q5	2183	2131	2095	2095
q6	177	121	88	88
q7	1040	933	905	905
q8	1651	1444	1450	1444
q9	3145	3141	3126	3126
q10	1856	1820	1648	1648
q11	362	272	258	258
q12	456	437	352	352
q13	1488	1561	1176	1176
q14	173	172	164	164
q15	q16	402	400	363	363
q17	3575	3331	3223	3223
q18	4819	4446	4772	4446
q19	914	955	918	918
q20	1001	974	816	816
q21	3863	3250	3207	3207
q22	393	332	325	325
Total cold run time: 34944 ms
Total hot run time: 31405 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 82293 ms
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/tpcds-tools
TPC-DS sf100 test result on commit a938fea52a1fbec08c8276483b06425f78c63b6b, data reload: false

query5	4253	418	331	331
query6	389	150	140	140
query7	4925	427	233	233
query8	310	123	122	122
query9	8703	2885	2876	2876
query10	380	223	184	184
query11	5369	1044	923	923
query12	119	71	68	68
query13	1222	461	301	301
query14	6166	2215	2082	2082
query14_1	1973	1956	1961	1956
query15	171	123	116	116
query16	929	385	359	359
query17	801	473	400	400
query18	2339	334	251	251
query19	171	144	112	112
query20	74	78	71	71
query21	198	103	89	89
query22	5470	5499	5416	5416
query23	6652	6069	6108	6069
query23_1	6002	6159	6198	6159
query24	7315	1100	766	766
query24_1	757	789	752	752
query25	433	309	264	264
query26	1227	225	137	137
query27	2787	425	260	260
query28	4691	1490	1491	1490
query29	947	454	363	363
query30	253	157	134	134
query31	818	411	328	328
query32	125	77	78	77
query33	469	219	192	192
query34	1011	833	478	478
query35	428	397	337	337
query36	576	557	533	533
query37	118	76	67	67
query38	1001	831	816	816
query39	502	471	474	471
query39_1	452	439	461	439
query40	198	90	86	86
query41	56	52	52	52
query42	71	68	71	68
query43	241	238	208	208
query44	1026	545	561	545
query45	110	102	96	96
query46	787	841	540	540
query47	750	781	694	694
query48	316	317	235	235
query49	529	248	182	182
query50	753	255	192	192
query51	8287	8057	8089	8057
query52	67	67	65	65
query53	197	204	146	146
query54	220	181	153	153
query55	80	98	54	54
query56	223	256	180	180
query57	695	670	627	627
query58	209	157	148	148
query59	1220	1226	1105	1105
query60	233	169	187	169
query61	136	121	143	121
query62	338	211	179	179
query63	166	144	138	138
query64	2733	720	568	568
query65	1723	1586	1646	1586
query66	1793	259	194	194
query67	9640	9685	9623	9623
query68	2923	1255	733	733
query69	344	227	200	200
query70	668	591	628	591
query71	244	169	157	157
query72	2373	1718	1568	1568
query73	667	600	339	339
query74	1992	1219	1152	1152
query75	1182	1111	955	955
query76	2301	741	573	573
query77	253	261	220	220
query78	3941	3814	3202	3202
query79	1176	832	565	565
query80	1252	350	302	302
query81	484	158	163	158
query82	637	122	95	95
query83	268	214	191	191
query84	284	105	89	89
query85	782	357	294	294
query86	384	188	177	177
query87	1003	967	908	908
query88	2742	2088	2108	2088
query89	295	196	176	176
query90	1985	124	123	123
query91	130	120	99	99
query92	79	69	69	69
query93	1273	1130	675	675
query94	635	221	219	219
query95	525	245	228	228
query96	818	571	281	281
query97	1061	1040	1036	1036
query98	150	139	150	139
query99	413	348	310	310
Total cold run time: 175957 ms
Total hot run time: 82293 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
ClickBench: Total hot run time: 14.82 s
machine: 'aliyun_ecs.c7a.8xlarge_32C64G'
scripts: https://github.com/apache/doris/tree/master/tools/clickbench-tools
ClickBench test result on commit a938fea52a1fbec08c8276483b06425f78c63b6b, data reload: false

query1	0.01	0.00	0.00
query2	0.08	0.04	0.04
query3	0.25	0.11	0.11
query4	1.60	0.09	0.10
query5	0.19	0.15	0.16
query6	1.26	0.69	0.67
query7	0.04	0.01	0.00
query8	0.04	0.03	0.03
query9	0.29	0.21	0.21
query10	0.33	0.37	0.34
query11	0.16	0.11	0.12
query12	0.16	0.13	0.11
query13	0.31	0.30	0.31
query14	0.45	0.45	0.45
query15	0.35	0.33	0.34
query16	0.22	0.21	0.20
query17	0.66	0.68	0.72
query18	0.19	0.17	0.17
query19	1.19	1.19	1.15
query20	0.01	0.01	0.01
query21	15.44	0.15	0.12
query22	5.09	0.04	0.05
query23	16.16	0.24	0.10
query24	3.03	0.33	0.26
query25	0.10	0.04	0.04
query26	0.76	0.17	0.12
query27	0.04	0.03	0.04
query28	3.63	0.54	0.28
query29	12.47	3.16	2.58
query30	0.25	0.12	0.11
query31	2.75	0.37	0.17
query32	3.54	0.33	0.24
query33	1.42	1.49	1.49
query34	15.35	2.26	1.85
query35	1.78	1.72	1.72
query36	0.45	0.30	0.28
query37	0.06	0.04	0.04
query38	0.04	0.03	0.04
query39	0.03	0.03	0.02
query40	0.11	0.08	0.07
query41	0.08	0.02	0.02
query42	0.03	0.03	0.03
query43	0.03	0.03	0.03
Total cold run time: 90.43 s
Total hot run time: 14.82 s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants