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 1wVRRh-001xov-1f for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 10:06:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wVRRg-00Bke6-05 for pgsql-bugs@arkaria.postgresql.org; Fri, 05 Jun 2026 10:06:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1wVROg-00Biu0-0l for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 10:03:26 +0000 Received: from mail-oo1-xc30.google.com ([2607:f8b0:4864:20::c30]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wVROe-00000001Opp-0irT for pgsql-bugs@lists.postgresql.org; Fri, 05 Jun 2026 10:03:25 +0000 Received: by mail-oo1-xc30.google.com with SMTP id 006d021491bc7-69d7e72b052so1034018eaf.2 for ; Fri, 05 Jun 2026 03:03:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1780653802; cv=none; d=google.com; s=arc-20240605; b=SiakClBTCu4SkhW1rOGypE+zCF8cIodX+YJ3ZhJAH8WXL3bhKWG+sAp44IYWdSk2N2 7GoC2H3F3YllCNxei8ksKE5GSa1Z/7sRfGtuZ41ndJnCJHR0SciyrxqYuaDL3rZFc9qC rV7njOimC+5jiHviDuGI/Wo6I6KqNkDe25IDW2/y9CbFiMURNf5xtwqk25WjrQLRVUY7 rAYDvFcJq8QoUAKNMMkxt6BZLlM7xkXPUgKJExPDMq4Anzxo6Pd8xlupdEvjFs1gVmTF IK6IWtMzQeqKyx+u1cekszMA7FzEZIB6sUQJjJyKQSC+LIo0yzt+aw/mhed14rf31/c/ eBcA== 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=rZeC1z5xBa2Nu9IAxguYDZrpUK9b55xxpbyAtD+fVuA=; fh=dJd6bLvr/PGaYQujVQqrqlm81IA18q8bDYnK/WWArn0=; b=AvS0TXOsEjPPwwosyrrAtUrj1vFNv1vypUHD6smAbAwPskdgWKoYSDmxpYFLk6SJq2 j7Jm/Il2TLbGqwEuPjZTiNqT6Ej4ygJ5gC8PDE1HQK1irrMAUBgNXGlFSTAYme0JkDJ1 QbxN2RQmuN8RULHORex8o1S1iMLylMV34Wt5FOH/jGe5FvdZ0gEBsJep+nysEv8YVcy8 4IPBAu2CBKyKVe67bMlsEeiDAWMi9QdLTm/liutKUYjedFx9hgffsXJsCYe/rYpYVxwl 9iHfSFKrxacOsZeMLHaS0r4suAWeBm9e+U3TyyVwqRXX8BtMuQvXRWjTJLO6VlT+ghy/ Uc4w==; 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=1780653802; x=1781258602; 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=rZeC1z5xBa2Nu9IAxguYDZrpUK9b55xxpbyAtD+fVuA=; b=XyexLYLN0BaZS/h1Eb8j7V0jhE0NaqsB0nMpSzLdqkY8C7IhICBqul6qM5p3GrJkTO vWoexA1HgAhVtDAQRN/3dkg4QqycBZ69rqxS0T0ieOB15Ucq3bzSa9LLEi+Ny8najaxv JrCdwtuzdZvDEf5wFpZ8eLblDhWCLQCIxxyxq2pEiLo/BGLuzMtm2uUWXXzQzuoGtn58 +B+hCCFSYo6bXarpAgceh9vySCBHM3zR7vol+fRI+H+ayhGOy6u0uxGNP6A5GH5G9RTO U3SYzLexG5UqYr25XeNmJwMXfdgKHcmLXhq8vB6ha/+zSogYZvL12jWCEKK4pOysEiwV fXNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780653802; x=1781258602; 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=rZeC1z5xBa2Nu9IAxguYDZrpUK9b55xxpbyAtD+fVuA=; b=IvaILuu5cmDtPlokCccYgIj/8Sy1+e+UzlshZKPVa1ZgwImyAn1pIhTj7xlgW45ljT N1HVx61PFCfpwYjWES3VpbYT35ScsqbxkMY+rkTUhnQGZolNZVJ3OHWu9J6HAqx98Q/S qzgVTz+TnmQMyGPNQ1BMoqWJUiRjSpooTzWMHa2NRtZcjJfKOOvlpUSPtCITkoLRr3gv juglVSuOxS9h0F3MpzUlyQMRbBfgBNCj4ORnDOQA941FpNyc5NezIFWvm9PjCyjyeC6G UE5xoHo35Z97rt5yJz6wrZVrEHMXK8b9rH9VnVYtoMwZQWB8JXQL5amI0p8qnajs04+m TmyQ== X-Forwarded-Encrypted: i=1; AFNElJ88+LgCTsFhI/odL5wQFUAukLlVlQcG/pIS5FsP0MILqxZLghnn40aZqjRxU114VDLzmhB3opGmaJrV@lists.postgresql.org X-Gm-Message-State: AOJu0YzpDFa2Nat1Kvioyy4r+yliW80MPxXnhKwYbViFgWKeIMFQHPy9 mh9dd82AQ98c9+nxglI9/AQMkAn1yvFSsd15PzYStEwNt8Rd50eYKyYw40sIyrHx13jna44lXsZ mBJ/Wnymzhu4c9WbMD3d8Nz9R7695r7A= X-Gm-Gg: Acq92OGJ4QGm0fHMCdUqs20yN6uaSrJLQEboQN3KBTIEVo4t4oIoceS93NFr9KN+wIF cnvhcG1qfBcr6viRKlcBR/8OP7FFh2gVyvGLefjSkFqZj5ydv5GDEDH6xJ87RPBXMm3oWM/OFg5 QxvfxtpC0MVlI3Ib3MGPNgdSP6/39nVXNhbvP982CaNZ5Vhoi4YTJu38p/2ZA3Men6/2VTikQNo XHwmyJgP9n7hyLn6oML/NVDTOQ3F1yr171Llv4JyMuMIt9Wan8gxQ94gnhL9AWgLnztfAWla5iK UU4mf6Bwm6a43u84tA== X-Received: by 2002:a05:6820:2221:b0:69e:40a1:5fcf with SMTP id 006d021491bc7-69e68b1b308mr1522110eaf.5.1780653802355; Fri, 05 Jun 2026 03:03:22 -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: Fri, 5 Jun 2026 15:03:11 +0500 X-Gm-Features: AVVi8CdHidmjT_xgfLsw8q6OcSubVZ7xvsb0w_TvwW9UFHHm5psX3DO9sTe2Zpo 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="0000000000005b8f2906537ec5c4" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000005b8f2906537ec5c4 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable The growing allocation is leaked temporary JsonValueLists in executePredicate() (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 via executeItemOptUnwrapResult[NoThrow]() =E2=86=92 executeNextItem() =E2=86=92 JsonValueListAppend() (~1165, ~2451), but the interim lists are never freed 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 w= ithout missing vars =E2=80=94 Tom Lane demonstrated this on master (5a2043bf713) w= ith $[*] ? (@ < $) 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. =D0=BF=D1=82, 5 =D0=B8=D1=8E=D0=BD. 2026=E2=80=AF=D0=B3. =D0=B2 13:58, Amit= Langote : > Hi, > > Before I dig into the patch properly after the weekend, one question > on the report itself: has anyone traced why the old path runs away on > memory? We've characterized it as missing-var, then null, then > evaluation continues, then OOM, but I don't think the actual growing > allocation has been pinned down. Mostly want to understand whether the > same runaway is reachable without a missing variable, since raising > the error early wouldn't catch those cases. > > - Thanks, Amit > --0000000000005b8f2906537ec5c4 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
The growing allocation is leaked temporar= y JsonValueLists in executePredicate() (local lseq/rseq, ~1482=E2=80=931547= ) and the arithmetic helpers executeBinaryArithmExpr() / executeUnaryArithm= Expr() (~1561=E2=80=931684). Each nested comparison or arithmetic subexpres= sion materializes operands via executeItemOptUnwrapResult[NoThrow]() =E2=86= =92 executeNextItem() =E2=86=92 JsonValueListAppend() (~1165, ~2451), but t= he interim lists are never freed before return. For @? specifically, execut= eJsonPath() also leaks a local vals list in strict exists mode (~579=E2=80= =93586).

Missing vars make the AFL case worse by returning null inst= ead of error, so evaluation continues deep into nested $?()/comparisons ins= tead of stopping at the first $"=E2=80=A6" reference. The same le= ak mechanism is reachable without missing vars =E2=80=94 Tom Lane demonstra= ted this on master (5a2043bf713) with $[*] ? (@ < $) on a large array.
Our missing-variable patch fixes the reported OOM and the @? semantic= s bug by aborting early. Whether REL_14/15/16 also need a broader fix for i= nterim JsonValueList cleanup is beyond what I can confidently propose; I= 9;ve tried to pin down where the growth happens for that discussion.

=D0=BF=D1=82, 5 =D0=B8=D1=8E=D0=BD. 2026=E2=80=AF=D0=B3.= =D0=B2 13:58, Amit Langote <= amitlangote09@gmail.com>:
Hi,

Before I dig into the patch properly after the weekend, one question
on the report itself: has anyone traced why the old path runs away on
memory? We've characterized it as missing-var, then null, then
evaluation continues, then OOM, but I don't think the actual growing allocation has been pinned down. Mostly want to understand whether the
same runaway is reachable without a missing variable, since raising
the error early wouldn't catch those cases.

- Thanks, Amit
--0000000000005b8f2906537ec5c4--