Skip to content

[fix](bitmap) fix SIGSEGV when reading zero-length serialized BITMAP/HLL/QuantileState cell - #67473

Merged
hello-stephen merged 2 commits into
apache:masterfrom
qzsee:fix-complex-type
Sep 24, 2026
Merged

hello-stephen merged 2 commits into
apache:masterfrom
qzsee:fix-complex-type

Conversation

@qzsee

@qzsee qzsee commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: close #xxx

Related PR: #xxx

Problem Summary:

When a BITMAP / HLL / QUANTILE_STATE cell on disk has a serialized length
of 0, ColumnComplexType::insert_binary_data used to interpret the raw
page bytes as an in-memory value_type object via reinterpret_cast and
then copy-assign it, which is undefined behavior. The heap-pointer
members of BitmapValue / HyperLogLog / QuantileState were dereferenced
as if they were valid pointers, and BE processes crashed with SIGSEGV
during queries that hit read_by_rowids (e.g. lazy materialization on
aggregate / unique-key tables that carry a BITMAP value column).

Fix it by keeping the default-constructed empty object produced by
insert_default() and returning early when length == 0.

Add regression tests in be/test/core/column/column_complex_test.cpp
covering all three complex types and all three code paths that flow
into insert_binary_data.

Release note

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

@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?

BiteTheDDDDt
BiteTheDDDDt previously approved these changes Sep 3, 2026

@BiteTheDDDDt BiteTheDDDDt 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.

LGTM

@BiteTheDDDDt

Copy link
Copy Markdown
Contributor

run buildall

@BiteTheDDDDt

Copy link
Copy Markdown
Contributor

/review

@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.

Requesting changes on 04190660015d0c48bf3a207cf7284f04a7f150e3 after two review rounds; both follow-up reviewers converged with NO_NEW_VALUABLE_FINDINGS. The blocking findings are inline: the all-type zero-byte recovery lacks a BITMAP/QUANTILE_STATE compatibility contract, the BITMAP regression oracle can accept the old invalid state, and the added test fails clang-format 16.

Checkpoint conclusions:

  • Goal and proof: the early return removes the invalid zero-length object copy across direct, continuous, StringRef, V1, V2, and V3 paths, but the recovery semantics and BITMAP test proof remain incomplete.
  • Scope: the implementation is small and focused, and the new test translation unit is auto-discovered by the BE unit-test target.
  • Concurrency, lifetime, COW, and memory: no new shared state, locks, static initialization, ownership edge, or invalid default-object lifetime was found.
  • Configuration and compatibility: no config, protocol, symbol, or storage-format change is introduced. HLL has a historical dirty-data exception, but zero-byte compatibility for BITMAP and QUANTILE_STATE is unresolved.
  • Error and data correctness: malformed BITMAP/QUANTILE_STATE cells can be silently reported as empty; this is the primary correctness blocker.
  • Tests and checks: no build was run under the review runner contract. clang-format-16 --dry-run --Werror fails on the added test; git diff --check and build-support/check-build-hygiene.sh pass. No regression result files are involved.
  • Transactions, persistence writes, FE/BE variables, and observability: none are otherwise implicated; if compatibility recovery is retained, its scope and observability need to be explicit.
  • Performance: no material regression was found.
  • Review focus: no additional focus was supplied, so the full PR was reviewed.

Comment thread be/src/core/column/column_complex.h Resolved
@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.02% (29550/46891)
Line Coverage 48.06% (309830/644699)
Region Coverage 43.65% (250382/573592)
Branch Coverage 45.23% (116497/257553)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.26% (34635/45417)
Line Coverage 61.33% (390883/637336)
Region Coverage 57.41% (328038/571408)
Branch Coverage 58.32% (149766/256814)

@HappenLee

Copy link
Copy Markdown
Contributor

/review

@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.

Requesting changes on c279c87489e320f5203220c440cde58cc46460f5 after two complete review rounds; all round-2 reviewers converged with NO_NEW_VALUABLE_FINDINGS. I am not adding a new inline comment because the only substantiated blocker is already captured in the existing P1 thread.

