Skip to content

fix(changelog): Avoid a regex StackOverflow#88

Merged
jmongard merged 1 commit into
jmongard:masterfrom
sschuberth:regex-stackoverflow-fix
Jun 11, 2026
Merged

fix(changelog): Avoid a regex StackOverflow#88
jmongard merged 1 commit into
jmongard:masterfrom
sschuberth:regex-stackoverflow-fix

Conversation

@sschuberth

Copy link
Copy Markdown
Contributor

Complex real-life commit messages could cause a StackOverflow for regex matching. While the exact cause has not been investigated, the issue disappears when changing the regex to not match the full commmit message (including the body), but only the title line. This should be sufficient as all users of CommitInfo.message only get the first line by calling lineSequence().first() anyway.

Complex real-life commit messages could cause a StackOverflow for regex
matching. While the exact cause has not been investigated, the issue
disappears when changing the regex to not match the full commmit message
(including the body), but only the title line. This should be sufficient
as all users of `CommitInfo.message` only get the first line by calling
`lineSequence().first()` anyway.
@sschuberth

Copy link
Copy Markdown
Contributor Author

@jmongard, what do you think about also renaming CommitInfo.message to CommitInfo.title? Was that field ever supposed to contain the full message?

@jmongard jmongard merged commit 0039917 into jmongard:master Jun 11, 2026
1 check passed
@jmongard

Copy link
Copy Markdown
Owner

It could be renamed. I had no special thought about it other than it containing the commit message.
I'm not sure if there is a case where you would like to have the commit body as an expander in the release notes. Probably not.

@sschuberth

Copy link
Copy Markdown
Contributor Author

I'm not sure if there is a case where you would like to have the commit body as an expander in the release notes. Probably not.

And even if so, the whole commit message (title and body) would still be available as CommitInfo.text, I believe.

@sschuberth sschuberth deleted the regex-stackoverflow-fix branch June 11, 2026 15:32
@sschuberth

Copy link
Copy Markdown
Contributor Author

It could be renamed.

See #89.

@sschuberth

Copy link
Copy Markdown
Contributor Author

While the exact cause has not been investigated

For the record, here's an AI-generated explanation of the root cause:

The StackOverflowError happens because of catastrophic backtracking combined with how Java's default regex engine (java.util.regex) is implemented.

Java uses a Nondeterministic Finite Automaton (NFA) execution engine, which relies on recursive method calls on the call stack to explore matching pathways and handle backtracking.

Here is the exact culprit in your expression:
(?<Message>(?:.|\n)*)

Why it Fails on Your Text

  1. The Alternation Inside the Quantifier: The group (?:.|\n)* tells the engine: "Match either a character OR a newline, and do this over and over." 2. The Branching Stack: Every single time the engine processes a character, it has to choose between . and \n. To remember these choices (in case it needs to backtrack later), Java pushes a stack frame for every single iteration.
  2. Deep Recursion: Because your input text is a very long commit message (hundreds of characters), the engine nesting depth exceeds the JVM's thread stack size limit, crashing with a StackOverflowError.

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