Skip to content

Commit 45c49e6

Browse files
committed
[yugabyte#27447] YSQL: avoid ASAN failure in multirange code
Summary: Running Java test TestPgRegressPgTypesUDT on ASAN fails with ts1|pid74720|:24411 ${YB_SRC_ROOT}/src/postgres/src/include/lib/sort_template.h:301:15: runtime error: applying non-zero offset 8 to null pointer ts1|pid74720|:24411 #0 0x55eb30c5c61b in qsort_arg ${YB_SRC_ROOT}/src/postgres/src/include/lib/sort_template.h:301:15 ts1|pid74720|:24411 #1 0x55eb30883c9a in multirange_canonicalize ${YB_SRC_ROOT}/src/postgres/src/backend/utils/adt/multirangetypes.c:481:2 ts1|pid74720|:24411 #2 0x55eb30883c9a in make_multirange ${YB_SRC_ROOT}/src/postgres/src/backend/utils/adt/multirangetypes.c:648:16 ts1|pid74720|:24411 #3 0x55eb2ffd01db in ExecInterpExpr ${YB_SRC_ROOT}/src/postgres/src/backend/executor/execExprInterp.c:731:8 ... ts1|pid74720|:24411 SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior ${YB_SRC_ROOT}/src/postgres/src/include/lib/sort_template.h:301:15 ts1|pid74720|:24411 2025-05-30 04:15:01.687 UTC [74992] WARNING: server process (PID 76254) exited with exit code 1 ts1|pid74720|:24411 2025-05-30 04:15:01.687 UTC [74992] DETAIL: Failed process was running: select textmultirange(); pg_regress|pid75085|stdout test yb.port.multirangetypes ... FAILED (test process exited with exit code 2) 1615 ms The issue is that multirange_constructor0 passes NULL, which flows all the way down to qsort_arg, and qsort_arg attempts pointer arithmetic on that NULL. Fix by returning early before that. This fix may impact other cases besides multirange since qsort_arg is used in several places, but given no issues were reported till now, perhaps it isn't possible to pass NULL to qsort_arg through those places. Jira: DB-16985 Test Plan: On Almalinux 8: ./yb_build.sh asan daemons initdb \ --java-test 'org.yb.pgsql.TestPgRegressPgTypesUDT#schedule' Close: yugabyte#27447 Reviewers: telgersma Reviewed By: telgersma Subscribers: yql Differential Revision: https://phorge.dev.yugabyte.com/D44464
1 parent d86bf40 commit 45c49e6

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/postgres/src/include/lib/sort_template.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,15 @@ ST_SORT(ST_ELEMENT_TYPE * data, size_t n
296296

297297
loop:
298298
DO_CHECK_FOR_INTERRUPTS();
299+
/*
300+
* YB: avoid ASAN undefined-behavior issue by returning early before
301+
* pointer arithmetic on NULL.
302+
*/
303+
if (a == NULL)
304+
{
305+
Assert(n == 0);
306+
return;
307+
}
299308
if (n < 7)
300309
{
301310
for (pm = a + ST_POINTER_STEP; pm < a + n * ST_POINTER_STEP;

0 commit comments

Comments
 (0)