diff options
author | elie <elie> | 2015-04-25 09:53:43 +0000 |
---|---|---|
committer | elie <elie> | 2015-04-25 09:53:43 +0000 |
commit | 6cd6af222bb36726f95d486461589105840d883f (patch) | |
tree | bf1ea2ef1f99110854f629e652e147b7705beb8b | |
parent | 7ead58fff72d7a092c825b13daed9f9b95e156d8 (diff) | |
download | pyasn1-6cd6af222bb36726f95d486461589105840d883f.tar.gz |
fix to BitString and OctetString decoders dealing with constructed
encoding -- it used to be possible to embed other types in substrate
-rw-r--r-- | CHANGES | 2 | ||||
-rw-r--r-- | pyasn1/codec/ber/decoder.py | 8 | ||||
-rw-r--r-- | test/codec/ber/test_decoder.py | 11 |
3 files changed, 15 insertions, 6 deletions
@@ -52,6 +52,8 @@ Revision 0.1.8rc2 - Fix to REAL type binary decoder to handle different bases and scale factor. - Fix to TagSet.repr() to include [obsolete] baseTag information. - Fix to broken REAL type decoding handling. +- Fix to BitString and OctetString decoders dealing with constructed + encoding -- it used to be possible to embed other types in substrate. Revision 0.1.7 -------------- diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py index 7bb09ea..2da4142 100644 --- a/pyasn1/codec/ber/decoder.py +++ b/pyasn1/codec/ber/decoder.py @@ -144,7 +144,7 @@ class BitStringDecoder(AbstractSimpleDecoder): if substrateFun: return substrateFun(r, substrate, length) while head: - component, head = decodeFun(head) + component, head = decodeFun(head, self.protoComponent) r = r + component return r, tail @@ -154,7 +154,7 @@ class BitStringDecoder(AbstractSimpleDecoder): if substrateFun: return substrateFun(r, substrate, length) while substrate: - component, substrate = decodeFun(substrate) + component, substrate = decodeFun(substrate, self.protoComponent) if eoo.endOfOctets.isSameTypeWith(component) and \ component == eoo.endOfOctets: break @@ -177,7 +177,7 @@ class OctetStringDecoder(AbstractSimpleDecoder): if substrateFun: return substrateFun(r, substrate, length) while head: - component, head = decodeFun(head) + component, head = decodeFun(head, self.protoComponent) r = r + component return r, tail @@ -187,7 +187,7 @@ class OctetStringDecoder(AbstractSimpleDecoder): if substrateFun: return substrateFun(r, substrate, length) while substrate: - component, substrate = decodeFun(substrate) + component, substrate = decodeFun(substrate, self.protoComponent) if eoo.endOfOctets.isSameTypeWith(component) and \ component == eoo.endOfOctets: break diff --git a/test/codec/ber/test_decoder.py b/test/codec/ber/test_decoder.py index 72ed77f..cde3ff8 100644 --- a/test/codec/ber/test_decoder.py +++ b/test/codec/ber/test_decoder.py @@ -99,7 +99,14 @@ class BitStringDecoderTestCase(unittest.TestCase): ints2octs((35, 128, 3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), substrateFun=lambda a,b,c: (b,c) ) == (ints2octs((3, 2, 0, 169, 3, 2, 1, 138, 0, 0)), -1) - + def testTypeChecking(self): + try: + decoder.decode(ints2octs((35, 4, 2, 2, 42, 42))) + except PyAsn1Error: + pass + except: + assert 0, 'accepted mis-encoded bit-string constructed out of an integer' + class OctetStringDecoderTestCase(unittest.TestCase): def testDefMode(self): assert decoder.decode( @@ -387,7 +394,7 @@ class RealDecoderTestCase(unittest.TestCase): decoder.decode(ints2octs((9, 1, 131))) except PyAsn1Error: pass - else: + except: assert 0, 'accepted too-short real' class SequenceDecoderTestCase(unittest.TestCase): |