Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-18997

Server does not validate boolean values in BSON

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 3.1.7
    • Affects Version/s: 3.0.3
    • Component/s: Internal Code
    • None
    • Minor Change
    • Platform 6 07/17/15, Platform 7 08/10/15
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      The BSON specification mandates that a field of type boolean is a byte with either the value \x00 or \x01. The server does not check this as part of the BSON validation process. If a poorly written driver incorrectly used a different value to represent true or false, undefined behavior will result. For example, if I insert hand-crafted BSON where the value of a field "b" is of type boolean and the byte value is \x02:

      > db.test.find()
      { "_id" : ObjectId("55806db733ee03327f4907ea"), "b" : true }
      > db.test.count({b : true})
      0
      > db.test.count({b : false})
      0
      

      Furthermore, BSON decoders in different languages are written differently. Some convert the byte to a boolean with a check like "b != \x00", while others do "b == \x01", so the former would decode this field as true, while the latter will decode it as false.

            Assignee:
            andrew.morrow@mongodb.com Andrew Morrow (Inactive)
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: