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

UnmarshalExtJSON panics with invalid json

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 0.2.0
    • Affects Version/s: 0.1.0
    • Component/s: JSON & ExtJSON
    • None

       

      UnmarshalExtJSON panics when provided invalid JSON instead of returning an error.

       

       

       

      Example code:

       

      bson.UnmarshalExtJSON([]byte(`notjson`), false, &bson.M{})
      

       

       

      Result:

       

      panic: runtime error: invalid memory address or nil pointer dereference
      [signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x111be31]goroutine 1 [running]:
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsonrw.(*extJSONValueReader).Type(0x0, 0x18)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsonrw/extjson_reader.go:225 +0x11
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec.DefaultValueDecoders.MapDecodeValue(0xc4200c4070, 0x136d600, 0x1370460, 0x0, 0x126c020, 0xc4200a0020, 0x195, 0x20, 0x1273ec0)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec/default_value_decoders.go:653 +0x1dc
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec.(DefaultValueDecoders).MapDecodeValue-fm(0xc4200c4070, 0x0, 0x1370460, 0x0, 0x126c020, 0xc4200a0020, 0x195, 0x1370820, 0x126c020)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec/default_value_decoders.go:79 +0x76
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec.ValueDecoderFunc.DecodeValue(0xc420092a40, 0xc4200c4070, 0x126c000, 0x1370460, 0x0, 0x126c020, 0xc4200a0020, 0x195, 0x104dfb0, 0x18)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/bsoncodec/bsoncodec.go:151 +0x78
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson.(*Decoder).Decode(0xc4200a6640, 0x12460e0, 0xc4200a0020, 0x1272b60, 0xc4200a6640)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/decoder.go:86 +0x259
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson.unmarshalFromReader(0xc4200c4070, 0xc42008d600, 0x1370460, 0x0, 0x12460e0, 0xc4200a0020, 0x0, 0x0)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/unmarshal.go:92 +0xea
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson.UnmarshalExtJSONWithRegistry(0xc4200c4070, 0xc4200f9be0, 0x7, 0x8, 0xc42008d600, 0x12460e0, 0xc4200a0020, 0x1290ca0, 0xc42008d620)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/unmarshal.go:68 +0xca
      mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson.UnmarshalExtJSON(0xc4200f9be0, 0x7, 0x8, 0xc4200f9b00, 0x12460e0, 0xc4200a0020, 0x12a81cd, 0x0)
              /Users/aarons/go/src/mdbdriver/vendor/github.com/mongodb/mongo-go-driver/bson/unmarshal.go:60 +0x6f
      main.main()
              /Users/aarons/go/src/mdbdriver/main.go:14 +0xce
      exit status 2
      

       

            Assignee:
            divjot.arora@mongodb.com Divjot Arora (Inactive)
            Reporter:
            aaronszy Aaron Szymanski
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: