You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The reason will be displayed to describe this comment to others. Learn more.
the driver-provided size validation is well scoped and the normal fetch and arrow paths hold up. I found one suggestion worth incorporating before merge, so requesting changes.
Reject short, zero, or oversized driver indicators for fixed C bindings before standard-row or Arrow processors read the reusable rowset buffers.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This completion logic still omits SQL_NO_DATA. After a truncating SQL_NO_TOTAL chunk, ODBC may complete the sequence with SQL_NO_DATA; unlike GetDataVar at lines 5676-5686, this direct LOB path treats that status as an error before reaching this break and raises for an otherwise completed value. Handle SQL_NO_DATA before reading the now-undefined indicator, accepting it only after payload progress, and add the corresponding injected LOB sequence.
Apply fixed-width and decimal indicator bounds before SQLGetData conversions used by fetchone and LOB-containing batches, with injected malformed-driver regressions.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoid per-cell type dispatch for invariant column widths
mssql_python/pybind/ddbc_bindings.cpp:5180
This restores a type switch for every fetched cell, even though dataType is invariant per column and the dispatch table above explicitly precomputes shape-dependent work to avoid that hot-loop cost. Precompute the expected fixed width in ColumnInfo while caching metadata, then make this per-cell validation a simple zero-or-equality check; that preserves the new safety check without adding repeated type dispatch to rows × columns processing.
This issue also appears on line 6644 of the same file.
Preserve the PR 803 malformed-driver suite while adding geometric LOB growth and execute-boundary regressions from the stacked base.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use ODBC indicators and payload capacity instead of trimming data bytes, preserve embedded NUL values, and precompute fixed-width sizes outside row and Arrow cell loops.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This cannot distinguish the single ODBC terminator from valid trailing U+0000 payload characters. It causes two related problems:
Trailing NUL characters are silently removed from returned data.
On a truncated chunk containing only NUL payload characters, bytesRead becomes zero and the new progress check throws:
if (continueForTruncation && bytesRead == 0) {
ThrowStdException("LOB fetch truncation made no progress");
}
The problem affects both narrow and wide character LOBs, although the current review thread emphasizes UTF-16.
Recommended fix
Derive progress from the bytes returned before terminator removal, then remove at most one protocol terminator:
The exact treatment should be verified against the driver’s SQLGetData terminator behavior. Add regression coverage where a large VARCHAR(MAX) and NVARCHAR(MAX) value contains or ends in one or more NUL characters across a chunk boundary.
for every row × column value. The Arrow path repeats this at FetchArrowBatch_wrap.
ValidateFixedFetchDataLength calls FixedFetchValueSize, which runs a SQL-type switch. The expected width depends only on column metadata and should be computed once per column in the existing metadata setup phase.
Recommended fix
Add a precomputed field:
struct ColumnInfo {
// ...
size_t fixedValueSize;
};
and Populate it once:
columnInfos[col].fixedValueSize =
FixedFetchValueSize(columnInfos[col].dataType);
and then hot loop validation becomes,
const size_t expectedSize = columnInfos[col - 1].fixedValueSize;
if (expectedSize != 0 && static_cast<uint64_t>(dataLen) != expectedSize) {
ThrowStdException(
"Fixed-width data indicator does not match the bound buffer size");
}
Do the equivalent for Arrow using a per-column vector. This is not a correctness blocker, but it avoids adding invariant type dispatch to the fetch hot path.
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
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.
Work Item / Issue Reference
Summary
Stacked on #802 so this review contains only driver-provided fetch validation.