Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2116

Verify BSON passed to libmongocrypt contains complete documents

    XMLWordPrintable

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 2.12.0.rc0
    • Component/s: None
    • Labels:
      None

      Description

      In Ruby we have the #to_bson method on various classes that implements serialization to bson. Depending on what type of object it's called on, it produces either complete legal bson documents or document fragments.

      libmongocrypt as I understand it requires complete legal bson documents as input. Therefore code like the following is problematic:

              data = command.to_bson.to_s
              Binary.wrap_string(data) do |data_p|
                check_ctx_status(context) do
                  mongocrypt_ctx_encrypt_init(context.ctx_p, db_name, an_int, data_p)
                end
              end
      

      If command is nil (or of a wrong type like Integer), it's still possible to call to_bson on it which produces a partial bson fragment, which eventually produces a not very descriptive error in libmongocrypt per https://jira.mongodb.org/browse/MONGOCRYPT-246.

      To improve diagnostics in Ruby driver we should take steps to ensure that the data we give to libmongocrypt is complete bson documents. I believe checking that the type of objects that #to_bson is called on, and requiring that those are Hash instances, would be sufficient to start.

        Attachments

          Activity

            People

            Assignee:
            emily.giurleo Emily Giurleo
            Reporter:
            oleg.pudeyev Oleg Pudeyev
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: