Skip to content

Commit d0912f6

Browse files
gargsaumyaCopilot
andcommitted
FIX: bound LOB growth test helper
Reject boolean, zero, oversized chunk counts and invalid chunk sizes before the internal production test binding can enter its simulation loop. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 48a2f23 commit d0912f6

2 files changed

Lines changed: 25 additions & 1 deletion

File tree

‎mssql_python/pybind/ddbc_bindings.cpp‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,16 @@ size_t ExtendNativeFetchBuffer(std::vector<char>& buffer, size_t currentSize, si
519519
return requiredSize;
520520
}
521521

522-
py::tuple TestLobBufferGrowth(size_t chunkCount, size_t chunkSize) {
522+
py::tuple TestLobBufferGrowth(py::handle chunkCountArg, py::handle chunkSizeArg) {
523+
const size_t chunkCount = static_cast<size_t>(
524+
ValidateNativeRowCountArgument(chunkCountArg, "LOB growth chunk count", false));
525+
if (!PyLong_Check(chunkSizeArg.ptr()) || PyBool_Check(chunkSizeArg.ptr())) {
526+
ThrowStdException("LOB growth chunk size must be a positive integer");
527+
}
528+
const size_t chunkSize = chunkSizeArg.cast<size_t>();
529+
if (chunkSize == 0 || chunkSize > MAX_NATIVE_FETCH_BYTES) {
530+
ThrowStdException("LOB growth chunk size must be between 1 and 256 MiB");
531+
}
523532
std::vector<char> buffer;
524533
size_t dataSize = 0;
525534
size_t reservedBytes = 0;

‎tests/test_010_pybind_functions.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,21 @@ def test_lob_buffer_growth_is_geometric():
8787
assert growth_count == 7
8888

8989

90+
@pytest.mark.skipif(not DDBC_AVAILABLE, reason="ddbc_bindings not available")
91+
@pytest.mark.parametrize(
92+
("chunk_count", "chunk_size", "message"),
93+
[
94+
(1_000_001, 1, "chunk count"),
95+
(True, 1, "chunk count"),
96+
(1, 0, "chunk size"),
97+
(1, True, "chunk size"),
98+
],
99+
)
100+
def test_lob_buffer_growth_helper_rejects_unsafe_sizes(chunk_count, chunk_size, message):
101+
with pytest.raises((RuntimeError, TypeError), match=message):
102+
ddbc._test_lob_buffer_growth(chunk_count, chunk_size)
103+
104+
90105
@pytest.mark.skipif(not DDBC_AVAILABLE, reason="ddbc_bindings not available")
91106
class TestPybindModuleInfo:
92107
"""Test module information and architecture detection."""

0 commit comments

Comments
 (0)