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
CSHARP-5065: Dispose RawBsonDocument in ExplicitEncryptionLibMongoCryptController.cs #1321
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -568,8 +568,8 @@ private Guid UnwrapKeyId(RawBsonDocument wrappedKeyDocument) | |||
|
|||
private BsonValue UnwrapValue(byte[] encryptedWrappedBytes) | |||
{ | |||
var rawDocument = new RawBsonDocument(encryptedWrappedBytes); | |||
return rawDocument["v"]; | |||
var bsonDocument = BsonSerializer.Deserialize<BsonDocument>(encryptedWrappedBytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks safe to me. I don't recall what was the motivation to use RawBsonDocument
as in most cases the v
value will being read completely but consumer.
Maybe @rstam has some ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why a RawBsonDocument
is being used here. If the goal is to deserialize the key bytes we should just do that directly.
Not sure that is the goal though.
@@ -568,8 +568,8 @@ private Guid UnwrapKeyId(RawBsonDocument wrappedKeyDocument) | |||
|
|||
private BsonValue UnwrapValue(byte[] encryptedWrappedBytes) | |||
{ | |||
var rawDocument = new RawBsonDocument(encryptedWrappedBytes); | |||
return rawDocument["v"]; | |||
var bsonDocument = BsonSerializer.Deserialize<BsonDocument>(encryptedWrappedBytes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know why a RawBsonDocument
is being used here. If the goal is to deserialize the key bytes we should just do that directly.
Not sure that is the goal though.
wrap uses of
RawBsonDocument
appropriately in using statements.Switch to using
BsonSerializer.Deserialize
in theUnwrapValue
function instead of usingRawBsonDocument
. This helps us since we couldn't dispose ofRawBsonDocument
in this case as the returned value would be disposed as well. Also avoids us having to do cloning as a remedy if we were to still useRawBsonDocument
.Just want input on whether I'm missing something here by not using RawBsonDocument