Conversions to bindata do not preserve, set, or check correct subtypes

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Works as Designed
    • Priority: Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • ALL
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • 0

      To reproduce:

      MongoDB Enterprise > db.c.insert({_id: 0, bson: 100});
      WriteResult({ "nInserted" : 1 })
      MongoDB Enterprise > db.c.aggregate([{
               $project: {
                   _id: 0,
                   output: {
                       $convert:
                           {to: {type: "binData", subtype: 2}, input: "$bson", format: "base64"}
                   }
               }     
      }]);
      { "output" : BinData(2,"AAAAAAAAWUA=") }
      MongoDB Enterprise >
      

      A BinData subtype of 2 represents a String.  But that's incorrect for this bindata.

       

      We should be checking the `subtype` field in all conversions to BinData such that they match the intended type.

      For example, this function for numbers just blindly passes the subtype to the returned BinData: https://github.com/10gen/mongo/blob/master/src/mongo/db/exec/expression/evaluate_math.cpp#L1481

       

      We should audit all conversions functions to bindata and verify that they check BinData subtypes correctly.

            Assignee:
            Ivan Fefer
            Reporter:
            Finley Lau
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: