SQLite: do not ask for the metadata of a column that has no table - #38976
Merged
AndriySvyryd merged 1 commit intoSep 14, 2026
Merged
AndriySvyryd merged 1 commit into
AndriySvyryd merged 1 commit into
Conversation
GetStream looked for a rowid column to open a blob on, and for a value that came from an expression the database, table and origin names are all null. Those nulls were passed to sqlite3_table_column_metadata, which answers SQLITE_MISUSE, so reading a stream from an expression threw as soon as any other expression column was in the same query. - A column with no database or table name now returns the MemoryStream fallback, the same as when no rowid column is found - GetTextReader and GetFieldValue<Stream> go through GetStream, so they are fixed with it Fixes dotnet#27776
AndriySvyryd
approved these changes
Sep 14, 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 #27776
the issue asks whether the column metadata calls in
GetStreamcan be handed a null , and they can .what happens
GetStreamlooks for a rowid column so it can hand back aSqliteBlob. for a value that came from an expression there is no underlying column , sosqlite3_column_database_name,sqlite3_column_table_nameandsqlite3_column_origin_nameall answer null . i printed them forSELECT 42, substr("Content", 1, 3) FROM "Case":the search starts from a null database and table name , so the literal in column 0 matches it , and its null origin name goes into
sqlite3_table_column_metadata. sqlite answersSQLITE_MISUSEandGetStreamthrows :the same expression on its own is fine , because there is no second column for the search to reach . that is why the report says removing the
42makes it work . it is also why a real column sitting next to a literal is fine , a non null table name does not match the literal's null one .this is the ado.net repro of ericsink/SQLitePCL.raw#479 , which asked whether the bug was in the wrapper or in the caller . it is the caller .
the fix
a column with no database or table name has no row to open a blob on , so return the
MemoryStream, which is what already happens when no rowid column is found :GetTextReaderandGetFieldValue<Stream>both go throughGetStream, so they are fixed with it .tests
three , next to the existing
GetStreamones .GetStream_works_when_expression_and_a_literal_in_the_same_query, the report's shape . throwsSQLITE_MISUSEon main , gives aMemoryStreamwith the right three bytes afterGetTextReader_works_when_expression_and_a_literal_in_the_same_query, same path through the text reader . same before and afterGetStream_Blob_works_when_a_literal_is_in_the_same_query, a real blob column with a literal beside it . passes on main and after , so the guard is not swallowing the blob caseon main that is 2 failures out of 714 , and both are the two above . with the change
Microsoft.Data.Sqlite.sqlite3.Testsis 707 pass ,sqlite3mc708 pass ,EFCore.Sqlite.Tests896 pass , all 0 failed .EFCore.Sqlite.FunctionalTestsis 38042 pass , and its 177 failures are allmod_spatialite.dylibnot being installed on this mac , the same 177 as before the change .🤖 Generated with Claude Code
https://claude.ai/code/session_01VfnFMKDUZWENKk7Vpe6GS7