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

fix: regex max stack depth crash #2789

Merged
merged 2 commits into from
Nov 18, 2024
Merged

Conversation

isekovanic
Copy link
Contributor

@isekovanic isekovanic commented Nov 18, 2024

🎯 Goal

Fixes the occasional regex maximum depth reached error.

Not going to go into the specifics on why this happens as they're complicated, but I will add a few bullet points:

  • Tried porting the latest version of simple-markdown available here, but nothing changed with that and the issue is still noticeable
  • The issue typically happens whenever we have one (or more) \n characters, followed by many white spaces; the regex state machine runs something similar to /\s+/g at one point, which considers both. However, despite treating them both as the same character under \s, it actually does a ridiculous amount of backtracking and combinations while all that's going on, even due to a single \n character as it tries to look for every possible scenario.
  • Ironically, simply a long sequence of whitespaces finishes in a single go since it manages to match everything in O(n).

Note: We should really look into upgrading our markdown package in general. I was successful in doing so, but decided to separate this fix and the migration since deeper testing would be required.

🛠 Implementation details

🎨 UI Changes

iOS
Before After
Android
Before After

🧪 Testing

☑️ Checklist

  • I have signed the Stream CLA (required)
  • PR targets the develop branch
  • Documentation is updated
  • New code is tested in main example apps, including all possible scenarios
    • SampleApp iOS and Android
    • Expo iOS and Android

@Stream-SDK-Bot
Copy link
Contributor

Stream-SDK-Bot commented Nov 18, 2024

SDK Size

title develop branch diff status
js_bundle_size 452 KB 455 KB +2624 B 🔴

@isekovanic isekovanic merged commit 32115ca into v6.0.0 Nov 18, 2024
5 of 7 checks passed
@isekovanic isekovanic deleted the fix/regex-max-stack-depth-crash branch November 18, 2024 15:53
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