THRIFT-2757: py - Added integer limits checks in compact and JSON protocols
Client: Python
Patch: Bret Curtis
This closes: #234
diff --git a/lib/py/src/protocol/TProtocol.py b/lib/py/src/protocol/TProtocol.py
index 40e05b1..bd69067 100644
--- a/lib/py/src/protocol/TProtocol.py
+++ b/lib/py/src/protocol/TProtocol.py
@@ -402,6 +402,12 @@
else:
writer(val)
+def checkIntegerLimits(i, bits):
+ lo = -(2 ** (bits - 1))
+ hi = 2 ** (bits - 1) - 1
+ if not lo <= i <= hi:
+ raise TProtocolException(TProtocolException.INVALID_DATA,
+ "i%d value: %d is outside range: [%d, %d]" % (bits, i, lo, hi))
class TProtocolFactory:
def getProtocol(self, trans):