Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

Catastrophic Backtracking while using `Binds`

Đang mở
#411 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
cli, devtools

Hướng nghiên cứu

Bắt đầu với MOUNT_WIN_REGEX trong iotedgehubdev/compose_parser.py và MOUNT_MODE_REGEX trong iotedgehubdev/constants.py, sau đó tái hiện thời gian thực thi đã được báo cáo bằng các Windows bind mount có độ sâu tăng dần. Theo dõi cách createOptions áp dụng các mẫu và xác minh rằng các đường dẫn hợp lệ có chữ cái viết hoa không còn có thời gian matching tăng theo hàm mũ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Trying to use Binds in createOptions (binding Windows directory to Linux container) seems to raise catastrophic backtracking. The pattern responsible is MOUNT_WIN_REGEX
https://github.com/Azure/iotedgehubdev/blob/7eede7286a0603e565c8b183d090f2585521aae6/iotedgehubdev/compose_parser.py#L190

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:
https://github.com/Azure/iotedgehubdev/blob/7eede7286a0603e565c8b183d090f2585521aae6/iotedgehubdev/constants.py#L48

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
Ngôn ngữ chính
Python
Star
91
Fork
38
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

  • Không có Dockerfile hay tệp Docker Compose
  • Không có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Azure/iotedgehubdev

Tất cả issue của Azure/iotedgehubdev

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.