The latest head fixes the two earlier P2 items: clang-format 16 now accepts the include order, and the BITMAP test asserts the canonical BitmapTypeCode::EMPTY. The P1 remains unresolved: current writers encode empty BITMAP/HLL/QUANTILE_STATE values as 1/1/5 bytes and nullable rows are omitted from data pages. Only HLL has a documented legacy zero-length recovery contract. Applying the fallback to BITMAP and QUANTILE_STATE can therefore turn truncated/corrupt cells into valid empty query results unless a real per-type compatibility contract is established.

Checkpoint conclusions:

  • Goal and proof: the change removes the invalid zero-length object reinterpret/copy and the helper tests cover direct and batched insertion, but the all-type recovery policy is not yet justified; the existing P1 remains blocking.
  • Scope and clarity: the source change is small and focused, and the new test is discovered by the BE unit-test CMake glob.
  • Concurrency: no threads, locks, atomics, or shared concurrent state are involved.
  • Lifecycle and ownership: no static-initialization or special-release lifecycle is introduced; insert_default() creates destination-owned RAII state and no COW/Block mutation issue was found.
  • Configuration: no configuration item or dynamic-update behavior is added.
  • Compatibility: V1, V2, and V3 all preserve zero cell lengths into the shared decoder path. HLL has a historical compatibility exception; BITMAP and QUANTILE_STATE do not have a demonstrated producer/version contract.
  • Parallel paths and conditions: next_batch and read_by_rowids converge through the two tested batch helpers, and nullable rows remain governed by the null bitmap. The zero-length conditional still needs the per-type policy requested by P1.
  • Tests and results: positive nonempty behavior is covered by existing tests and the added BITMAP oracle is now canonical. No build or test execution was performed because this review runner forbids it; no regression .out files are involved.
  • Observability and error handling: silently normalizing unsupported zero-length BITMAP/QUANTILE_STATE payloads removes corruption evidence; rejection or an explicit scoped recovery contract is required. No separate logging or metric change is otherwise needed.
  • Transactions, persistence, writes, and FE/BE variables: no transaction, EditLog, storage-write atomicity, visibility-version, or transmitted-variable change is involved.
  • Performance: the O(1) branch removes an invalid copy and introduces no material hot-path regression.
  • Other findings: none after duplicate fencing and the final changed-file sweep.
  • User focus: no additional review focus was supplied.

Static checks run: clang-format-16 --dry-run --Werror on both changed files and build-support/check-build-hygiene.sh; both passed.

@HappenLee HappenLee 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.

LGTM

@HappenLee

Copy link
Copy Markdown
Contributor

run buildall

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17605	3867	3846	3846
q2	2199	371	308	308
q3	10058	1405	763	763
q4	4679	477	363	363
q5	7478	820	551	551
q6	176	167	134	134
q7	745	786	609	609
q8	9342	1522	1527	1522
q9	5946	4209	4176	4176
q10	6821	1327	1021	1021
q11	431	269	243	243
q12	635	410	294	294
q13	18059	2770	2012	2012
q14	278	255	233	233
q15	q16	732	716	662	662
q17	1718	1146	963	963
q18	6530	5606	5572	5572
q19	1201	1300	1080	1080
q20	474	408	252	252
q21	5417	2889	2679	2679
q22	423	344	298	298
Total cold run time: 100947 ms
Total hot run time: 27581 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4178	4049	4037	4037
q2	723	548	514	514
q3	4469	4841	4269	4269
q4	2227	2286	1440	1440
q5	4161	4091	4076	4076
q6	224	167	123	123
q7	1705	1580	1412	1412
q8	2156	2283	2114	2114
q9	7419	7308	7263	7263
q10	3711	3748	3146	3146
q11	559	447	377	377
q12	735	710	523	523
q13	2488	2772	2169	2169
q14	313	295	268	268
q15	q16	702	720	641	641
q17	7900	7141	7132	7132
q18	11982	11089	11863	11089
q19	1193	1077	1110	1077
q20	2234	2197	1942	1942
q21	5251	4377	4357	4357
q22	521	441	416	416
Total cold run time: 64851 ms
Total hot run time: 58385 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152707 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 c279c87489e320f5203220c440cde58cc46460f5, data reload: false

