-
-
Notifications
You must be signed in to change notification settings - Fork 13
Fix SQL parsing, DBNull handling, and resource leaks #55
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
base: master
Are you sure you want to change the base?
Conversation
|
Important Review skippedBot user detected. To trigger a single review, invoke the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. Comment |
…on helper Co-authored-by: christianhelle <710400+christianhelle@users.noreply.github.com>
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.
Pull request overview
This PR addresses three distinct categories of bugs discovered during a codebase audit: SQL statement parsing with whitespace, database NULL value handling, and resource leaks in cryptographic operations.
Key Changes:
- Fixed SQL SELECT detection to handle leading/trailing whitespace by adding
.Trim()to match SqlCeDatabase31 behavior - Corrected data script generation to properly detect database NULL values by checking both
nullandDBNull.Value - Eliminated resource leaks by wrapping all IDisposable cryptographic and stream objects in
usingstatements
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 14 comments.
| File | Description |
|---|---|
| Source/SqlCeDatabase35/SqlCeDatabase.cs | Added .Trim() to SQL statement detection to correctly identify SELECT queries with leading/trailing whitespace, ensuring consistency with SqlCeDatabase31 implementation |
| Source/SqlCeDatabase/TableExtensions.cs | Enhanced NULL value detection by checking for both null and DBNull.Value, fixing incorrect literal output of database NULLs in generated INSERT statements |
| Source/Editor/Misc/StringEncryptionHelper.cs | Wrapped all IDisposable objects (MemoryStream, CryptoStream, FileStream, Rijndael, PasswordDeriveBytes) in using statements across 6 methods to prevent resource leaks |
| // there is no more data coming in, | ||
| // and it is now a good time to apply the padding and | ||
| // finalize the encryption process. | ||
| cs.Close(); |
Copilot
AI
Dec 8, 2025
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.
[nitpick] The explicit cs.Close() call is redundant since the using statement will automatically dispose the CryptoStream. Consider either:
- Removing the explicit
Close()call and relying on theusingstatement (consistent with the file encryption methods) - Using
cs.FlushFinalBlock()instead ofcs.Close()to make the intent clearer
This inconsistency exists in both Encrypt and Decrypt methods that work with byte arrays (lines 63 and 252), while the file-based methods correctly rely only on the using statement.
| cs.Close(); |
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.
Replaced cs.Close() with cs.FlushFinalBlock() for clarity in commit 1bba89d. The using statement now handles disposal while FlushFinalBlock() explicitly signals the end of encryption operations.
| // and there is no more data coming in, | ||
| // and it is now a good time to remove the padding | ||
| // and finalize the decryption process. | ||
| cs.Close(); |
Copilot
AI
Dec 8, 2025
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.
[nitpick] The explicit cs.Close() call is redundant since the using statement will automatically dispose the CryptoStream. Consider either removing it or using cs.FlushFinalBlock() for clarity. This should be consistent with how the file-based encryption/decryption methods handle resource disposal.
| cs.Close(); | |
| cs.FlushFinalBlock(); |
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.
Fixed in commit 1bba89d - replaced redundant cs.Close() with cs.FlushFinalBlock() for consistency with the file-based methods.
| // You can also read KeySize/BlockSize properties off | ||
| // the algorithm to find out the sizes. | ||
| byte[] encryptedData = Encrypt(clearBytes, | ||
| pdb.GetBytes(32), pdb.GetBytes(16)); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
| // You can also read KeySize/BlockSize properties off | ||
| // the algorithm to find out the sizes. | ||
| byte[] encryptedData = Encrypt(clearBytes, | ||
| pdb.GetBytes(32), pdb.GetBytes(16)); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
| // bytes and so should be the IV size. | ||
| // You can also read KeySize/BlockSize properties off the | ||
| // algorithm to find out the sizes. | ||
| return Encrypt(clearData, pdb.GetBytes(32), pdb.GetBytes(16)); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
| // You can also read KeySize/BlockSize properties off | ||
| // the algorithm to find out the sizes. | ||
| byte[] decryptedData = Decrypt(cipherBytes, | ||
| pdb.GetBytes(32), pdb.GetBytes(16)); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
|
|
||
| // You can also read KeySize/BlockSize properties off the | ||
| // algorithm to find out the sizes. | ||
| return Decrypt(cipherData, pdb.GetBytes(32), pdb.GetBytes(16)); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
|
|
||
| // You can also read KeySize/BlockSize properties off the | ||
| // algorithm to find out the sizes. | ||
| return Decrypt(cipherData, pdb.GetBytes(32), pdb.GetBytes(16)); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
| // close everything | ||
| cs.Close(); // this will also close the unrelying fsOut stream | ||
| fsIn.Close(); | ||
| alg.Key = pdb.GetBytes(32); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
| cs.Close(); // this will also close the unrelying fsOut stream | ||
| fsIn.Close(); | ||
| alg.Key = pdb.GetBytes(32); | ||
| alg.IV = pdb.GetBytes(16); |
Copilot
AI
Dec 8, 2025
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.
Call to obsolete method GetBytes.
|
@copilot apply changes based on the comments in this thread |
Co-authored-by: christianhelle <710400+christianhelle@users.noreply.github.com>
Applied the changes - replaced redundant Note: The obsolete |
.Trim()in SQL statement check in SqlCeDatabase35.SqlCeDatabase.ExecuteQuery() - queries with leading whitespace were not being recognized as SELECT statementsusingstatementscs.Close()calls withcs.FlushFinalBlock()for clarity sinceusingstatements handle disposalOriginal prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.