Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-645

lookupInterfaceDecoder does not ensure type is a pointer

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.1.0
    • Affects Version/s: None
    • Component/s: BSON
    • None

      A type that has a property of another struct that proxies a primitive like a string cannot be unmarshaled after being marshaled with the following error: "positioned on string, but attempted to read embedded document".

      Example code:

      type encValueWrapper struct {
          EncValue EncryptedValue
      }
      
      type EncryptedValue struct {
          value    string
          rawValue []byte
      }
      
      func (ev EncryptedValue) DecryptValue(crypter Crypter, out interface{}) error {
          if ev.value != "" {
              return crypter.DecryptValue(ev.value, out)
          }
          return crypter.DecryptParsedValue(ev.rawValue, out)
      }
      
      func (ev EncryptedValue) ProxyBSON() (interface{}, error) {
          if ev.value == "" {
              return nil, ErrNotEncryptedValue
          }
          return ev.value, nil
      }
      
      func (ev *EncryptedValue) UnmarshalBSONValue(t bsontype.Type, data []byte) error {
          temp, err := NewEncryptedValueFromBSON(bson.RawValue{Type: t, Value: data})
          if err != nil {
              return err
          }
          *ev = temp
          return nil
      }
      

            Assignee:
            kris.brandow@mongodb.com Kristofer Brandow (Inactive)
            Reporter:
            eric.daniels@mongodb.com Eric Daniels
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: