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

Catastrophic Backtracking while using Binds #411

Open
aidint opened this issue May 26, 2023 · 1 comment
Open

Catastrophic Backtracking while using Binds #411

aidint opened this issue May 26, 2023 · 1 comment

Comments

@aidint
Copy link

aidint commented May 26, 2023

Trying to use Binds in createOptions (binding Windows directory to Linux container) seems to raise catastrophic backtracking. The pattern responsible is MOUNT_WIN_REGEX

match = regex.match(EdgeConstants.MOUNT_WIN_REGEX, bind) or regex.match(EdgeConstants.MOUNT_LCOW_REGEX, bind)

The following is the result of applying MOUNT_WIN_REGEX on different binds:

C:/:/app/ took 0.009343099998659454
C:/Folder1/:/app/ took 0.00018330000239075162
C:/Folder1/Folder2/:/app/ took 0.003711700002895668
C:/Folder1/Folder2/Folder3/:/app/ took 0.28317089999836753
C:/Folder1/Folder2/Folder3/Folder4/:/app/ took 18.772531900001923

as you can see, runtime grows exponentially. The fifth depth didn't return any result even after 5 minutes. This is the code I ran:

bind = "C:/"
counter = 1

def match(bind):

    return regex.match(MOUNT_WIN_REGEX, bind)

while counter < 10:
    
    result = timeit.timeit(lambda: match(f"{bind}:/app/"), number=1)
    print(f"{bind}:/app/ took {result}")
    bind += f"Folder{counter}/"
    counter += 1

The reason seems to be the inline modifier (?i) in MOUNT_MODE_REGEX:

MOUNT_MODE_REGEX = r'(:(?P<mode>(?i)ro|rw))?'

The modifier somehow is propagated to the whole pattern. Removing the modifier will solve the catastrophic backtracking, but the pattern won't match paths with capital letters. By including the range A-Z in the pattern, the issue of backtracking resurfaces.

Suggestions:

  • split the bind string by :, and apply smaller patterns on split strings instead of applying the huge regex patterns on the whole string
  • instead of applying two huge regex patterns, break them up and use if-elif for pattern matching
@konichi3
Copy link
Collaborator

konichi3 commented Jul 6, 2023

We are aware of the issue here in our backlog, however the simulator is in maintenance mode at this time.

Have you explore running your solution on a real device or using EFLOW instead?

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