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

An issue about parsing URL with regular expression #1238

Closed
Jinyn01 opened this issue Oct 23, 2023 · 7 comments
Closed

An issue about parsing URL with regular expression #1238

Jinyn01 opened this issue Oct 23, 2023 · 7 comments

Comments

@Jinyn01
Copy link

Jinyn01 commented Oct 23, 2023

Description:

When I parse URLs with a complex regular expression, the result of XS is Killed, which looks like an issue.

Environment

Ubuntu 18.04 x86_64

JS Information:

Moddable SDK 3.7.0

Testcase:

const regex = /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/
const str = 'https://www.example.com/path/to/resource?param1=value1&param2=value2#section';

const result = regex.exec(regex);

Result:

Killed
@phoddie
Copy link
Collaborator

phoddie commented Oct 23, 2023

Thank you for the report. The problem reproduces here on macOS as well. It looks like the process is killed because it eventually allocates too much memory.

Note that the title of this issue is incorrect. The test case does not parse a URL. The URL is in the variable str but that is unused when calling exec. Is this a test case from a fuzzing run?

Note also that this issue is reported against Moddable SDK 3.7.0. The current release is 4.2.1.

FWIW - JavaScriptCore and V8 evaluate the regex quickly and without an error.

We will investigate.

@Jinyn01
Copy link
Author

Jinyn01 commented Oct 24, 2023

Thank you very much for your reply. I'm sorry for my carelessness, I made a mistake while locating the problem. Actually, this piece of code was originally designed for URL parsing, but I mistakenly wrote the function parameter str as regex. The correct code should be const result = regex.exec(str). I apologize for any inconvenience caused.

@phoddie
Copy link
Collaborator

phoddie commented Oct 24, 2023

Thank you for the clarification. The problem happens using either str or regex as the argument. We are testing a fix now. That should be available later in the week.

mkellner pushed a commit that referenced this issue Oct 24, 2023
@phoddie
Copy link
Collaborator

phoddie commented Oct 24, 2023

The fix for this is live now. Please give it a try.

@phoddie
Copy link
Collaborator

phoddie commented Oct 24, 2023

Just FWIW -- the Moddable SDK includes an implementation of the web's URL class. That might be a little more straightforward than a regular expression. But, do whatever works best for you.

@Jinyn01
Copy link
Author

Jinyn01 commented Oct 25, 2023

I have tried the solution you provided and the problem has been successfully resolved. Thank you very much.

@Jinyn01 Jinyn01 closed this as completed Oct 25, 2023
@phoddie
Copy link
Collaborator

phoddie commented Oct 25, 2023

Excellent. Thanks again for reporting the issue. We're always glad to fix issues like this.

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

No branches or pull requests

2 participants