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

Joni spins forever on invalid input #7

Closed
electrum opened this issue May 31, 2013 · 2 comments
Closed

Joni spins forever on invalid input #7

electrum opened this issue May 31, 2013 · 2 comments
Milestone

Comments

@electrum
Copy link

If you create a Matcher from a byte array containing invalid UTF-8, the match() method will spin forever due to invalid characters not being handled by ByteCodeMachine. For example, in the method opAnyCharStar():

    while (s < range) {
        ...
        int n = enc.length(bytes, s, end);
        if (s + n > range) {opFail(); return;}
        ...
    }

The enc.length() call returns -1 for malformed input, but this value isn't checked for, so the loop never exits. I haven't looked at this deeply enough to know the correct solution, but there are a ton of calls and none of them are checked.

@headius
Copy link
Member

headius commented Jun 1, 2013

I wouldn't say this is by design, but Joni does assume you're passing it valid character sequences. Adding character verification everywhere it is needed would obviously add overhead to the character-walking logic in Joni, slowing down all matches.

However, in the case you show, adding a -1 check would not be a significant source of overhead...so it may be worth adding.

@headius
Copy link
Member

headius commented Oct 31, 2013

FWIW, recent releases of joni will check Thread interrupt status, so it may be possible to break out of a bad match like this.

I'm going to mark this won't fix until there's a general solution.

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