summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2015-09-15 18:06:22 +0000
committerelie <elie>2015-09-15 18:06:22 +0000
commit01ec0c0b20be511dd95678a176c605184eb372bf (patch)
tree643fe76c74dde1e97c0996c5edb65da7c5b3396d
parent8b721d294ab99f55b9ff670b53bc1e5d1920b37c (diff)
downloadpyasn1-01ec0c0b20be511dd95678a176c605184eb372bf.tar.gz
Fix to CER/DER Boolean decoder - fail on non single-octet payload.
Thanks to Alex Gaynor for pointing out!
-rw-r--r--CHANGES.txt1
-rw-r--r--pyasn1/codec/cer/decoder.py6
-rw-r--r--test/codec/cer/test_decoder.py10
3 files changed, 14 insertions, 3 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 90bd1fc..9f4c647 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -5,6 +5,7 @@ Revision 0.1.9
- Extensions added to text files, CVS attic flushed.
- Fix to make uninitilaized pyasn1 objects failing properly on hash().
- Fix to ObjectIdentifier initialization from unicode string.
+- Fix to CER/DER Boolean decoder - fail on non single-octet payload.
Revision 0.1.8, released 22-06-2015
-----------------------------------
diff --git a/pyasn1/codec/cer/decoder.py b/pyasn1/codec/cer/decoder.py
index 9fd37c1..1770cd8 100644
--- a/pyasn1/codec/cer/decoder.py
+++ b/pyasn1/codec/cer/decoder.py
@@ -9,8 +9,8 @@ class BooleanDecoder(decoder.AbstractSimpleDecoder):
def valueDecoder(self, fullSubstrate, substrate, asn1Spec, tagSet, length,
state, decodeFun, substrateFun):
head, tail = substrate[:length], substrate[length:]
- if not head:
- raise error.PyAsn1Error('Empty substrate')
+ if not head or length != 1:
+ raise error.PyAsn1Error('Not single-octet Boolean payload')
byte = oct2int(head[0])
# CER/DER specifies encoding of TRUE as 0xFF and FALSE as 0x0, while
# BER allows any non-zero value as TRUE; cf. sections 8.2.2. and 11.1
@@ -20,7 +20,7 @@ class BooleanDecoder(decoder.AbstractSimpleDecoder):
elif byte == 0x00:
value = 0
else:
- raise error.PyAsn1Error('Boolean CER violation: %s' % byte)
+ raise error.PyAsn1Error('Unexpected Boolean payload: %s' % byte)
return self._createComponent(asn1Spec, tagSet, value), tail
tagMap = decoder.tagMap.copy()
diff --git a/test/codec/cer/test_decoder.py b/test/codec/cer/test_decoder.py
index 7195b72..9d793a3 100644
--- a/test/codec/cer/test_decoder.py
+++ b/test/codec/cer/test_decoder.py
@@ -17,6 +17,16 @@ class BooleanDecoderTestCase(unittest.TestCase):
assert decoder.decode(ints2octs((1, 1, 255))) == (1, null)
def testFalse(self):
assert decoder.decode(ints2octs((1, 1, 0))) == (0, null)
+ def testEmpty(self):
+ try:
+ decoder.decode(ints2octs((1, 0)))
+ except PyAsn1Error:
+ pass
+ def testOverflow(self):
+ try:
+ decoder.decode(ints2octs((1, 2, 0, 0)))
+ except PyAsn1Error:
+ pass
class OctetStringDecoderTestCase(unittest.TestCase):
def testShortMode(self):