WebSocket close reasons can be truncated inside a UTF-8 character

Đang mở Phù hợp với người mới
#125 0 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ó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
networking

Hướng nghiên cứu

Đọc WebSocket.close() và _fail(), nơi issue báo cáo cùng một hành vi cắt lát byte. Chạy các bài kiểm thử WebSocket hiện có và bổ sung kiểm thử cho các lý do đa byte ở giới hạn 123 byte, bao gồm các ví dụ được cung cấp và các trường hợp đối chứng cần chạy thành công. Hoàn thành khi việc cắt ngắn giữ đúng giới hạn byte mà không chia tách một ký tự UTF-8 trong cả hai luồng đóng.

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

Mô tả

On main 851b0080cacb03ec38da828160681c64f8d0b29c, WebSocket.close() constructs the close frame with reason.encode("utf-8")[:123]. This keeps the control frame within the byte limit but can split a multibyte character, producing an invalid UTF-8 close reason.

For example, await socket.close(1000, "é" * 62) sends a 123-byte reason ending in the first byte of the final character. A local server that unmasks the close frame and decodes payload[2:] gets UnicodeDecodeError at byte 122. "😀" * 31 and "a" * 122 + "é" also reproduce it. ASCII reasons and multibyte reasons ending on a complete-character boundary are controls that pass.

RFC 6455 section 5.5.1 specifies UTF-8 data after the close code, and section 8.1 requires a peer to fail the connection for invalid UTF-8. Thus a normal application close can become a protocol failure. The same byte slicing appears in _fail().

Validation used Python 3.13.17 on Linux and a local asyncio TCP server, with no external service. The existing 19 WebSocket tests pass when run in isolation. Eight additional close-reason cases against unchanged source produce three failures and five passing controls. These are isolated networking tests, not the repository's complete checks, installed-package test-plugin validation, or mobile tests. The active feat/runtime branch has the same WebSocket source.

Would a fix that preserves the existing truncation behavior but cuts only at complete UTF-8 boundaries be welcome? If so, could you assign this to me before I prepare a PR, following the contribution guide?

This was found during source review and reproduced with constructed examples, not a production incident. AI assistance was used for investigation and local reproduction. No production-source changes have been made.

Ngôn ngữ chính
Python
Star
131
Fork
22
Merge trung bình
3 ngày 2 giờ
Pull request đã merge (30 ngày)
5

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

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 pythonnative/pythonnative

Tất cả issue của pythonnative/pythonnative

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.