Having the length of a "seq" or "map" be tied to the allocated capacity is dangerous. #115
Description
For many decoders, (like JSON), calling read_seq
with the length of items in a Json array or map is fine because the Json array or map is already in memory, so having a Vec or HashMap initialize with_capacity
isn't that bad.
However, in a bug found by @jmesmon, the bincode decoder can be tricked into getting Vec
to preallocate more memory than the system has, causing the program crash. I put in a lot of restrictions in Bincode to prevent DOS attacks, with the goal of being able to use Bincode on a public port for gamedev, but the automatic "capacity is the same as length" would let any attacker take down any program using bincode to decode.
I've implemented a fix here. This would be a breaking change for people that implement their own Decoder
s because the type signature differs, but elements that are Decodable
won't need to change. Furthermore, the #[derive(Decodable)]
plugin shouldn't need to change because it doesn't emit any read_map
or read_seq
calls.