[CSHARP-4213] CryptClient.StartDecryptionContext pins buffer but never unpins Created: 15/Jun/22 Updated: 28/Oct/23 Resolved: 17/Jun/22 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | Field Level Encryption |
| Affects Version/s: | None |
| Fix Version/s: | 2.16.1 |
| Type: | Bug | Priority: | Critical - P2 |
| Reporter: | James Kovacs | Assignee: | Dmitry Lukyanov (Inactive) |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | FLE | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Case: | (copied to CRM) | ||||
| Description |
|
The following code is located in CryptClient.cs:
Note the 5th line where gch is allocated. The allocated GCHandle is a struct that represents a pointer that can be passed to unmanaged code. You must explicitly free it. It has no finalizer or Dispose method. If you allocate it pinned (as done here), it acts as a rooted reference which will keep the referenced memory (and anything it points to) alive indefinitely. Note that we later allocate a PinnedBinary, which implements IDisposable and allows us to pin the buffer to be passed to the unmanaged code and correctly unpins it upon return. Based on my review of the code, the 5th line allocating gch is dead code that should be deleted. Not only is it dead code, it is responsible for keeping alive any System.Byte[] buffer passed into this method. Because we attempt to decrypt any response from the server (in case there are encrypted fields in the response), this results in a slow build-up of System.Byte[] objects when CSFLE is enabled for the .NET/C# Driver. |
| Comments |
| Comment by Githook User [ 21/Jun/22 ] |
|
Author: {'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}Message: |
| Comment by Githook User [ 17/Jun/22 ] |
|
Author: {'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}Message: |
| Comment by Githook User [ 17/Jun/22 ] |
|
Author: {'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}Message: |
| Comment by Githook User [ 17/Jun/22 ] |
|
Author: {'name': 'Dmitry Lukyanov', 'email': 'dmitry.lukyanov@mongodb.com', 'username': 'DmitryLukyanov'}Message: |