xml.sax: the content of an external entity is not checked to be well-formed
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 35.9k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
Bug report
The parsing of an external entity is never finalized, so errors which are only detected at the end of the input are not reported. An external entity whose content is not well-formed is silently accepted.
import io, xml.sax
from xml.sax.handler import feature_external_ges
from xml.sax.xmlreader import InputSource
class Resolver:
def resolveEntity(self, pubid, sysid):
source = InputSource()
source.setByteStream(io.BytesIO(b'<entity>')) # no end tag
return source
parser = xml.sax.make_parser()
parser.setFeature(feature_external_ges, True)
parser.setEntityResolver(Resolver())
parser.feed('<!DOCTYPE d [<!ENTITY e SYSTEM "x">]><d>&e;</d>')
parser.close() # no error
ExpatParser.close() returns early when _entity_stack is not empty, so feed(b"", isFinal=True) is never called for the parser created for the entity. The check is needed to not end the document while the entity is being parsed, but it also skips finalizing the entity itself.
If the parser of the entity is finalized, the example above fails with "error in processing external entity reference", and test_sax still passes.
Errors which Expat detects while feeding data, like a mismatched tag, are reported even now. Only errors detected at the end of the input, like an unclosed element, are lost.
Linked PRs
- gh-156828
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu từ ExpatParser.close() và đường đi của parser thực thể bên ngoài được mô tả trong báo cáo; sử dụng trình tái hiện được cung cấp để xác nhận việc thiếu bước hoàn tất. Chạy test_sax và xác minh rằng các thực thể bên ngoài không đúng định dạng sẽ phát sinh lỗi đã nêu, trong khi các bài kiểm thử hiện có vẫn vượt qua.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức phù hợp với người mới
- 25/100