Subject: Re: bug#47264: [PATCH v2] pcre: migrate to pcre2

From: Carlo Marcelo Arenas Belón <[email-masked]>
Date: Mon, 15 Nov 2021 12:49:17 -0800

On Mon, Nov 15, 2021 at 08:17:02AM -0800, Paul Eggert wrote:
> On 11/14/21 20:44, Carlo Arenas wrote:
> 
> > > This shouldn't be a problem in practice. Surely PCRE2_SIZE_MAX is for
> > > forward compatibility to a potential future version of PCRE2 that may
> > > define PCRE2_SIZE to be some other type. For PCRE2 10.20 and earlier
> > > PCRE2_SIZE is hardwired to size_t, so there is only one plausible
> > > default for PCRE2_SIZE_MAX, namely SIZE_MAX.
> > 
> > which is why I mention that it will be better to at least document
> > that in a comment, as it was done everywhere else where assumptions
> > made in the pcre library were used.
> 
> What sort of documentation did you have in mind, exactly?

Apologies, I realize it is difficult to talk about code in abstract when
not inlined, but I think it will better addressed by "fixing" it as shown
in the attached patch.

> > Interestingly enough this discussion gave me an idea for a feature in
> > PCRE where that value will be set to something else than SIZE_MAX and
> > that might break grep in a future release if it lands.
> 
> How would it break grep? I'm not following. If a future version of PCRE
> defines PCRE_SIZE_MAX to something other than SIZE_MAX, grep should work
> just fine because it will use what PCRE defines.

only if we always use PCRE2_SIZE_MAX

Carlo
>From fc459a80d20d437ce244753434371d02cf016a62 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Carlo=20Marcelo=20Arenas=20Bel=C3=B3n?= <[email-masked]>
Date: Mon, 15 Nov 2021 12:36:17 -0800
Subject: [PATCH] pcre: avoid using SIZE_MAX
MIME-Version: 1.0
Content-Type: text/x-patch; charset=UTF-8
Content-Transfer-Encoding: 8bit

Not a problem in practice, as all versions of PCRE2 that define
PCRE2_SIZE_MAX do it as SIZE_MAX, but lets avoid any surprises
by using the same value we are using everywhere else in case it
ever changes.

Signed-off-by: Carlo Marcelo Arenas Belón <[email-masked]>
---
 src/pcresearch.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/pcresearch.c b/src/pcresearch.c
index c12c674..dcf146a 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -82,7 +82,8 @@ jit_exec (struct pcre_comp *pc, char const *subject, idx_t search_bytes,
          Going over the jitstack_max limit could trigger an int
          overflow bug.  */
       int STACK_GROWTH_RATE = 8192;
-      idx_t jitstack_max = MIN (IDX_MAX, SIZE_MAX - (STACK_GROWTH_RATE - 1));
+      idx_t jitstack_max = MIN (IDX_MAX,
+                                PCRE2_SIZE_MAX - (STACK_GROWTH_RATE - 1));
 
       int e = pcre2_match (pc->cre, (PCRE2_SPTR) subject, search_bytes,
                            search_offset, options, pc->data, pc->mcontext);
-- 
2.34.0.352.g07dee3c5e1