Repository navigation
Copy only what fits in SqliteDataReader.GetValues - #39354
Merged
Merged
Conversation
GetValues threw IndexOutOfRangeException for an array shorter than the row. IDataRecord.GetValues: "You can pass an Object array that contains fewer than the number of columns that are contained in the resulting row. Only the amount of data the Object array holds is copied to the array." It now copies Math.Min(values.Length, FieldCount) values and returns that count. Fixes dotnet#39352 Found with https://github.com/pengdows/pengdows.AdoNetApiTest.conformance Co-Authored-By: Claude Opus 5.5 <[email protected]>
5 of 6 tasks
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Empty destination arrays bypass the existing no-current-row validation before the first read and after reader exhaustion.
1 open issue
What changed in this PR
This pull request updates SqliteDataReader.GetValues to copy only the values that fit in the supplied destination array, matching the IDataRecord contract.
Changes:
- Bounds copying by
Math.Min(values.Length, FieldCount)and returns the number copied. - Replaces the narrow-array exception test with coverage for partial and empty arrays.
- Introduces a zero-length path that bypasses current-row validation.
| File | Summary |
|---|---|
test/Microsoft.Data.Sqlite.Tests/SqliteDataReaderTest.cs |
Tests partial copying and empty destination arrays. |
src/Microsoft.Data.Sqlite.Core/SqliteValueReader.cs |
Limits value copying to the destination array length. |
Review effort: Lite
With the copy bounded by values.Length, an empty array skipped GetValue and so the current-row check: GetValues(Array.Empty<object>()) returned 0 before the first Read() and after Read() returned false. SqliteDataRecord now checks for a current row in GetValues, as it already does in GetValue. Co-Authored-By: Claude Opus 5.5 <[email protected]>
AndriySvyryd
approved these changes
Oct 22, 2026
AndriySvyryd
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Fixes #39352
SqliteDataReader.GetValuesthrows for an array shorter than the row; it now copiesMath.Min(values.Length, FieldCount)values and returns that count.What the documentation says
IDataRecord.GetValues, Remarks:
Why this is a bug
The contract explicitly allows a short array and says what to do with it; throwing
IndexOutOfRangeExceptionbreaks code that reads the leading columns of a row into a fixed-size buffer.Tests
GetValues_throws_when_too_narrowis replaced byGetValues_copies_only_what_fits_when_too_narrow: a 2-element array for a 3-column row copies1, 2and returns 2; an empty array returns 0.Microsoft.Data.Sqlite.Tests: 784 passed, 0 failed (7 skipped).This is the
GetValueshalf of #39344, which I'm closing in favour of one PR per change.Checklist
Found with https://github.com/pengdows/pengdows.AdoNetApiTest.conformance
🤖 Generated with Claude Code