summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2012-05-28 10:08:31 +0000
committerelie <elie>2012-05-28 10:08:31 +0000
commit97af12c945f85ed0aeeecd7730f92ba32d3324a1 (patch)
tree2ce2ff9c8cbce73b6a06a6eac3396d3e6fc67b56
parent95afea9d81015a00a6eaa55c783cf31ad9bb6b2c (diff)
downloadpyasn1-97af12c945f85ed0aeeecd7730f92ba32d3324a1.tar.gz
catch inappropriate substrate type passed to decoder
-rw-r--r--CHANGES3
-rw-r--r--pyasn1/codec/ber/decoder.py5
-rw-r--r--pyasn1/compat/octets.py2
-rw-r--r--setup.py2
4 files changed, 9 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 3d75f97..8a1fdbe 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,7 +4,8 @@ Revision 0.1.4
- built-in codec debugging facility added
- Added some more checks to ObjectIdentifier BER encoder catching
posible 2^8 overflow condition by two leading sub-OIDs
-- Fix in Boolean truth testting built-in methods
+- Catch inappropriate substrate type passed to decoder.
+- Fix in Boolean truth testing built-in methods
- Fix to substrate underrun error handling at ObjectIdentifier BER decoder
- Fix to BER Boolean decoder that allows other pre-computed
values besides 0 and 1
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py
index db3e00a..bc4ae43 100644
--- a/pyasn1/codec/ber/decoder.py
+++ b/pyasn1/codec/ber/decoder.py
@@ -1,7 +1,7 @@
# BER decoder
from pyasn1.type import tag, base, univ, char, useful, tagmap
from pyasn1.codec.ber import eoo
-from pyasn1.compat.octets import oct2int, octs2ints
+from pyasn1.compat.octets import oct2int, octs2ints, isOctetsType
from pyasn1 import debug, error
class AbstractDecoder:
@@ -547,6 +547,9 @@ class Decoder:
raise error.SubstrateUnderrunError(
'Short octet stream on tag decoding'
)
+ if not isOctetsType(substrate) and \
+ not isinstance(substrate, univ.OctetString):
+ raise error.PyAsn1Error('Bad octet stream type')
firstOctet = substrate[0]
substrate = substrate[1:]
diff --git a/pyasn1/compat/octets.py b/pyasn1/compat/octets.py
index d0303ea..f7f2a29 100644
--- a/pyasn1/compat/octets.py
+++ b/pyasn1/compat/octets.py
@@ -8,6 +8,7 @@ if version_info[0] <= 2:
octs2ints = lambda s: [ oct2int(x) for x in s ]
str2octs = lambda x: x
octs2str = lambda x: x
+ isOctetsType = lambda s: isinstance(s, str)
else:
ints2octs = bytes
int2oct = lambda x: ints2octs((x,))
@@ -16,3 +17,4 @@ else:
octs2ints = lambda s: [ x for x in s ]
str2octs = lambda x: x.encode()
octs2str = lambda x: x.decode()
+ isOctetsType = lambda s: isinstance(s, bytes)
diff --git a/setup.py b/setup.py
index 74c8b0a..0c522e6 100644
--- a/setup.py
+++ b/setup.py
@@ -25,7 +25,7 @@ except ImportError:
params.update( {
'name': 'pyasn1',
- 'version': '0.1.4',
+ 'version': '0.1.4rc0',
'description': 'ASN.1 types and codecs',
'author': 'Ilya Etingof',
'author_email': 'ilya@glas.net',