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.94.2) (envelope-from ) id 1rmzRn-00B01y-LQ for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Mar 2024 17:09:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rmzRl-006dLK-Db for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Mar 2024 17:09:49 +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.94.2) (envelope-from ) id 1rmzRl-006dLB-3h for pgsql-hackers@lists.postgresql.org; Wed, 20 Mar 2024 17:09:49 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1rmzRi-005a17-8U for pgsql-hackers@lists.postgresql.org; Wed, 20 Mar 2024 17:09:48 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-5101cd91017so94660e87.2 for ; Wed, 20 Mar 2024 10:09:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb.com; s=google; t=1710954585; x=1711559385; darn=lists.postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=s/gZ/qvWTbLYFIlE+hkhLjx7IToPxTxiI1RoV5NyEo4=; b=LMVhH0xJO8NlqJ7lfDZLe8ivHEn1c1h7Ezd8Fiek4KRqG2fQLMF3P9T2AsfipfaEh9 9C0hQiuErH6yvFLgF9yPyDMBTidnuazwN1RFjWeUDYbSteaUDszK5x4Qa/mkDcOZQY2u Ced5Cw78JWf4qpKohgfDGHWqo7Kr0kYAbBccM4Hsoe9AAvoIUaBPr444mNrNNVv243dy nTMp3Xhtsp6gWDM7TPM0SLGn7IvP2XI7LptTPEEpUsb3zMWtVngeq71V5hhpqqhJMt7w ergftfvIlR1/3P+OFSDm118yP50hguSH0ER/Z0Edw+y1F1igYU5AeKl110JpAsIr4A0e t4bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710954585; x=1711559385; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s/gZ/qvWTbLYFIlE+hkhLjx7IToPxTxiI1RoV5NyEo4=; b=eA+THCiyJy7AeIrTGyUNAmtRPOhUQ1NlnfjfrOi2qvwmgD2RU6BY2rQL4Osh2Vqcml +W9NMrXPnuNtCXig+pRZNEdd5HkYUcmZuQym2o6wI6Cg3/X2medyCDM4JFzoYL1vmmf5 +q7JfDtybPORct98pixzbCyG/GFLix9yKE7tCTZnIs8AdcHzpJT/EjyKMAposTFpD4pP aHV2qLLFBZWqUeLCHazzh8JNqRG4NfPbh8lnBzsTtOrMf3iu3M0JvoZjX3Cl7mra0n08 G3UORdtDAgQGynVlSuC5Hh4l+rHD3iSUNgVXEBMkNDPWUUN0xTQziorwWHhNzKdz2vdG elRg== X-Forwarded-Encrypted: i=1; AJvYcCUfc0vf2aRrQCKAHYdaldUOhB2SVppfwYWptB87ySnK3tTpkLC/UhCghSdkvK4cOuytrBWVJ70gcTaWt3MOxBrkS8PDye/ZYMpb6x7erOmktqcc X-Gm-Message-State: AOJu0YwomHNtmVThpTUCzLltadd2Rxm9qAr5eBtoJDVawLGg9lpgGJ6G 7TqmOGWLYRu0hJbo6us+ynfQmdgEK5yj0iFvtCvcxEPkzQSJ80FwQ/1LqvQB3ZN2mfqbOlJks2l xKCbrtxiOv6KdhkiVa2Ajsm/px51a3PJfYi03 X-Google-Smtp-Source: AGHT+IHCg9sKtjOjlN0Qb3NkBPlsVQwBSEm05bHOAeRSzz6RoRCoPRQiySZ9GRJ4YG65aGBHrIFhxnB9CZLlzzs20vU= X-Received: by 2002:ac2:5a0a:0:b0:513:cf73:d8d2 with SMTP id q10-20020ac25a0a000000b00513cf73d8d2mr10462893lfn.54.1710954584926; Wed, 20 Mar 2024 10:09:44 -0700 (PDT) MIME-Version: 1.0 References: <7b0a51d6-0d9d-7366-3a1a-f74397a02f55@dunslane.net> <3892d996-0ec8-3a56-1a6c-b397a3c31516@dunslane.net> <3efe8333-3285-1d9d-5ad3-0f9784d5c1c4@dunslane.net> <1778cdac-bb93-5bbd-1505-5684e95b0094@dunslane.net> <1b30469a-9d29-c021-f28a-74e248760aa4@dunslane.net> <682c8fff-355c-a04f-57ac-81055c4ccda8@dunslane.net> <70705cf3-c875-d489-c6a9-7dd61f1dc1af@dunslane.net> <694fd815-0414-0f09-98b3-db28d77fa37f@dunslane.net> In-Reply-To: From: Jacob Champion Date: Wed, 20 Mar 2024 10:09:33 -0700 Message-ID: Subject: Re: WIP Incremental JSON Parser To: Andrew Dunstan Cc: Robert Haas , Peter Smith , PostgreSQL Hackers Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, Mar 19, 2024 at 3:07=E2=80=AFPM Andrew Dunstan wrote: > On Mon, Mar 18, 2024 at 3:35=E2=80=AFPM Jacob Champion wrote: >> With the incremental parser, I think prev_token_terminator is not >> likely to be safe to use except in very specific circumstances, since >> it could be pointing into a stale chunk. Some documentation around how >> to use that safely in a semantic action would be good. > > Quite right. It's not safe. Should we ensure it's set to something like N= ULL or -1? Nulling it out seems reasonable. > Also, where do you think we should put a warning about it? I was thinking in the doc comment for JsonLexContext. > It also removes the frontend exits I had. In the case of stack depth, we = follow the example of the RD parser and only check stack depth for backend = code. In the case of the check that the lexer is set up for incremental par= sing, the exit is replaced by an Assert. That means your test for an over-n= ested array doesn't work any more, so I have commented it out. Hm, okay. We really ought to fix the recursive parser, but that's for a separate thread. (Probably OAuth.) The ideal behavior IMO would be for the caller to configure a maximum depth in the JsonLexContext. Note that the repalloc will eventually still exit() if the pstack gets too big; is that a concern? Alternatively, could unbounded heap growth be a problem for a superuser? I guess the scalars themselves aren't capped for length... On Wed, Mar 20, 2024 at 12:19=E2=80=AFAM Andrew Dunstan wrote: > On second thoughts, I think it might be better if we invent a new error r= eturn code for a lexer mode mismatch. +1 --Jacob