Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug assertions to ensure we never write too much to parsed_pattern #568

Merged

Conversation

NWilson
Copy link
Member

@NWilson NWilson commented Nov 18, 2024

A follow-up to #561.

The bug was found by fuzzing - but it would have been a serious problem if we'd made a release with this bug in.

I have added deterministic assertions, so that we don't rely on fuzzing, in case we make the same (easy) mistake again in future.

It's a little bit cumbersome, since there are two cases when we do write out more items to parsed_pattern than we consume from the input: ")" after (*atomic_script_run:... will write out two META_KETs when it consumes the ")", and secondly a quantifier after (*ACCEPT) can write out a META_NOCAPTURE/META_KET pair.

The code here is rather inelegant, but it's the best I could manage.

Copy link
Collaborator

@zherczeg zherczeg left a comment

Choose a reason for hiding this comment

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

LGTM


Returns: the number of uint32_t units for parsed_pattern
*/
static ptrdiff_t
Copy link
Collaborator

Choose a reason for hiding this comment

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

size_t ? Or PCRE2_SIZE?

Copy link
Member Author

Choose a reason for hiding this comment

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

This was intentional. There is some arithmetic in the PCRE2_ASSERT lines, and some of the expressions are negative, so it made sense to make all the expressions signed rather than unsigned. Otherwise there would be ugly casts.

@PhilipHazel PhilipHazel merged commit db95416 into PCRE2Project:master Nov 18, 2024
18 checks passed
@NWilson NWilson deleted the user/niwilson/parsed_pattern_assert branch December 17, 2024 09:48
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.

3 participants