hadashiA / VYaml

The extra fast, low memory footprint YAML library for C#, focued on .NET and Unity.
MIT License
305 stars 18 forks source link

Possible `IndexOutOfRangeException` in `Utf8YamlTokenizer.TryPeek` when using `DeserializeMultipleDocumentsAsync` #31

Closed UlyssesWu closed 1 year ago

UlyssesWu commented 1 year ago

https://github.com/hadashiA/VYaml/blob/7f1c814f16ea11699843a69d9db11e0319299f31/VYaml.Core/Parser/Utf8YamlTokenizer.cs#L1596

I got an IndexOutOfRangeException when reader.CurrentSpan.Length = 65536, reader.CurrentSpanIndex = 65535, offset = 1. remainingOffset = -1 causes the exception.

You can test with this yaml: ROP.yaml.txt

using var fs = new FileStream(path, new FileStreamOptions(){Access = FileAccess.Read, Options = FileOptions.Asynchronous});
var root = await YamlSerializer.DeserializeMultipleDocumentsAsync<dynamic>(fs);

This is related to DeserializeMultipleDocumentsAsync and maybe StreamHelper codes. If I use DeserializeMultipleDocuments, there is no error.