mneumann / rust-msgpack

[DEPRECATED] msgpack.org implementation for Rust language. Please use https://github.com/3Hren/msgpack-rust
121 stars 31 forks source link

Nullary option variants corrupt the next element in the decoder. #41

Closed drbawb closed 9 years ago

drbawb commented 9 years ago

If an Option<T> is enclosed inside some other type (struct, enum, map, tuple, etc.) and the None variant is present: the element following the decoded None will be read as a nil since the nil-byte is still in the stream.

This is because read_option uses _peek_byte() to determine if a nil value is in the stream but it does not consume that byte if a None was present. Thus when the next token is read from the stream it will be read as a nil.

This can be fixed by simply consuming the nil if we successfully read a None variant. I added a test and fix on my fork: feature/fix-option-nullary however it will be blocked on PR #39 being merged.

mneumann commented 9 years ago

Please submit a pull request and I'll merge!

drbawb commented 9 years ago

(Fixed in PR #43 )