Skip to content

Fix infinite loop in replaceStringInfoString#1750

Open
Smyatkin-Maxim wants to merge 1 commit into
mainfrom
string_replace_fix
Open

Fix infinite loop in replaceStringInfoString#1750
Smyatkin-Maxim wants to merge 1 commit into
mainfrom
string_replace_fix

Conversation

@Smyatkin-Maxim
Copy link
Copy Markdown
Contributor

@Smyatkin-Maxim Smyatkin-Maxim commented May 16, 2026

The function had a few problems:

  • replace ="a" and replacement="ab" would give an infinite loop leading to OOM. We have a similar case in pg_dump: replace="range", replacement="multirange"
  • Copying the whole string each time there is a match
  • Empty replace pattern also leads to infinite loop

We can still do better: for example count number of matches and do a single allocation, or even run the replacement inplace. But it's probably not worth it.

What does this PR do?

Type of Change

  • Bug fix (non-breaking change)
  • New feature (non-breaking change)
  • Breaking change (fix or feature with breaking changes)
  • Documentation update

Breaking Changes

Test Plan

  • Unit tests added/updated
  • Integration tests added/updated
  • Passed make installcheck
  • Passed make -C src/test installcheck-cbdb-parallel
  • gpupgrade of regression database

Impact

Performance:

User-facing changes:

Dependencies:

Checklist

Additional Context

CI Skip Instructions


The function had a few problems:
- replace ="a" and replacement="ab" would give an infinite loop leading
  to OOM. We have a similar case in pg_dump: replace="range",
  replacement="multirange"
- Copying the whole string each time there is a match
- Empty replace pattern also leads to infinite loop

We can still do better: for example count number of matches and do a
single allocation, or even run the replacement inplace. But it's
probably not worth it.
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.

1 participant