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

Extended JSON lone $scope does not error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: 1.3.0
    • Fix Version/s: 1.3.2
    • Component/s: JSON & ExtJSON
    • Labels:
      None

      Description

      A lone $scope key should error because the spec says:

      If the parsed object contains any of the special keys in the Conversion table such as "$binary", "$timestamp", etc., then it must contain exactly the keys of a type wrapper. Any missing or extra keys constitute an error.

      But the driver parses it without error:

      {"":"","":{"$scope":{}}}}
      1c000000020001000000000f000e0000000100000000050000000000
      

      N.B. Removing the opening key/value pair causes a panic, so there's probably a larger problem in $scope parsing.

      {"":{"$scope":{}}}
      panic: runtime error: invalid memory address or nil pointer dereference
      [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x567198]
       
      goroutine 1 [running]:
      go.mongodb.org/mongo-driver/bson/bsonrw.(*extJSONValue).parseJavascript(...)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/bsonrw/extjson_wrappers.go:334
      go.mongodb.org/mongo-driver/bson/bsonrw.(*extJSONValueReader).ReadCodeWithScope(0xc000116240, 0x7dd80f, 0x7f312ac92ec8, 0xc00009d870, 0x4422ee, 0xc000112048, 0x7f2618)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/bsonrw/extjson_reader.go:347 +0xb8
      go.mongodb.org/mongo-driver/bson/bsonrw.Copier.CopyValue(0x67fc40, 0xc000128000, 0x67fd20, 0xc000116240, 0xc000128000, 0x0)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/bsonrw/copier.go:275 +0x66f
      go.mongodb.org/mongo-driver/bson/bsonrw.Copier.copyDocumentCore(0x679f00, 0xc000128000, 0x679500, 0xc000116240, 0x0, 0x42c0ca)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/bsonrw/copier.go:382 +0xd5
      go.mongodb.org/mongo-driver/bson/bsonrw.Copier.CopyDocument(0x67fc40, 0xc000128000, 0x67fd20, 0xc000116240, 0x0, 0xc000114400)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/bsonrw/copier.go:45 +0xbf
      go.mongodb.org/mongo-driver/bson/bsonrw.Copier.AppendDocumentBytes(0x7f2618, 0x0, 0x0, 0x67fd20, 0xc000116240, 0x0, 0x0, 0x0, 0x0, 0x0)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/bsonrw/copier.go:131 +0x1e7
      go.mongodb.org/mongo-driver/bson.PrimitiveCodecs.RawDecodeValue(0xc0000eec40, 0xc00009db00, 0x0, 0x0, 0x67fd20, 0xc000116240, 0x618b60, 0xc000114380, 0x197, 0x5aac94, ...)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/primitive_codecs.go:86 +0x136
      go.mongodb.org/mongo-driver/bson/bsoncodec.ValueDecoderFunc.DecodeValue(0xc00001ab40, 0xc0000eec40, 0x618b00, 0x0, 0x0, 0x67fd20, 0xc000116240, 0x618b60, 0xc000114380, 0x197, ...)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/bsoncodec/bsoncodec.go:156 +0x98
      go.mongodb.org/mongo-driver/bson.(*Decoder).Decode(0xc000116090, 0x618700, 0xc000114380, 0xc00009dcc0, 0x679120)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/decoder.go:98 +0x20d
      go.mongodb.org/mongo-driver/bson.unmarshalFromReader(0xc0000eec40, 0xc000116200, 0x0, 0x0, 0x67fd20, 0xc000116240, 0x618700, 0xc000114380, 0x0, 0x0)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/unmarshal.go:100 +0x121
      go.mongodb.org/mongo-driver/bson.UnmarshalExtJSONWithRegistry(0xc0000eec40, 0xc00011e1a0, 0x12, 0x20, 0x0, 0x618700, 0xc000114380, 0x0, 0x0)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/unmarshal.go:72 +0x100
      go.mongodb.org/mongo-driver/bson.UnmarshalExtJSON(...)
              /home/xdg/golang/pkg/mod/go.mongodb.org/mongo-driver@v1.3.0/bson/unmarshal.go:60
      main.main()
              /home/xdg/tmp/godriver-extjson/main.go:27 +0x35e
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              divjot.arora Divjot Arora
              Reporter:
              david.golden David Golden
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: