Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GODRIVER-1923 Error if BSON cstrings contain null bytes #622

Merged
merged 5 commits into from Mar 29, 2021

Conversation

@divjotarora
Copy link
Collaborator

@divjotarora divjotarora commented Mar 25, 2021

Per bsonspec.org, cstrings are only used for BSON key names and for the pattern/options fields in a BSON regex value so this PR applies validation to those types. This validation does not apply to regular BSON strings, which can have null bytes because they're prefixed with a 4-byte length. It also does not apply to extended JSON because the JSON specification allows null bytes and other unicode code points as long as they are properly escaped (e.g. in JSON, this would look like {"foo\u0000": "bar"}.

@divjotarora divjotarora force-pushed the godriver1923-bson-cstrings branch from 93e724c to 78b349d Mar 25, 2021
@divjotarora divjotarora changed the title Error if BSON cstrings contain null bytes GODRIVER-1923 Error if BSON cstrings contain null bytes Mar 25, 2021
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Code change LGTM! I just have two questions.

bson/marshal_test.go Show resolved Hide resolved
bson/bsonrw/value_writer.go Show resolved Hide resolved
Copy link
Collaborator Author

@divjotarora divjotarora left a comment

Added validation to panic in bsoncore if a raw document is being constructed directly (e.g. using bsoncore.NewDocumentBuilder).

bson/bsonrw/value_writer.go Show resolved Hide resolved
bson/bsonrw/value_writer.go Show resolved Hide resolved
bson/marshal_test.go Show resolved Hide resolved
@divjotarora divjotarora requested review from iwysiu and kevinAlbs Mar 25, 2021
iwysiu
iwysiu approved these changes Mar 25, 2021
Copy link
Collaborator

@benjirewis benjirewis left a comment

LGTM!

x/bsonx/bsoncore/bsoncore_test.go Show resolved Hide resolved
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

Code LGTM, just a small question about tests.

bson/bsonrw/value_writer.go Show resolved Hide resolved
x/bsonx/bsoncore/bsoncore_test.go Show resolved Hide resolved
x/bsonx/bsoncore/bsoncore_test.go Outdated Show resolved Hide resolved
@divjotarora divjotarora requested a review from kevinAlbs Mar 29, 2021
Copy link
Contributor

@kevinAlbs kevinAlbs left a comment

LGTM!

@divjotarora divjotarora merged commit 2aca31d into mongodb:master Mar 29, 2021
15 checks passed
@divjotarora divjotarora deleted the godriver1923-bson-cstrings branch Mar 29, 2021
tolsen added a commit to tolsen/mongo-go-driver that referenced this issue Jun 10, 2021
iwysiu added a commit to iwysiu/mongo-go-driver that referenced this issue Jun 11, 2021
iwysiu added a commit that referenced this issue Jun 14, 2021
Co-authored-by: Divjot Arora <divjot.arora@10gen.com>
kevinAlbs added a commit to kevinAlbs/mongo-go-driver that referenced this issue Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants