Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wZn24-001HhS-0j for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jun 2026 09:58:04 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZn23-005TDq-0J for pgsql-bugs@arkaria.postgresql.org; Wed, 17 Jun 2026 09:58:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wZn22-005TDi-2L for pgsql-bugs@lists.postgresql.org; Wed, 17 Jun 2026 09:58:02 +0000 Received: from mail-oo1-xc32.google.com ([2607:f8b0:4864:20::c32]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZn21-00000000mo6-19FB for pgsql-bugs@lists.postgresql.org; Wed, 17 Jun 2026 09:58:01 +0000 Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-69e4ac3b37fso4073837eaf.1 for ; Wed, 17 Jun 2026 02:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781690280; cv=none; d=google.com; s=arc-20240605; b=i5Qo6FjwSUMiAfBafKCzTmGmLLJnJvhRT9IRSWPzIDtlCUsmXqXKFwrNL/VY3/c8LE NMhIYrI6AAYAjiI5DMZKFgf3qyzwiBymzdCXq1eSx5ttJYPGl/DRm7UQNl4wz/E8p/dl GcgClp9z8wgFzdR1vhDzbV0YhhxlOHckX1Yx6tE7m4X60QF5E1wAeFU98291238l5ZWF CK5OlryvMWhmWNTi/4YRlzSJKGhMS0ZMvCBNBpl8vwICdLgpoBfQNf6Lbdiu0sV+EMjQ s/T1dV21VL7TVqISwCpLe5C45Vr5E1IHVMGbiM6XpHzALHX6yRaDWhVt/ImTE+lXh0+4 9PSw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=ArsuhWoNlyqhoKHTmw88bpbdeYL+NgmACD5JS5xEoSc=; fh=0iYbO2hTS8l+eusuPglbJ5mleYB8FPw0PJ4JPmT45s8=; b=jq7Eoz2eWI9RaKb2nIhfWHOi0dnjC6wyZweSAkJ7Xzgfuif6frWZOj4qGMwfqnKlHd xZihCY0YofTuVofN8HMyCMz9v6r6gkBH9evIATUeS7w1U5V2WI3XUij0dUL4DiOcyxJh +wRtTOMUv59dTmUcJ9It9iq7Hl8W3h7F6qeI+mDP69/eG7HVHDMpDMW4SblJxbfF6Ffj TrEIEjx9pgNKW4KfOFvtDjTEageblLRUF0jj5uyYU7cAVCixIOgUQITRYVn+BPWHHodQ zxk+9vDopMun9lkPjWVCaXV1sGh6mQZ5Accsz5t/ldW2A6NPcv93VyQJVgLEJlATtcZe jfAA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781690280; x=1782295080; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=ArsuhWoNlyqhoKHTmw88bpbdeYL+NgmACD5JS5xEoSc=; b=rlgux+J/NG/tXn9U37L5iFCV46stlyBF3BpexAL9wokFNpWPlZizE+pzdF06+fR062 k6YbyM6gfNYSS66+ZwbrzFgGufPvc18yYymiJWmt9ZJUi3sQsc3gOnxkMGxZ+qUPlUKJ udwXggYpbt0B3jwm7KBP3keHVvOZ94V1JGeIhyaGlWO3gm5vsTrTju32/xBvJLzTBxQi WMsVPGsBa3mGsBcn5VUM6qpdI4mkrHor1XxoaKCNaKvvdETBC6IAeRyyGdXhyP4LAem3 3Jgr3hcQiqFv5TgoMjuBtnTawdPOrTYG4Sjtd5y+A8hOu2Et3F2YDSc5pN5kC/67Gprf 18qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781690280; x=1782295080; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ArsuhWoNlyqhoKHTmw88bpbdeYL+NgmACD5JS5xEoSc=; b=AE6KCBtf99AXOcOycq8s1XBJrAPwduavNdsUVDderM7PHR2vmbhGzU5xmjBpwLBd2h B5ZymTjWWNJZgRe9aejiFcO1uLCX+PUsswMDldp+c/GmAbFwHUgHILFZYbIALkUePnIs A2HRjQoCTowGcG9tnX3wVIA5ZPYVzl5RCrH2v+z03RW/I0JxdE9uLcTspy8RTc5bEkDj VP4aFpYnGOYlO3EHtMOLuMKMMfLZZ/1QImW1P9cHto/jYz5F3oYysUbIzvZX5BhAaXXT Q6hd5s2Q1/nsxII6phAxcIK/mBhbPdYLGsRcjfly+gZ33MAeHQsihGKoROh0jKdxbGTO mdBQ== X-Forwarded-Encrypted: i=1; AFNElJ9+2Yg0iDyj2fc0roROL3tYwNsDWWDwuLaIizxDg3tRlPzFRIMvpq7tvpfDqkQGuxKwthwYAQ0SkWec@lists.postgresql.org X-Gm-Message-State: AOJu0YyyiL6ryWvs8ss3qkJQvvt8aw4R01fFIbiJ2NmzXBgSn7hbm9vl gu+vIxleVP3Noisl3ArMwA7nh7lLBvIQIqUKFCM/8zhlY2AFEeR+YwdvBVeBNy35kSAWmmz2kfI SN3tDAZdqSHa1x8vk8NfbQeMmaPUBuLs= X-Gm-Gg: Acq92OEThjMQSYybUZbj1sHsa2zCbUYVDjyAUxWrOoELx/nq5Br1E24A1yg7abTqMpT 6eIsDTHrE193TmGWRUpSYCba/h7Mrv+J0xzoTSWjDIURMdr+l0Jhrqfiv45+UWQm8C6Z5YVM8k5 4B0/3OCalbLzyL9MWwQqtVBUF+lSfTG8USrEBfshlXSgLCL+xoD+VM2DNAxPwrHYi3TO9UcoJyO yekbsYCVCwd0GKjJ2FocyJO3a2PTssF1BVjVvPutjd2csbkqR8sP0p2l8Ik3LtnTzc2FqoC X-Received: by 2002:a05:6820:f008:b0:69e:3bdb:70f5 with SMTP id 006d021491bc7-6a0b6273106mr2175511eaf.55.1781690280244; Wed, 17 Jun 2026 02:58:00 -0700 (PDT) MIME-Version: 1.0 References: <19458-a69c98bc498333ba@postgresql.org> <6DE4A9D6-6D5C-41C0-8AFE-F51CFBDDAD5A@yandex-team.ru> <674AEA44-D9C5-423D-B118-693CA130106E@yandex-team.ru> In-Reply-To: From: Andrey Rachitskiy Date: Wed, 17 Jun 2026 14:57:48 +0500 X-Gm-Features: AVVi8CcBAQgCANUyVZI9aotBNyQzn_d09WRX6Kbl0_Oy8tqlfqJ4VxCunvBebzY Message-ID: Subject: Re: BUG #19458: OOM killer in jsonb_path_exists_opr (@?) with malformed JSONPath containing non-existent variables To: Amit Langote Cc: Andrey Borodin , Nikita Malakhov , PostgreSQL mailing lists , Nikolay Shaplov Content-Type: multipart/alternative; boundary="00000000000040fa9c06547018fe" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --00000000000040fa9c06547018fe Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi Amit, I tested patch v2-0001-Report-undefined-jsonpath-variable-when-no-variab.patch on: REL_14_STABLE REL_15_STABLE REL_16_STABLE Results: The patch applies cleanly on all three branches. Regression tests added/affected by the patch pass on all three branches: REL_14: all relevant tests passed REL_15: all relevant tests passed REL_16: all relevant tests passed The provided jsonpath reproducer query now consistently returns an error about an undefined jsonpath variable on all three branches, which matches the expected behavior change from this patch. Conclusion: The patch looks good from the testing side and can be merged. =D1=81=D1=80, 17 =D0=B8=D1=8E=D0=BD. 2026=E2=80=AF=D0=B3. =D0=B2 13:27, Ami= t Langote : > Hi Andrey, > > On Fri, Jun 5, 2026 at 7:03=E2=80=AFPM Andrey Rachitskiy > wrote: > > The growing allocation is leaked temporary JsonValueLists in > executePredicate() (local lseq/rseq, ~1482=E2=80=931547) and the arithmet= ic helpers > executeBinaryArithmExpr() / executeUnaryArithmExpr() (~1561=E2=80=931684)= . Each > nested comparison or arithmetic subexpression materializes operands via > executeItemOptUnwrapResult[NoThrow]() =E2=86=92 executeNextItem() =E2=86= =92 > JsonValueListAppend() (~1165, ~2451), but the interim lists are never fre= ed > before return. For @? specifically, executeJsonPath() also leaks a local > vals list in strict exists mode (~579=E2=80=93586). > > > > Missing vars make the AFL case worse by returning null instead of error= , > so evaluation continues deep into nested $?()/comparisons instead of > stopping at the first $"=E2=80=A6" reference. The same leak mechanism is = reachable > without missing vars =E2=80=94 Tom Lane demonstrated this on master (5a20= 43bf713) > with $[*] ? (@ < $) on a large array. > > > > Our missing-variable patch fixes the reported OOM and the @? semantics > bug by aborting early. Whether REL_14/15/16 also need a broader fix for > interim JsonValueList cleanup is beyond what I can confidently propose; > I've tried to pin down where the growth happens for that discussion. > > Thanks for that tracedown and for pointing to Tom's commit. The deeper > interim-JsonValueList leak looks unlikely to get fixed in the back > branches; Tom's cleanup (5a2043bf713) went only to master. > > I'll look at committing the attached revised version of your Apr 20 > patch (same fix, plus a regression test) down to REL_14. Please > check/test. > > -- > Thanks, Amit Langote > --=20 --- Regards, Andrey Rachitskiy Postgres Professional --00000000000040fa9c06547018fe Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hi = Amit,

I tested patch v2-0001-Report-undefined-jsonpath-variable-when= -no-variab.patch on:

REL_14_STABLE
REL_15_STABLE
REL_16_STABLE=

Results:
The patch applies cleanly on all three branches.
Reg= ression tests added/affected by the patch pass on all three branches:
RE= L_14: all relevant tests passed
REL_15: all relevant tests passed
REL= _16: all relevant tests passed
The provided jsonpath reproducer query no= w consistently returns an error about an undefined jsonpath variable on all= three branches, which matches the expected behavior change from this patch= .

Conclusion:
The patch looks good from the testing side and can = be merged.

=D1=81=D1=80, 17 =D0=B8=D1=8E=D0= =BD. 2026=E2=80=AF=D0=B3. =D0=B2 13:27, Amit Langote <amitlangote09@gmail.com>:
Hi Andrey,

On Fri, Jun 5, 2026 at 7:03=E2=80=AFPM Andrey Rachitskiy <pl0h0yp1@gmail.com> wrote:=
> The growing allocation is leaked temporary JsonValueLists in executePr= edicate() (local lseq/rseq, ~1482=E2=80=931547) and the arithmetic helpers = executeBinaryArithmExpr() / executeUnaryArithmExpr() (~1561=E2=80=931684). = Each nested comparison or arithmetic subexpression materializes operands vi= a executeItemOptUnwrapResult[NoThrow]() =E2=86=92 executeNextItem() =E2=86= =92 JsonValueListAppend() (~1165, ~2451), but the interim lists are never f= reed before return. For @? specifically, executeJsonPath() also leaks a loc= al vals list in strict exists mode (~579=E2=80=93586).
>
> Missing vars make the AFL case worse by returning null instead of erro= r, so evaluation continues deep into nested $?()/comparisons instead of sto= pping at the first $"=E2=80=A6" reference. The same leak mechanis= m is reachable without missing vars =E2=80=94 Tom Lane demonstrated this on= master (5a2043bf713) with $[*] ? (@ < $) on a large array.
>
> Our missing-variable patch fixes the reported OOM and the @? semantics= bug by aborting early. Whether REL_14/15/16 also need a broader fix for in= terim JsonValueList cleanup is beyond what I can confidently propose; I'= ;ve tried to pin down where the growth happens for that discussion.

Thanks for that tracedown and for pointing to Tom's commit. The deeper<= br> interim-JsonValueList leak looks unlikely to get fixed in the back
branches; Tom's cleanup (5a2043bf713) went only to master.

I'll look at committing the attached revised version of your Apr 20
patch (same fix, plus a regression test) down to REL_14. Please
check/test.

--
Thanks, Amit Langote


--
-= --
Regards,
Andrey Rachitskiy
Postgres Professional
--00000000000040fa9c06547018fe--