Psych.dump_stream raises NoMethodError when the stream has no documents
Maintainer thường phản hồi trong vòng 1 ngày
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
- 83/100
Hướng nghiên cứu
Bắt đầu với Psych::TreeBuilder#end_stream và #set_end_location trong tree_builder.rb, sau đó lần theo cách YAMLTree#finish xử lý một luồng không có tài liệu. Thêm kiểm thử hồi quy cho Psych.dump_stream với không tài liệu nào và xác minh rằng nó trả về chuỗi rỗng mà safe_load_stream đọc thành [].
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Version: Psych 5.3.1 (Ruby 4.0.10, libyaml 0.2.5). The dump-side crash
also reproduces on Psych 5.2.2 (Ruby 3.4.13).
Reproduction (complete; no input files needed):
require "psych"
Psych.dump_stream
# => NoMethodError: undefined method 'end_line=' for nil
The round-trip form of the same failure:
Psych.safe_load_stream("") # => []
Psych.dump_stream(*Psych.safe_load_stream(""))
# => NoMethodError: undefined method 'end_line=' for nil
Any input that loads to zero documents triggers it, e.g. a comment-only
stream ("# Comment only.\n").
Expected: dumping an empty stream succeeds — for example, it returns
"", which safe_load_stream reads back as [].
Actual: NoMethodError raised from Psych::TreeBuilder#set_end_location
(tree_builder.rb:133), called from TreeBuilder#end_stream via
Psych::Visitors::YAMLTree#finish. With no document ever added, the node
whose end location is being set is nil.
Relation to #685: the same error message appears in #685, but that
report traces it to a syntax error in user code on the parse side. This
report is the dump side: nothing is parsed, no malformed input is involved,
and Psych.dump_stream with zero documents crashes deterministically.
Proposed fix: guard the nil node in TreeBuilder#end_stream /
#set_end_location so a stream with no documents finishes normally and the
emitter produces an empty string. If that direction looks right, may I send
a pull request with tests?
Disclosure: this was found with a load/dump round-trip (self-consistency)
check run with AI assistance. The reproduction above is minimal and was
verified by hand on the versions listed.
- Ngôn ngữ chính
- Ruby
- Star
- 596
- Fork
- 228
- Merge trung bình
- 24 phút
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc 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.
Issue khác của ruby/psych
-
Sexagesimal scalars are mis-scannedCó thể đã có người làm @ihamzatarar đã nhận 13 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
ruby/psych#814 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 stringsCó thể đã có người làm @Halvanhelv đã nhận 83 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 55/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Psych::Emitter#start_document: tag-directive handles and prefixes are aliased as raw `char *`, and the Strings die inside the loopCó thể đã có người làm @ninjapanzer đã nhận 14 ngày trước. Đang mở
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
ruby/psych#812 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 52/100
ruby/psych#811 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Mend: dependency security vulnerability
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
valkey-io/valkey-glide-ruby#461 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 69/100
openstreetmap/openstreetmap-website#7662 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 95/100
Maintainer thường phản hồi trong vòng 2 ngày
-
1.severity: security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày