Documenting BSON Errata

Skip to first unread message

Feb 2, 2016, 6:08:01 PM2/2/16

I'm documenting quirks & undefined behavior in BSON (negative size parameters, malformed arrays, etc) for my own purposes implementing the standard. I haven't found much documentation of this subject. Are there any articles, posts on this forum, etc that you all are aware of that I could read and cite? Would people like me to post it when I'm done?


D Merriman

Feb 19, 2016, 4:44:14 PM2/19/16
not really afaik -- if something is obviously not allowed (negative size) it would be undefined the behavior of course.

in mongodb if you tried to insert such a document, it should give you an error back, but the BSON spec is just what is legal not what any behavior if malformed should be.

Mar 3, 2016, 4:14:30 PM3/3/16
Thank you for your response.

My reading of the spec is that negative sizes are allowed (why else would it explicitly call for signed size parameters?), and that this is handled in an implementation-defined manner, but perhaps I'm being overly literal. :)

Dwight Merriman

Mar 3, 2016, 5:41:28 PM3/3/16
i didn't reread everything but the string field it says 

String - The int32 is the number bytes in the (byte*) + 1 (for the trailing '\x00'). The (byte*) is zero or more UTF-8 encoded characters.

since it explicitly says the string is nonnegative length the size must be too. :-)

it could be less cryptic, and there is also the minor question of why is it wasting a bit thats always zero.

i hope for some of this to be cleaned up in a future revision of the spec (which would have a new version number even if changes are minimal).  there has been an attempt to not modify the existing document much as in theory a specification for a certain spec version should never change.

You received this message because you are subscribed to the Google Groups "BSON" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
For more options, visit

Reply all
Reply to author
0 new messages