chRyNaN / uri

A Kotlin Multiplatform Utility Library for Uniform Resource Identifiers (URIs)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Regex is unreliable on K/N

J-Swift opened this issue · comments

Describe the bug
The Kotlin/Native regex engine has known issues with stack overflowing, and as such is extremely unreliable on iOS in my testing. Here are some youtrack issues about it:

https://youtrack.jetbrains.com/issue/KT-35508/EXCBADACCESScode2-address0x16d8dbff0-crashes-on-iOS-when-using-a-sequence-from-map-etc
https://youtrack.jetbrains.com/issue/KT-39789/Segfault-in-KotlinNative-regex-interpreter
https://youtrack.jetbrains.com/issue/KT-46211/KotlinNative-Stack-overflow-crash-in-Regex-classes-with-simple-pattern-and-very-large-input
https://youtrack.jetbrains.com/issue/KT-53352/Native-iOS-Crash-when-using-regex-newSingleThreadContext

I ran into this in my own code, and was only able to workaround the crash by injecting a native regex implementation (i.e. using NSRegularExpression), but then I crashed when calling into this library since it uses Regex behind the scenes 😄

To Reproduce
Steps to reproduce the behavior:

val testing = "https://static01.nyt.com/images/2017/12/17/business/15NETVOTE2/merlin_131286365_4b8e35f3-0c1e-42e9-be51-a01c779456f7-facebookJumbo.jpg?year=2017&h=550&w=1050&s=a303fe833125a071cc3c33506af0bcb7c2ea7b8550c7a3e086a1421b2f9d7388&k=ZQJBKqZ0VN"

Uri.fromStringOrNull(testing)

Smartphone (please complete the following information):

  • iPhone 14 pro simulator running ios 16.0

Additional context
The youtrack mentions increasing stack size should help, but I was unable to get that to work in my testing. Maybe I wasn't doing it right though.

Really just opening this ticket for broader awareness. I'm not sure the best approach to fixing it other than possibly rewriting using native regex. The jetbrains team does not seem keen to fixing it on their end.

Welcome and thanks for contributing! Make sure to leave a detailed explanation of the issue.