pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feeduse-after-free in jsonb_set_lax()
8+ messages / 4 participants
[nested] [flat]
Commits from this thread:
2026-10-19 cb98b23da3 52af12e9d9 723075b031 4a3177299f b3477b1cab 42b320abe3 e355089a57 Fix use-after-free in jsonb_set_lax for Const NULL new_value
* use-after-free in jsonb_set_lax()
@ 2026-10-15 02:44 John Naylor <johncnaylorls@gmail.com>
2026-10-15 04:08 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
2026-10-15 09:08 ` Re: use-after-free in jsonb_set_lax() Laurenz Albe <laurenz.albe@cybertec.at>
0 siblings, 2 replies; 8+ messages in thread
From: John Naylor @ 2026-10-15 02:44 UTC (permalink / raw)
To: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
I received an off-list report of a crash in production using this
function. It's possible to reproduce a crash in a non-assert build
with a fuzzing script, but the easiest demo of the problem is (on an
assert build):
=# SELECT jsonb_set_lax(j, '{a}', NULL, true, t)
FROM (VALUES (jsonb_build_object('a', '1'), 'use_json_null'),
(jsonb_build_object('a', '1'), 'delete_key')) AS v(j, t);
ERROR: unknown type of jsonb container
I've attached a fix, which I plan to commit to all supported versions
in a couple days barring objections.
I didn't find any other places in the code base with a similar bug,
but of course I can't be certain.
--
John Naylor
Amazon Web Services
Attachments:
v1-0001-Fix-use-after-free-in-jsonb_set_lax-for-Const-NUL.patch (text/x-patch, 4.2K) download
From 3032fd443e32afd049682b8346872d534718b6ae Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Thu, 15 Oct 2026 08:54:43 +0700
Subject: [PATCH v1] Fix use-after-free in jsonb_set_lax for Const NULL
new_value
Commit a83586b5543 decided to scribble on the caller's fcinfo but failed
to take into account that const arguments are written once at expression
init and assumed never to change.
The use_json_null branch overwrote fcinfo->args[2] with a jsonb null
built in the per-tuple expression context. In later rows,
args[2].isnull is still false and args[2].value still holds that
pointer, but the per-tuple context has been reset. Later rows find
args[2].isnull = false, short-circuit past the NULL handling at the top
of the function, and jump straight to jsonb_set with the stale pointer
regardless of their own null_value_treatment argument, which is never
read.
To fix, call jsonb_set through its own call frame instead. Arguments 0,
1 and 3 were already checked non-NULL above, so we can use
DirectFunctionCall4.
Add regression tests covering use_json_null followed by delete_key and
return_target, and a multi-row default-treatment query.
Discussion: https://postgr.es/m/
Reported-by: Evan Si <evsi@amazon.com>
Backpatch-through: 14
---
src/backend/utils/adt/jsonfuncs.c | 8 +++++---
src/test/regress/expected/jsonb.out | 28 ++++++++++++++++++++++++++++
src/test/regress/sql/jsonb.sql | 10 ++++++++++
3 files changed, 43 insertions(+), 3 deletions(-)
diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c
index adbafd0ecd3..274ed9d3184 100644
--- a/src/backend/utils/adt/jsonfuncs.c
+++ b/src/backend/utils/adt/jsonfuncs.c
@@ -4934,9 +4934,11 @@ jsonb_set_lax(PG_FUNCTION_ARGS)
newval = DirectFunctionCall1(jsonb_in, CStringGetDatum("null"));
- fcinfo->args[2].value = newval;
- fcinfo->args[2].isnull = false;
- return jsonb_set(fcinfo);
+ return DirectFunctionCall4(jsonb_set,
+ PG_GETARG_DATUM(0),
+ PG_GETARG_DATUM(1),
+ newval,
+ PG_GETARG_DATUM(3));
}
else if (strcmp(handle_val, "delete_key") == 0)
{
diff --git a/src/test/regress/expected/jsonb.out b/src/test/regress/expected/jsonb.out
index 82c31e2962b..615f6232b0d 100644
--- a/src/test/regress/expected/jsonb.out
+++ b/src/test/regress/expected/jsonb.out
@@ -4915,6 +4915,34 @@ select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'use_
{"a": 1, "b": null}
(1 row)
+-- multi-row cases with a constant NULL new_value
+select jsonb_set_lax(j, '{a}', null, true, t)
+from (values ('{"a":1}'::jsonb, 'use_json_null'),
+ ('{"a":1}'::jsonb, 'delete_key')) v(j, t);
+ jsonb_set_lax
+---------------
+ {"a": null}
+ {}
+(2 rows)
+
+select jsonb_set_lax(j, '{a}', null, true, t)
+from (values ('{"a":1}'::jsonb, 'use_json_null'),
+ ('{"a":1}'::jsonb, 'return_target')) v(j, t);
+ jsonb_set_lax
+---------------
+ {"a": null}
+ {"a": 1}
+(2 rows)
+
+select jsonb_set_lax(j, '{a}', null)
+from (values ('{"a":1}'::jsonb), ('{"a":2}'::jsonb), ('{"a":3}'::jsonb)) v(j);
+ jsonb_set_lax
+---------------
+ {"a": null}
+ {"a": null}
+ {"a": null}
+(3 rows)
+
\pset null ''
-- jsonb_insert
select jsonb_insert('{"a": [0,1,2]}', '{a, 1}', '"new_value"');
diff --git a/src/test/regress/sql/jsonb.sql b/src/test/regress/sql/jsonb.sql
index 610ee28b97f..be766f4fe53 100644
--- a/src/test/regress/sql/jsonb.sql
+++ b/src/test/regress/sql/jsonb.sql
@@ -1283,6 +1283,16 @@ select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'retu
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'delete_key') as delete_key;
select jsonb_set_lax('{"a":1,"b":2}', '{b}', null, null_value_treatment => 'use_json_null') as use_json_null;
+-- multi-row cases with a constant NULL new_value
+select jsonb_set_lax(j, '{a}', null, true, t)
+from (values ('{"a":1}'::jsonb, 'use_json_null'),
+ ('{"a":1}'::jsonb, 'delete_key')) v(j, t);
+select jsonb_set_lax(j, '{a}', null, true, t)
+from (values ('{"a":1}'::jsonb, 'use_json_null'),
+ ('{"a":1}'::jsonb, 'return_target')) v(j, t);
+select jsonb_set_lax(j, '{a}', null)
+from (values ('{"a":1}'::jsonb), ('{"a":2}'::jsonb), ('{"a":3}'::jsonb)) v(j);
+
\pset null ''
-- jsonb_insert
--
2.55.0
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: use-after-free in jsonb_set_lax()
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
@ 2026-10-15 04:08 ` Manu <manuelreyesbravo@gmail.com>
2026-10-15 05:31 ` Re: use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Manu @ 2026-10-15 04:08 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: John Naylor <johncnaylorls@gmail.com>
Hi John,
> I didn't find any other places in the code base with a similar bug,
> but of course I can't be certain.
I swept for siblings and found none. Of the 444 writes to
fcinfo->args[] in the backend, all go into a frame the function built
itself or an executor/planner frame, except 15 into a caller-supplied
frame; jsonb_set_lax is the only SQL-callable one among those. Const
args are written once at expression init in the expected places
(ExecInitFunc, the JSON constructors). Same on 14-17. A differential
multi-row vs per-row fuzz over the jsonb family (132k cases, cassert
and ASan) only ever fires in jsonb_set_lax, and is clean with v1.
One note on severity, in case it affects the classification: the
read-after-free reaches the output, not just control flow. Under ASan
the thread's repro does not crash; it silently returns {"a": null}
instead of {}, since the freed null stays in the per-tuple keeper
block. The 3-argument form jsonb_set_lax(col, path, NULL) over two
rows returns bytes of freed memory inside the result value (on a
cassert build); on a non-assert build that is reused heap, so it looks
able to disclose memory contents, not only crash or return wrong data.
Allocating ~5 kB per row turns it into a clean heap-use-after-free at
the !PG_ARGISNULL(2) shortcut. v1 is clean on all of it.
Regards,
Manu
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: use-after-free in jsonb_set_lax()
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 04:08 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
@ 2026-10-15 05:31 ` John Naylor <johncnaylorls@gmail.com>
2026-10-15 06:21 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: John Naylor @ 2026-10-15 05:31 UTC (permalink / raw)
To: Manu <manuelreyesbravo@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org
On Thu, Oct 15, 2026 at 11:08 AM Manu <manuelreyesbravo@gmail.com> wrote:
> > I didn't find any other places in the code base with a similar bug,
> > but of course I can't be certain.
>
> I swept for siblings and found none. Of the 444 writes to
> fcinfo->args[] in the backend, all go into a frame the function built
> itself or an executor/planner frame, except 15 into a caller-supplied
> frame; jsonb_set_lax is the only SQL-callable one among those. Const
> args are written once at expression init in the expected places
> (ExecInitFunc, the JSON constructors). Same on 14-17. A differential
> multi-row vs per-row fuzz over the jsonb family (132k cases, cassert
> and ASan) only ever fires in jsonb_set_lax, and is clean with v1.
Please don't copy and paste LLM output into emails. It's annoying.
--
John Naylor
Amazon Web Services
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: use-after-free in jsonb_set_lax()
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 04:08 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
2026-10-15 05:31 ` Re: use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
@ 2026-10-15 06:21 ` Manu <manuelreyesbravo@gmail.com>
2026-10-16 02:23 ` Re: use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: Manu @ 2026-10-15 06:21 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: John Naylor <johncnaylorls@gmail.com>
Hi John,
> Please don't copy and paste LLM output into emails.
It wasn't pasted; it's a real build here. The repro and the ASan report
(with my build paths in it) are attached. It runs under an ASan build in
a couple of seconds.
The point, short: on a non-assert build this is not only a crash. The
ASan report (attached) is heap-use-after-free, READ of size 1 at a
freed address, in jsonb_set at jsonfuncs.c:4859 reached from
jsonb_set_lax at 4917. The freed read lands in the value jsonb_set
returns, so the result can carry reused heap, not just wrong data. That
is what seemed worth a line for the back-branches. v1 is clean over the
multi-row cases I ran.
Regards,
Manu
Attachments:
repro_asan.sql.txt (text/plain, 408B) download
\echo == variant: arg0 computed per-row with ~5 kB padding, so the per-tuple context
\echo == spills out of its keeper block and the jsonb null lands in a block free()d on reset
SELECT jsonb_set_lax(j || jsonb_build_object('pad', repeat('x', 5000)), '{a}', NULL, true, t) - 'pad'
FROM (VALUES (jsonb_build_object('a','1'),'use_json_null'),
(jsonb_build_object('a','1'),'delete_key')) AS v(j,t);
asan-report.txt (text/plain, 11.9K) download
=================================================================
==666397==ERROR: AddressSanitizer: heap-use-after-free on address 0x7e1f71c1fce0 at pc 0x000001876f63 bp 0x7ffcb4285260 sp 0x7ffcb4285258
READ of size 1 at 0x7e1f71c1fce0 thread T0
#0 0x000001876f62 in VARATT_IS_EXTENDED ../../../../src/include/varatt.h:463
#1 0x000001876f62 in pg_detoast_datum /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/fmgr/fmgr.c:1800
#2 0x000001658fd2 in DatumGetJsonbP ../../../../src/include/utils/jsonb.h:403
#3 0x000001658fd2 in jsonb_set /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonfuncs.c:4859
#4 0x0000016599ce in jsonb_set_lax /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonfuncs.c:4917
#5 0x000000f4ce32 in ExecInterpExpr /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execExprInterp.c:936
#6 0x000000f7f889 in ExecEvalExprNoReturn ../../../src/include/executor/executor.h:431
#7 0x000000f7f889 in ExecEvalExprNoReturnSwitchContext ../../../src/include/executor/executor.h:472
#8 0x000000f7f889 in ExecProject ../../../src/include/executor/executor.h:504
#9 0x000000f7f889 in ExecScanExtended ../../../src/include/executor/execScan.h:236
#10 0x000000f7f889 in ExecScan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execScan.c:59
#11 0x0000010266c1 in ExecValuesScan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/nodeValuesscan.c:200
#12 0x000000f5c309 in ExecProcNode ../../../src/include/executor/executor.h:327
#13 0x000000f5c309 in ExecutePlan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:1766
#14 0x000000f5c309 in standard_ExecutorRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:377
#15 0x000000f5c622 in ExecutorRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:314
#16 0x0000014f5767 in PortalRunSelect /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/pquery.c:921
#17 0x0000014f931e in PortalRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/pquery.c:765
#18 0x0000014ef947 in exec_simple_query /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/postgres.c:1297
#19 0x0000014f14d3 in PostgresMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/postgres.c:4946
#20 0x0000014e631c in BackendMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/backend_startup.c:124
#21 0x0000013073a6 in postmaster_child_launch /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/launch_backend.c:268
#22 0x00000130ea20 in BackendStartup /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:3650
#23 0x00000130ea20 in ServerLoop /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:1727
#24 0x0000013116e3 in PostmasterMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:1414
#25 0x000001073f48 in main /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/main/main.c:227
#26 0x7f8f72d63300 in __libc_start_call_main (/lib64/libc.so.6+0x7d300) (BuildId: 02120880204b69a3b1f1e23a2eb47b2b12bc2636)
#27 0x7f8f72d63417 in __libc_start_main_impl (/lib64/libc.so.6+0x7d417) (BuildId: 02120880204b69a3b1f1e23a2eb47b2b12bc2636)
#28 0x0000009e7264 in _start (/home/manu/Proyectos/yggdrasil/.arboles/jslax-inst/master-asan/bin/postgres+0x9e7264) (BuildId: 937b858dcb7103a06735e294a004a9b447c26598)
0x7e1f71c1fce0 is located 15072 bytes inside of 16384-byte region [0x7e1f71c1c200,0x7e1f71c20200)
freed by thread T0 here:
#0 0x7f8f7316420f in free.part.0 (/lib64/libasan.so.8+0x16420f) (BuildId: 03bc53f1963ff3227be69a129d4fe48bb6a64b94)
#1 0x0000018b9636 in AllocSetReset /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/mmgr/aset.c:605
#2 0x0000018c7b9f in MemoryContextResetOnly /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/mmgr/mcxt.c:442
#3 0x0000018c8173 in MemoryContextReset /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/mmgr/mcxt.c:416
#4 0x000000f7ebac in ExecScanExtended ../../../src/include/executor/execScan.h:187
#5 0x000000f7ebac in ExecScan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execScan.c:59
#6 0x0000010266c1 in ExecValuesScan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/nodeValuesscan.c:200
#7 0x000000f5c309 in ExecProcNode ../../../src/include/executor/executor.h:327
#8 0x000000f5c309 in ExecutePlan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:1766
#9 0x000000f5c309 in standard_ExecutorRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:377
#10 0x000000f5c622 in ExecutorRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:314
#11 0x0000014f5767 in PortalRunSelect /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/pquery.c:921
#12 0x0000014f931e in PortalRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/pquery.c:765
#13 0x0000014ef947 in exec_simple_query /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/postgres.c:1297
#14 0x0000014f14d3 in PostgresMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/postgres.c:4946
#15 0x0000014e631c in BackendMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/backend_startup.c:124
#16 0x0000013073a6 in postmaster_child_launch /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/launch_backend.c:268
#17 0x00000130ea20 in BackendStartup /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:3650
#18 0x00000130ea20 in ServerLoop /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:1727
#19 0x0000013116e3 in PostmasterMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:1414
#20 0x000001073f48 in main /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/main/main.c:227
#21 0x7f8f72d63300 in __libc_start_call_main (/lib64/libc.so.6+0x7d300) (BuildId: 02120880204b69a3b1f1e23a2eb47b2b12bc2636)
#22 0x7f8f72d63417 in __libc_start_main_impl (/lib64/libc.so.6+0x7d417) (BuildId: 02120880204b69a3b1f1e23a2eb47b2b12bc2636)
#23 0x0000009e7264 in _start (/home/manu/Proyectos/yggdrasil/.arboles/jslax-inst/master-asan/bin/postgres+0x9e7264) (BuildId: 937b858dcb7103a06735e294a004a9b447c26598)
previously allocated by thread T0 here:
#0 0x7f8f7316515f in malloc (/lib64/libasan.so.8+0x16515f) (BuildId: 03bc53f1963ff3227be69a129d4fe48bb6a64b94)
#1 0x0000018b8bcf in AllocSetAllocFromNewBlock /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/mmgr/aset.c:950
#2 0x0000018b9ba0 in AllocSetAlloc /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/mmgr/aset.c:1096
#3 0x0000018ba1b9 in AllocSetRealloc /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/mmgr/aset.c:1473
#4 0x0000018c9683 in repalloc /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/mmgr/mcxt.c:1665
#5 0x000001926c51 in enlargeStringInfo /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/common/stringinfo.c:410
#6 0x00000163d666 in reserveFromBuffer /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:1610
#7 0x00000163d798 in appendToBuffer /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:1644
#8 0x00000163d957 in convertJsonbScalar /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:1954
#9 0x00000163eb0b in convertJsonbValue /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:1732
#10 0x00000163f297 in convertJsonbObject /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:1901
#11 0x00000163f297 in convertJsonbValue /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:1736
#12 0x00000163f5e8 in convertToJsonb /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:1690
#13 0x0000016428c1 in JsonbValueToJsonb /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb_util.c:118
#14 0x0000016339df in jsonb_build_object_worker /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb.c:1175
#15 0x000001633b47 in jsonb_build_object /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/utils/adt/jsonb.c:1195
#16 0x000000f4ce32 in ExecInterpExpr /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execExprInterp.c:936
#17 0x000000f3bafa in ExecInterpExprStillValid /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execExprInterp.c:2309
#18 0x000000f7f889 in ExecEvalExprNoReturn ../../../src/include/executor/executor.h:431
#19 0x000000f7f889 in ExecEvalExprNoReturnSwitchContext ../../../src/include/executor/executor.h:472
#20 0x000000f7f889 in ExecProject ../../../src/include/executor/executor.h:504
#21 0x000000f7f889 in ExecScanExtended ../../../src/include/executor/execScan.h:236
#22 0x000000f7f889 in ExecScan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execScan.c:59
#23 0x0000010266c1 in ExecValuesScan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/nodeValuesscan.c:200
#24 0x000000f75d43 in ExecProcNodeFirst /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execProcnode.c:469
#25 0x000000f5c309 in ExecProcNode ../../../src/include/executor/executor.h:327
#26 0x000000f5c309 in ExecutePlan /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:1766
#27 0x000000f5c309 in standard_ExecutorRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:377
#28 0x000000f5c622 in ExecutorRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/executor/execMain.c:314
#29 0x0000014f5767 in PortalRunSelect /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/pquery.c:921
#30 0x0000014f931e in PortalRun /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/pquery.c:765
#31 0x0000014ef947 in exec_simple_query /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/postgres.c:1297
#32 0x0000014f14d3 in PostgresMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/postgres.c:4946
#33 0x0000014e631c in BackendMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/tcop/backend_startup.c:124
#34 0x0000013073a6 in postmaster_child_launch /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/launch_backend.c:268
#35 0x00000130ea20 in BackendStartup /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:3650
#36 0x00000130ea20 in ServerLoop /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:1727
#37 0x0000013116e3 in PostmasterMain /home/manu/Proyectos/yggdrasil/.arboles/jslax-master-asan/src/backend/postmaster/postmaster.c:1414
SUMMARY: AddressSanitizer: heap-use-after-free ../../../../src/include/varatt.h:463 in VARATT_IS_EXTENDED
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: use-after-free in jsonb_set_lax()
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 04:08 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
2026-10-15 05:31 ` Re: use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 06:21 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
@ 2026-10-16 02:23 ` John Naylor <johncnaylorls@gmail.com>
2026-10-16 03:28 ` Re: use-after-free in jsonb_set_lax() Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
0 siblings, 1 reply; 8+ messages in thread
From: John Naylor @ 2026-10-16 02:23 UTC (permalink / raw)
To: Manu <manuelreyesbravo@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org
On Thu, Oct 15, 2026 at 1:21 PM Manu <manuelreyesbravo@gmail.com> wrote:
> > Please don't copy and paste LLM output into emails.
>
> It wasn't pasted; it's a real build here.
What Claude model was used to compose this email?
--
John Naylor
Amazon Web Services
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: use-after-free in jsonb_set_lax()
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 04:08 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
2026-10-15 05:31 ` Re: use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 06:21 ` Re: use-after-free in jsonb_set_lax() Manu <manuelreyesbravo@gmail.com>
2026-10-16 02:23 ` Re: use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
@ 2026-10-16 03:28 ` Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: Manuel Reyes Bravo @ 2026-10-16 03:28 UTC (permalink / raw)
To: John Naylor <johncnaylorls@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org
>What Claude model was used to compose this email?
Claude, as a drafting aid. The sweep, the fuzzing and the ASan runs
are mine and ran on my machines; that is what I meant by "not pasted",
but I should have answered the actual question. Point taken on the style,
I’ll keep future emails to the facts. Nothing further from me on this one;
thanks for the fix.
Regards,
Manu
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: use-after-free in jsonb_set_lax()
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
@ 2026-10-15 09:08 ` Laurenz Albe <laurenz.albe@cybertec.at>
2026-10-19 05:02 ` Re: use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
1 sibling, 1 reply; 8+ messages in thread
From: Laurenz Albe @ 2026-10-15 09:08 UTC (permalink / raw)
To: John Naylor <johncnaylorls@gmail.com>; pgsql-bugs <pgsql-bugs@lists.postgresql.org>
On Thu, 2026-10-15 at 09:44 +0700, John Naylor wrote:
> I received an off-list report of a crash in production using this
> function. It's possible to reproduce a crash in a non-assert build
> with a fuzzing script, but the easiest demo of the problem is (on an
> assert build):
>
> =# SELECT jsonb_set_lax(j, '{a}', NULL, true, t)
> FROM (VALUES (jsonb_build_object('a', '1'), 'use_json_null'),
> (jsonb_build_object('a', '1'), 'delete_key')) AS v(j, t);
> ERROR: unknown type of jsonb container
>
> I've attached a fix, which I plan to commit to all supported versions
> in a couple days barring objections.
>
> I didn't find any other places in the code base with a similar bug,
> but of course I can't be certain.
Funny, I also received a bug report about a crash in jsonb_set_lax()
yesterday, and your patch fixes the problem.
The reproducer I got was
WITH RECURSIVE c AS ( SELECT 1 n,
jsonb_set_lax('{"a":1}'::jsonb,'{a}',NULL,true,'use_json_null') j
UNION ALL
SELECT n+1, jsonb_set_lax(jsonb_build_object('n',n,'p',j,'x',repeat('A',500)),'{n}',NULL,true,
CASE WHEN n%2=0 THEN 'delete_key' ELSE 'use_json_null' END)
FROM c WHERE n<80
) SELECT n FROM c ORDER BY n DESC LIMIT 1;
So, +1 from me!
Yours,
Laurenz Albe
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: use-after-free in jsonb_set_lax()
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 09:08 ` Re: use-after-free in jsonb_set_lax() Laurenz Albe <laurenz.albe@cybertec.at>
@ 2026-10-19 05:02 ` John Naylor <johncnaylorls@gmail.com>
0 siblings, 0 replies; 8+ messages in thread
From: John Naylor @ 2026-10-19 05:02 UTC (permalink / raw)
To: Laurenz Albe <laurenz.albe@cybertec.at>; +Cc: pgsql-bugs <pgsql-bugs@lists.postgresql.org>
On Thu, Oct 15, 2026 at 4:08 PM Laurenz Albe <laurenz.albe@cybertec.at> wrote:
> Funny, I also received a bug report about a crash in jsonb_set_lax()
> yesterday, and your patch fixes the problem.
Glad to hear it! Pushed. (although I forgot to give you a tested-by credit..)
--
John Naylor
Amazon Web Services
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2026-10-19 05:02 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-10-15 02:44 use-after-free in jsonb_set_lax() John Naylor <johncnaylorls@gmail.com>
2026-10-15 04:08 ` Manu <manuelreyesbravo@gmail.com>
2026-10-15 05:31 ` John Naylor <johncnaylorls@gmail.com>
2026-10-15 06:21 ` Manu <manuelreyesbravo@gmail.com>
2026-10-16 02:23 ` John Naylor <johncnaylorls@gmail.com>
2026-10-16 03:28 ` Manuel Reyes Bravo <manuelreyesbravo@gmail.com>
2026-10-15 09:08 ` Laurenz Albe <laurenz.albe@cybertec.at>
2026-10-19 05:02 ` John Naylor <johncnaylorls@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox