[GODRIVER-1520] Extended JSON lone $scope does not error Created: 03/Mar/20  Updated: 28/Oct/23  Resolved: 12/Mar/20

Status: Closed
Project: Go Driver
Component/s: JSON & ExtJSON
Affects Version/s: 1.3.0
Fix Version/s: 1.3.2

Type: Bug Priority: Major - P3
Reporter: David Golden Assignee: Divjot Arora (Inactive)
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
is related to GODRIVER-1521 Extended JSON $scope prone to panics Closed

 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



 Comments   
Comment by Githook User [ 12/Mar/20 ]

Author:

{'username': 'divjotarora', 'name': 'Divjot Arora', 'email': 'divjot.arora@10gen.com'}

Message: GODRIVER-1520 Fix panics for lone scope (#331)
Branch: release/1.3
https://github.com/mongodb/mongo-go-driver/commit/8c4d9feac128dabac94eef0b95a956a02310eadb

Comment by Githook User [ 12/Mar/20 ]

Author:

{'name': 'Divjot Arora', 'username': 'divjotarora', 'email': 'divjot.arora@10gen.com'}

Message: GODRIVER-1520 Fix panics for lone scope (#331)
Branch: master
https://github.com/mongodb/mongo-go-driver/commit/862179125183bdee9ceadf6bd82c86fca063f569

Comment by Divjot Arora (Inactive) [ 11/Mar/20 ]

https://github.com/mongodb/mongo-go-driver/pull/331

Generated at Thu Feb 08 08:36:34 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.