Skip to content

Commit 90ed89c

Browse files
committed
Added checks to from_binary for SparseVector [skip ci]
1 parent b1e3669 commit 90ed89c

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

pgvector/sparsevec.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ def from_text(cls, value: str) -> SparseVector:
129129
@classmethod
130130
def from_binary(cls, value: bytes) -> SparseVector:
131131
dim, nnz, unused = unpack_from('>iii', value)
132+
133+
if len(value) != 12 + 8 * nnz:
134+
raise ValueError('invalid length')
135+
136+
if unused != 0:
137+
raise ValueError('expected unused to be 0')
138+
132139
indices = unpack_from(f'>{nnz}i', value, 12)
133140
values = unpack_from(f'>{nnz}f', value, 12 + nnz * 4)
134141
return cls._from_parts(int(dim), list(indices), list(values))

0 commit comments

Comments
 (0)