Skip to content
This repository was archived by the owner on Dec 1, 2023. It is now read-only.
This repository was archived by the owner on Dec 1, 2023. It is now read-only.

Having the length of a "seq" or "map" be tied to the allocated capacity is dangerous. #115

Closed
@TyOverby

Description

@TyOverby

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 Decoders 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions