From 7a2937931231268e3d736ca0209911f2e16388f5 Mon Sep 17 00:00:00 2001 From: Alan Boudreault Date: Tue, 9 May 2017 17:12:52 -0400 Subject: [PATCH] raise an exception if a number cannot be encoded as vint --- cassandra/marshal.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cassandra/marshal.py b/cassandra/marshal.py index 712fa6e7..f8f51230 100644 --- a/cassandra/marshal.py +++ b/cassandra/marshal.py @@ -127,8 +127,8 @@ def vints_unpack(term): # noqa def vints_pack(values): revbytes = bytearray() values = [int(v) for v in values[::-1]] - for v in values: - v = encode_zig_zag(v) + for value in values: + v = encode_zig_zag(value) if v < 128: revbytes.append(v) else: @@ -145,6 +145,9 @@ def vints_pack(values): revbytes.append(v & 0xff) v >>= 8 + if num_extra_bytes > 8: + raise ValueError('Value %d is too big and cannot be encoded as vint' % value) + # We can now store the last bits in the first byte n = 8 - num_extra_bytes v |= (0xff >> n << n)