query5	4321	623	478	478
query6	454	239	206	206
query7	4808	553	305	305
query8	317	179	165	165
query9	8825	4050	4027	4027
query10	457	314	265	265
query11	5849	3560	3217	3217
query12	140	88	84	84
query13	1241	579	426	426
query14	6496	4493	4214	4214
query14_1	3901	3964	3903	3903
query15	202	200	177	177
query16	989	438	422	422
query17	889	652	540	540
query18	2409	449	319	319
query19	199	175	135	135
query20	81	80	83	80
query21	213	130	113	113
query22	13069	13038	12875	12875
query23	14062	13029	12452	12452
query23_1	12736	12462	12504	12462
query24	7280	1129	685	685
query24_1	710	711	709	709
query25	548	429	376	376
query26	1271	326	170	170
query27	2680	550	333	333
query28	4554	2019	1987	1987
query29	1663	736	519	519
query30	295	221	183	183
query31	906	756	642	642
query32	160	97	95	95
query33	545	308	261	261
query34	1172	1126	644	644
query35	723	781	634	634
query36	837	803	720	720
query37	151	105	98	98
query38	1823	1768	1685	1685
query39	695	699	670	670
query39_1	643	664	641	641
query40	223	136	102	102
query41	72	68	71	68
query42	97	99	101	99
query43	334	348	299	299
query44	1381	720	713	713
query45	185	189	168	168
query46	1083	1158	729	729
query47	1510	1508	1403	1403
query48	390	409	299	299
query49	604	400	294	294
query50	937	342	257	257
query51	10519	10464	10211	10211
query52	93	90	80	80
query53	249	262	183	183
query54	266	228	200	200
query55	86	77	71	71
query56	253	239	217	217
query57	1486	1526	1422	1422
query58	291	257	247	247
query59	2019	2067	1870	1870
query60	295	253	240	240
query61	170	164	195	164
query62	408	328	272	272
query63	221	181	183	181
query64	2899	1010	814	814
query65	3489	3385	3406	3385
query66	1827	420	309	309
query67	20211	19990	19936	19936
query68	3190	1498	928	928
query69	409	295	273	273
query70	907	829	819	819
query71	292	240	217	217
query72	2634	2536	2210	2210
query73	823	758	431	431
query74	4608	4478	4296	4296
query75	2296	2264	1926	1926
query76	2318	1137	741	741
query77	353	406	338	338
query78	9078	9162	8449	8449
query79	1415	1176	763	763
query80	573	464	389	389
query81	535	321	279	279
query82	609	160	125	125
query83	307	218	200	200
query84	320	145	116	116
query85	877	460	379	379
query86	332	235	235	235
query87	1998	1986	1825	1825
query88	3626	2745	2715	2715
query89	367	282	242	242
query90	1901	177	180	177
query91	171	170	136	136
query92	102	90	91	90
query93	1490	1448	885	885
query94	537	322	290	290
query95	674	467	336	336
query96	1035	791	375	375
query97	2448	2414	2323	2323
query98	159	152	144	144
query99	739	722	626	626
Total cold run time: 236637 ms
Total hot run time: 152707 ms

@hello-stephen

Copy link
Copy Markdown
Contributor

BE UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 63.93% (29752/46541)
Line Coverage 48.58% (309968/638035)
Region Coverage 44.08% (249797/566662)
Branch Coverage 45.67% (116167/254374)

@hello-stephen

Copy link
Copy Markdown
Contributor

BE Regression && UT Coverage Report

Increment line coverage 100.00% (1/1) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 76.29% (34381/45067)
Line Coverage 61.21% (386094/630759)
Region Coverage 57.68% (325552/564377)
Branch Coverage 58.42% (148138/253587)

@hello-stephen

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

