Skip to content

Commit f9a25de

Browse files
Validate column_count in decode_rows_continuation against _MAX_COLUMN_COUNT
decode_body() validated column_count but decode_rows_continuation() did not, creating an inconsistency where the continuation path had no defense-in-depth cap on the caller-provided column_count parameter. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 9cd7799 commit f9a25de

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

src/dqlitewire/messages/responses.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ def decode_rows_continuation(
378378
method to decode those continuation messages, passing the column_names
379379
and column_count from the initial response.
380380
"""
381+
if column_count > _MAX_COLUMN_COUNT:
382+
raise DecodeError(f"Column count {column_count} exceeds maximum {_MAX_COLUMN_COUNT}")
381383
if len(column_names) != column_count:
382384
raise DecodeError(
383385
f"column_names length ({len(column_names)}) does not match "

tests/test_messages_responses.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -533,6 +533,21 @@ def test_continuation_column_count_mismatch_raises(self) -> None:
533533
column_count=2,
534534
)
535535

536+
def test_decode_rows_continuation_rejects_excessive_column_count(self) -> None:
537+
"""decode_rows_continuation should reject column_count exceeding _MAX_COLUMN_COUNT."""
538+
import pytest
539+
540+
from dqlitewire.exceptions import DecodeError
541+
542+
body = b"\xff" * 8 # DONE marker
543+
excessive = 20_000
544+
with pytest.raises(DecodeError, match="exceeds maximum"):
545+
RowsResponse.decode_rows_continuation(
546+
body,
547+
column_names=["c"] * excessive,
548+
column_count=excessive,
549+
)
550+
536551

537552
class TestEmptyResponse:
538553
def test_encode(self) -> None:

0 commit comments

Comments
 (0)