Skip to content

Conversation

@carenas
Copy link
Contributor

@carenas carenas commented Aug 15, 2025

Mainly as a way to clean the code and make it more resilient.

It changes the behavior of the pattern /\[]{-1}/expand which will now be treated as a literal instead of triggering a bogus syntax error and clarifies that no pattern or buffer could be larger than SIZE_MAX bytes.

Improves error checking for 32-bit platforms and even 64-bit ones that are not LP64.

@carenas carenas changed the title pcre2text: improve expand and its use of buffers pcre2test: improve expand and its use of buffers Aug 15, 2025
src/pcre2test.c Outdated
size_t pp_offset = pp - buffer;
size_t pt_offset = pt - pbuffer8;
expand_input_buffers();
expand_input_buffers(m);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This thing with m can't be correct, can it? It looks like m is being set to the size of the current expansion, not the size of what's in the buffer plus the new content.

What happens for this: /[a]{1000}[b]{1000}/expand

Allow for a nicer fallback in case of syntax errors in the
pattern implementation while avoiding negative values
masquerading as positive ones. While at it, make sure that in non
LP64 environments UINT32_MAX is still considered valid.

Update the data implementation to behave similarly and cleanup
fixes that had accumlated unorganically.
@carenas carenas marked this pull request as draft August 29, 2025 11:44
}
else if (allowed_size != buffer_size)
{
void *q = realloc(buffer, buffer_size);

Check warning

Code scanning / clang

Potential leak of memory pointed to by 'p' Warning

Potential leak of memory pointed to by 'p'
Use realloc() for exponential resize of all buffers, which has the
advantage of potentially not needing to copy.

Add a parameter to `expand_input_buffers()` to indicate the minimum
size required and allow a smarter fallback when the buffer can't
be doubled.
@NWilson
Copy link
Member

NWilson commented Sep 26, 2025

I apologize, I think I have created a ton of conflicts in this branch after my splitting of pcre2test.c.

I will rebase your changes if you would like, just ask.

@NWilson NWilson changed the base branch from master to main November 5, 2025 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants