Skip to content

Commit 38670df

Browse files
Validate data length in decode_value for NULL type
Every other fixed-size decode path (INTEGER, FLOAT, BOOLEAN, etc.) validates that at least 8 bytes are available before returning a consumed count of 8. The NULL path was missing this check, which could cause misleading errors on truncated data — the error would appear on the next column decode instead of the NULL column. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5230143 commit 38670df

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/dqlitewire/types.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,8 @@ def decode_value(data: bytes, value_type: ValueType) -> tuple[Any, int]:
275275
elif value_type == ValueType.BLOB:
276276
return decode_blob(data)
277277
elif value_type == ValueType.NULL:
278+
if len(data) < 8:
279+
raise DecodeError(f"Need 8 bytes for NULL value, got {len(data)}")
278280
return None, 8
279281
else:
280282
raise DecodeError(f"Unknown value type: {value_type}")

tests/test_types.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -636,3 +636,11 @@ def test_decode_null(self) -> None:
636636
value, consumed = decode_value(b"\x00" * 8, ValueType.NULL)
637637
assert value is None
638638
assert consumed == 8
639+
640+
def test_decode_null_truncated(self) -> None:
641+
with pytest.raises(DecodeError, match="8 bytes"):
642+
decode_value(b"\x00" * 4, ValueType.NULL)
643+
644+
def test_decode_null_empty(self) -> None:
645+
with pytest.raises(DecodeError, match="8 bytes"):
646+
decode_value(b"", ValueType.NULL)

0 commit comments

Comments
 (0)