Psych.dump_stream raises NoMethodError when the stream has no documents
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
まず tree_builder.rb の Psych::TreeBuilder#end_stream と #set_end_location から始め、次に YAMLTree#finish がドキュメントのないストリームをどのように処理するかを追ってください。ドキュメント数がゼロの Psych.dump_stream に対するリグレッションテストを追加し、空文字列が返され、それを safe_load_stream が [] として読み込むことを確認してください。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- Ruby
- スター
- 596
- フォーク
- 228
- 平均マージ
- 24分
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
ruby/psych のほかの issue
-
Sexagesimal scalars are mis-scanned対応中かも @ihamzatarar が 13 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
Documentation
難易度 1/5 1時間未満 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
Psych.dump raises Encoding::CompatibilityError for UTF-16/UTF-32 strings対応中かも @Halvanhelv が 83 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
-
Psych::Emitter#start_document: tag-directive handles and prefixes are aliased as raw `char *`, and the Strings die inside the loop対応中かも @ninjapanzer が 14 日前に担当しました。 オープン
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
Mend: dependency security vulnerability
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
valkey-io/valkey-glide-ruby#461 ·
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
openstreetmap/openstreetmap-website#7662 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 2 日以内に返信
-
1.severity: security
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信