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

Verify BSON passed to libmongocrypt contains complete documents

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.12.0.rc0
    • Affects Version/s: None
    • Component/s: None
    • None

      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.

            Assignee:
            emily.giurleo@mongodb.com Emily Giurleo (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: