bson before 0.8 incorrectly uses int rather than size_t for many variables, parameters, and return values. In particular, the bson_ensure_space() parameter bytesNeeded could have an integer overflow via properly constructed bson input.
https://usn.ubuntu.com/4450-1/
https://launchpadlibrarian.net/474887364/bson-fix-overflow.patch
https://bugs.launchpad.net/ubuntu/+source/whoopsie/+bug/1872560