------ Round 1 ----------------------------------
============================================
q1	17858	3802	3920	3802
q2	2138	339	286	286
q3	10156	1386	960	960
q4	4683	480	348	348
q5	7481	843	565	565
q6	185	174	135	135
q7	767	793	596	596
q8	9314	1428	1352	1352
q9	5494	4191	4163	4163
q10	6862	1338	1030	1030
q11	429	263	241	241
q12	634	410	306	306
q13	18056	2644	1994	1994
q14	275	260	240	240
q15	q16	770	728	664	664
q17	1752	1178	974	974
q18	6518	5620	5580	5580
q19	1312	1283	1059	1059
q20	491	397	266	266
q21	5924	3527	3075	3075
q22	445	365	302	302
Total cold run time: 101544 ms
Total hot run time: 27938 ms

----- Round 2, with runtime_filter_mode=off -----
============================================
q1	4627	4713	4455	4455
q2	738	547	550	547
q3	4886	5159	4594	4594
q4	2296	2350	1448	1448
q5	4557	4527	4417	4417
q6	229	170	124	124
q7	1870	1658	1448	1448
q8	2477	2039	2037	2037
q9	7300	7331	7235	7235
q10	3643	3559	3089	3089
q11	516	377	341	341
q12	702	699	497	497
q13	2288	2619	2004	2004
q14	266	286	252	252
q15	q16	656	679	601	601
q17	7333	6753	6678	6678
q18	11930	11085	11856	11085
q19	1068	1018	1008	1008
q20	2288	2184	1914	1914
q21	4976	4095	4278	4095
q22	498	461	404	404
Total cold run time: 65144 ms
Total hot run time: 58273 ms

@hello-stephen

Copy link
Copy Markdown
Contributor
TPC-DS: Total hot run time: 152632 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 c279c87489e320f5203220c440cde58cc46460f5, data reload: false

query5	4311	602	461	461
query6	428	215	195	195
query7	4901	558	304	304
query8	323	175	160	160
query9	8793	4014	4023	4014
query10	451	296	254	254
query11	5925	3541	3223	3223
query12	154	94	90	90
query13	1265	609	446	446
query14	6530	4450	4219	4219
query14_1	3959	3940	3956	3940
query15	203	201	179	179
query16	1001	460	431	431
query17	896	667	544	544
query18	2415	452	340	340
query19	203	185	147	147
query20	83	81	81	81
query21	225	136	117	117
query22	12981	12880	12762	12762
query23	14008	13076	12452	12452
query23_1	12564	12656	12482	12482
query24	7508	1121	670	670
query24_1	720	733	766	733
query25	578	427	373	373
query26	1260	307	165	165
query27	2707	512	339	339
query28	4572	2058	2046	2046
query29	1575	725	524	524
query30	299	219	179	179
query31	899	807	628	628
query32	148	99	91	91
query33	540	330	246	246
query34	1198	1095	606	606
query35	710	752	684	684
query36	815	788	724	724
query37	151	108	97	97
query38	1819	1750	1671	1671
query39	683	702	664	664
query39_1	646	639	646	639
query40	226	124	104	104
query41	71	68	69	68
query42	97	91	93	91
query43	335	343	303	303
query44	1356	744	742	742
query45	229	175	159	159
query46	1080	1216	714	714
query47	1496	1491	1370	1370
query48	406	430	280	280
query49	581	397	289	289
query50	965	348	245	245
query51	10647	10554	10389	10389
query52	89	88	74	74
query53	233	249	177	177
query54	260	201	184	184
query55	83	72	69	69
query56	214	231	223	223
query57	1453	1394	1347	1347
query58	289	264	265	264
query59	1965	2048	1856	1856
query60	274	241	241	241
query61	147	143	144	143
query62	398	332	263	263
query63	214	172	174	172
query64	2829	988	831	831
query65	3476	3388	3380	3380
query66	1805	430	300	300
query67	20257	20174	19960	19960
query68	3074	1556	960	960
query69	415	307	253	253
query70	893	854	794	794
query71	303	234	213	213
query72	2643	2747	2259	2259
query73	834	774	450	450
query74	4603	4484	4267	4267
query75	2298	2293	1927	1927
query76	2308	1089	736	736
query77	356	401	301	301
query78	9190	9094	8469	8469
query79	1348	1189	768	768
query80	575	457	359	359
query81	534	323	272	272
query82	627	161	121	121
query83	300	225	199	199
query84	311	146	111	111
query85	823	457	366	366
query86	329	233	228	228
query87	2003	1983	1839	1839
query88	3649	2790	2777	2777
query89	366	297	245	245
query90	1905	181	167	167
query91	169	150	127	127
query92	103	89	80	80
query93	1504	1399	864	864
query94	535	318	285	285
query95	661	378	420	378
query96	1091	789	312	312
query97	2417	2467	2330	2330
query98	160	148	145	145
query99	733	730	616	616
Total cold run time: 236593 ms
Total hot run time: 152632 ms

@hello-stephen

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

query1	0.01	0.01	0.00
query2	0.09	0.04	0.04
query3	0.27	0.14	0.14
query4	1.61	0.14	0.14
query5	0.24	0.22	0.23
query6	1.16	0.94	0.94
query7	0.04	0.01	0.01
query8	0.05	0.04	0.03
query9	0.39	0.34	0.33
query10	0.58	0.53	0.54
query11	0.21	0.14	0.14
query12	0.19	0.18	0.14
query13	0.45	0.46	0.48
query14	0.96	0.95	0.92
query15	0.60	0.59	0.59
query16	0.30	0.33	0.32
query17	1.09	1.09	1.12
query18	0.22	0.20	0.20
query19	1.95	1.91	1.95
query20	0.01	0.01	0.01
query21	15.43	0.21	0.14
query22	4.86	0.05	0.05
query23	16.14	0.30	0.13
query24	3.02	0.43	0.33
query25	0.11	0.05	0.04
query26	0.73	0.22	0.14
query27	0.03	0.03	0.03
query28	3.59	0.74	0.34
query29	12.54	4.06	3.22
query30	0.28	0.15	0.15
query31	2.78	0.56	0.31
query32	3.22	0.59	0.50
query33	3.27	3.16	3.16
query34	15.60	3.96	3.28
query35	3.25	3.22	3.22
query36	0.54	0.42	0.43
query37	0.09	0.06	0.06
query38	0.05	0.04	0.04
query39	0.04	0.03	0.03
query40	0.18	0.15	0.14
query41	0.09	0.03	0.03
query42	0.04	0.02	0.02
query43	0.04	0.03	0.04
Total cold run time: 96.34 s
Total hot run time: 23.97 s

@qzsee
qzsee requested a review from BiteTheDDDDt September 23, 2026 11:48
@hello-stephen
hello-stephen merged commit b67f4d6 into apache:master Sep 24, 2026
33 checks passed
github-actions Bot pushed a commit that referenced this pull request Sep 24, 2026
…HLL/QuantileState cell (#67473)

When a BITMAP / HLL / QUANTILE_STATE cell on disk has a serialized
length
of 0, ColumnComplexType::insert_binary_data used to interpret the raw
page bytes as an in-memory value_type object via reinterpret_cast and
then copy-assign it, which is undefined behavior. The heap-pointer
members of BitmapValue / HyperLogLog / QuantileState were dereferenced
as if they were valid pointers, and BE processes crashed with SIGSEGV
during queries that hit read_by_rowids (e.g. lazy materialization on
aggregate / unique-key tables that carry a BITMAP value column).

Fix it by keeping the default-constructed empty object produced by
insert_default() and returning early when length == 0.

Add regression tests in be/test/core/column/column_complex_test.cpp
covering all three complex types and all three code paths that flow
into insert_binary_data.
yiguolei pushed a commit that referenced this pull request Sep 25, 2026
…ized BITMAP/HLL/QuantileState cell #67473 (#68497)

Cherry-picked from #67473

Co-authored-by: shee <13843187+qzsee@users.noreply.github.com>
yiguolei pushed a commit that referenced this pull request Sep 25, 2026
…ized BITMAP/HLL/QuantileState cell #67473 (#68497)

Cherry-picked from #67473

Co-authored-by: shee <13843187+qzsee@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants