summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorelie <elie>2013-02-09 11:56:48 +0000
committerelie <elie>2013-02-09 11:56:48 +0000
commit527d8a3bbe88107816f3a2d0dae33e7c68974f44 (patch)
treef7fd004e79ebafe1001750aee565e51c477276a5
parent0556ef80a26281cbc843e1f1c005d3441d050999 (diff)
downloadpyasn1-527d8a3bbe88107816f3a2d0dae33e7c68974f44.tar.gz
Fix to decoder working on indefinite length substrate -- end-of-octets
marker is now detected by both tag and value. Otherwise implicitly tagged values may interfere with end-of-octets marker.
-rw-r--r--CHANGES3
-rw-r--r--pyasn1/codec/ber/decoder.py21
2 files changed, 17 insertions, 7 deletions
diff --git a/CHANGES b/CHANGES
index 7c84c42..a2be213 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
Revision 0.1.7
--------------
+- Fix to decoder working on indefinite length substrate -- end-of-octets
+ marker is now detected by both tag and value. Otherwise implicitly tagged
+ values may interfere with end-of-octets marker.
- Fix to decoder to fail in cases where tagFormat indicates inappropriate
format for the type (e.g. BOOLEAN is always PRIMITIVE, SET is always
CONSTRUCTED and OCTET STRING is either of the two)
diff --git a/pyasn1/codec/ber/decoder.py b/pyasn1/codec/ber/decoder.py
index 82b3352..4dd00f3 100644
--- a/pyasn1/codec/ber/decoder.py
+++ b/pyasn1/codec/ber/decoder.py
@@ -64,7 +64,8 @@ class ExplicitTagDecoder(AbstractSimpleDecoder):
)
value, substrate = decodeFun(substrate, asn1Spec, tagSet, length)
terminator, substrate = decodeFun(substrate)
- if terminator == eoo.endOfOctets:
+ if eoo.endOfOctets.isSameTypeWith(terminator) and \
+ terminator == eoo.endOfOctets:
return value, substrate
else:
raise error.PyAsn1Error('Missing end-of-octets terminator')
@@ -154,7 +155,8 @@ class BitStringDecoder(AbstractSimpleDecoder):
return substrateFun(r, substrate, length)
while substrate:
component, substrate = decodeFun(substrate)
- if component == eoo.endOfOctets:
+ if eoo.endOfOctets.isSameTypeWith(component) and \
+ component == eoo.endOfOctets:
break
r = r + component
else:
@@ -186,7 +188,8 @@ class OctetStringDecoder(AbstractSimpleDecoder):
return substrateFun(r, substrate, length)
while substrate:
component, substrate = decodeFun(substrate)
- if component == eoo.endOfOctets:
+ if eoo.endOfOctets.isSameTypeWith(component) and \
+ component == eoo.endOfOctets:
break
r = r + component
else:
@@ -336,7 +339,8 @@ class SequenceDecoder(AbstractConstructedDecoder):
while substrate:
asn1Spec = self._getComponentTagMap(r, idx)
component, substrate = decodeFun(substrate, asn1Spec)
- if component == eoo.endOfOctets:
+ if eoo.endOfOctets.isSameTypeWith(component) and \
+ component == eoo.endOfOctets:
break
idx = self._getComponentPositionByType(
r, component.getEffectiveTagSet(), idx
@@ -377,7 +381,8 @@ class SequenceOfDecoder(AbstractConstructedDecoder):
idx = 0
while substrate:
component, substrate = decodeFun(substrate, asn1Spec)
- if component == eoo.endOfOctets:
+ if eoo.endOfOctets.isSameTypeWith(component) and \
+ component == eoo.endOfOctets:
break
r.setComponentByPosition(idx, component, asn1Spec is None)
idx = idx + 1
@@ -435,7 +440,8 @@ class ChoiceDecoder(AbstractConstructedDecoder):
if r.getTagSet() == tagSet: # explicitly tagged Choice
component, substrate = decodeFun(substrate, r.getComponentTagMap())
eooMarker, substrate = decodeFun(substrate) # eat up EOO marker
- if eooMarker != eoo.endOfOctets:
+ if not eoo.endOfOctets.isSameTypeWith(eooMarker) or \
+ eooMarker != eoo.endOfOctets:
raise error.PyAsn1Error('No EOO seen before substrate ends')
else:
component, substrate= decodeFun(
@@ -482,7 +488,8 @@ class AnyDecoder(AbstractSimpleDecoder):
return substrateFun(r, substrate, length)
while substrate:
component, substrate = decodeFun(substrate, asn1Spec)
- if component == eoo.endOfOctets:
+ if eoo.endOfOctets.isSameTypeWith(component) and \
+ component == eoo.endOfOctets:
break
r = r + component
else: