Skip to content

Check return value of yaml_*_event_initialize in the emitter - #823

Open
kou wants to merge 1 commit into
ruby:masterfrom
kou:emitter-check-event-initialize
Open

kou wants to merge 1 commit into
ruby:masterfrom
kou:emitter-check-event-initialize

Conversation

@kou

@kou kou commented Sep 21, 2026

Copy link
Copy Markdown
Member

libyaml's yaml_*_event_initialize() functions reject an anchor, tag, or value that is not valid UTF-8 (and can fail on allocation errors), returning 0 and leaving the passed yaml_event_t untouched.

The emitter ignored that return value and emitted the event anyway. It may cause unexpected behavior. For example, yaml_emitter_emit() may touch an invalid address or double free an invalid event.

We can avoid it by checking every yaml_*_event_initialize() call and raise instead of emitting a stale or uninitialized event.

libyaml's `yaml_*_event_initialize()` functions reject an anchor, tag,
or value that is not valid UTF-8 (and can fail on allocation errors),
returning 0 and leaving the passed `yaml_event_t` untouched.

The emitter ignored that return value and emitted the event anyway. It
may cause unexpected behavior. For example, `yaml_emitter_emit()` may
touch an invalid address or double free an invalid event.

We can avoid it by checking every `yaml_*_event_initialize()` call and
raise instead of emitting a stale or uninitialized event.
@kou
kou force-pushed the emitter-check-event-initialize branch from 4bda41c to 769ddd9 Compare September 21, 2026 14:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant