Fix SQL parsing, DBNull handling, and resource leaks#55
Fix SQL parsing, DBNull handling, and resource leaks#55
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.
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(); |
There was a problem hiding this comment.
[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.
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(); |
There was a problem hiding this comment.
[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.
Fixed in commit 1bba89d - replaced redundant cs.Close() with cs.FlushFinalBlock() for consistency with the file-based methods.
| // 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 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.