Skip to content

fix: enhance Skip() method to prevent infinite loops during deserialization of nested mappings#6

Merged
glucaci merged 1 commit into
mainfrom
fix-oom
Jan 5, 2026
Merged

fix: enhance Skip() method to prevent infinite loops during deserialization of nested mappings#6
glucaci merged 1 commit into
mainfrom
fix-oom

Conversation

@glucaci
Copy link
Copy Markdown
Member

@glucaci glucaci commented Jan 5, 2026

This pull request addresses a critical bug in the YAML deserialization logic that could cause infinite loops or out-of-memory errors when skipping unknown properties, especially those containing nested mappings or sibling discriminators with unknown values. The fix ensures that the reader correctly advances past skipped content, and comprehensive tests are added to verify correct behavior in these scenarios.

Key changes:

Bug Fixes & Reader Logic

  • Updated the Skip() method in Utf8YamlReader to always advance the reader past the end of skipped nested mappings and end markers, preventing infinite loops when unknown or unexpected tokens are encountered. This also includes clarifying documentation for Skip(). [1] [2]

Source Generator Updates

  • Changed the code generation pattern for sibling discriminator handling (in both property and dictionary reading) from a C# switch expression to a switch statement. This allows for explicit skipping of unknown discriminator values and ensures the reader advances correctly, assigning null when needed. [1] [2]

Test Coverage

  • Added a comprehensive suite of regression tests to cover scenarios with unknown properties (including deeply nested mappings), sibling discriminators with unknown values, and lists with mixed known/unknown discriminator values. These tests verify that deserialization does not hang and that subsequent properties are parsed correctly.

  • Registered new types in the test serialization context to support the new tests for nested mappings and sibling discriminators.

@glucaci glucaci merged commit 9c13310 into main Jan 5, 2026
1 check passed
@glucaci glucaci deleted the fix-oom branch January 5, 2026 20:48
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