修改工具类支持
diff --git a/tcutils/pbocfunc.py b/tcutils/pbocfunc.py
index 942ea18..7c4fe90 100644
--- a/tcutils/pbocfunc.py
+++ b/tcutils/pbocfunc.py
@@ -150,15 +150,19 @@
offset = 0
while offset < datalen:
t = ord(data[offset])
- if t & 0x0F == 0x0F:
+ if t & 0x0F == 0x0F and (t not in (0x4f, 0x8f)):
tag = data[offset:offset + 2]
offset += 2
else:
tag = data[offset]
offset += 1
+ if offset >= datalen:
+ raise ValueError(u"data length error, cannot get tag length")
t = ord(data[offset])
if t & 0x80 == 0x80:
vl = t & 0x7F
+ if offset + 1 + vl >= datalen:
+ raise ValueError(u"data length error, cannot get tag length")
vlen = 0
for c in data[offset + 1:offset + 1 + vl]:
vlen = (vlen << 8) + ord(c)
@@ -168,8 +172,8 @@
offset += 1
if datalen - offset < vlen:
- raise ValueError(u"data length Error, tag [%s]length[%d]" % (
- codecs.encode(tag, 'hex'), vlen))
+ raise ValueError(u"data length Error, tag [%s]length[%d],left[%d]" % (
+ codecs.encode(tag, 'hex'), vlen, datalen - offset))
value = data[offset:offset + vlen]
offset += vlen
yield (tag, value,)