Re: [pyasn1-users] SubstrateUnderrunError with roundtrip encode/decode.
Brought to you by:
elie
|
From: Ilya E. <il...@gl...> - 2013-01-27 21:26:36
|
Hi Paul, That also looks like a bug in CHOICE decoder whenever indefinite length mode is used. It's hopefully fixed at CVS so please give it a try: http://pyasn1.cvs.sourceforge.net/viewvc/pyasn1/pyasn1/?view=tar Please alert me in case of any issues. -ilya On Jan 21, 2013, at 2:48 PM, paul sorenson wrote: > When I run the attached file everything seems to be decoded ok but the decoder throws a SubstrateUnderrunError apparently encountering a spurious "00" on the end of the substrate. It only manifested when I added the OriginHost field. > > Not sure if it is a bug in my specification/code or elsewhere. Any help would be appreciated. > > Stacktrace: > > ...remaining substrate is: > 00000: 00 00 00 > DBG: decoder left scope CDR.OriginHost, call completed > DBG: codec ChoiceDecoder yields type OriginHost, value: > OriginHost: > domainName=my.domain > > ...remaining substrate is: > 00000: 00 > DBG: decoder left scope CDR, call completed > DBG: decoder called at scope CDR with state 0, working with up to 1 octets of substrate: > 00000: 00 > DBG: tag decoded into TagSet(Tag(tagClass=0, tagFormat=0, tagId=0)), decoding length > ERROR:root:decode failure. > Traceback (most recent call last): > File "foo.py", line 136, in main > asn1 = decoder.decode(ber, asn1Spec = spec) > File "/home/pms/src/C-IMS/src/pyasn1/codec/ber/decoder.py", line 752, in __call__ > stGetValueDecoder, self, substrateFun > File "/home/pms/src/C-IMS/src/pyasn1/codec/ber/decoder.py", line 329, in indefLenValueDecoder > component, substrate = decodeFun(substrate, asn1Spec) > File "/home/pms/src/C-IMS/src/pyasn1/codec/ber/decoder.py", line 610, in __call__ > 'Short octet stream on length decoding' > SubstrateUnderrunError: Short octet stream on length decoding > > > Code: > > import sys > import logging > from pyasn1.type import tag, char, univ, namedtype, namedval, constraint > from pyasn1.codec.ber import encoder, decoder > from pyasn1 import debug > > > RECORD_TYPE = 83 > > class iPBinV4Address(univ.OctetString): > subtypeSpec = constraint.ValueSizeConstraint(4, 4) > > > class iPBinV6Address(univ.OctetString): > subtypeSpec = constraint.ValueSizeConstraint(16, 16) > > > class IPBinaryAddress(univ.Choice): > componentType = namedtype.NamedTypes( > namedtype.NamedType('iPBinV4Address', > iPBinV4Address().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 0))), > namedtype.NamedType('iPBinV6Address', > iPBinV6Address().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 1)))) > > > class iPTextV4Address(char.IA5String): > subtypeSpec = constraint.ValueSizeConstraint(7, 15) > > > class iPTextV6Address(char.IA5String): > subtypeSpec = constraint.ValueSizeConstraint(15, 45) > > > class IPTextRepresentedAddress(univ.Choice): > componentType = namedtype.NamedTypes( > namedtype.NamedType('iPTextV4Address', > iPTextV4Address().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 3))), > namedtype.NamedType('iPTextV6Address', > iPTextV6Address().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 4)))) > > > class IPAddress(univ.Choice): > componentType = namedtype.NamedTypes( > namedtype.NamedType('iPBinaryddress', > IPBinaryAddress().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 3))), > namedtype.NamedType('iPTextRepresentedAddress', > IPTextRepresentedAddress().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 4)))) > > > class OriginHost(univ.Choice): > tagSet = univ.Choice.tagSet.tagImplicitly( > tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 4)) > > componentType = namedtype.NamedTypes( > namedtype.NamedType('iPAddress', IPAddress().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 0))), > namedtype.NamedType('domainName', char.GraphicString().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 1)))) > > > class CDR(univ.Set): > > tagSet = univ.Sequence.tagSet.tagImplicitly( > tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, RECORD_TYPE)) > > componentType = namedtype.NamedTypes( > > namedtype.NamedType('recordType', > univ.Integer().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 0))), > > namedtype.NamedType('sipMethod', > char.GraphicString().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 2))), > > namedtype.NamedType('roleOfNode', > univ.Enumerated().subtype( > implicitTag = tag.Tag(tag.tagClassContext, > tag.tagFormatSimple, 3), > namedValues = namedval.NamedValues( > ('originating', 0), > ('terminating', 1), > ('proxy', 2), > ('b2bua', 3) > ), > subtypeSpec = univ.Enumerated.subtypeSpec + > constraint.SingleValueConstraint(0, 1, 2, 3))), > > namedtype.NamedType('originHost', OriginHost()) > ) > > > def init(cdr): > ''' > Initialise fields of a CDR object. > > :param cdr: CDR instance. > > :return: CDR instance with fields initialised. > ''' > cdr.setComponentByName('recordType', RECORD_TYPE) > cdr.setComponentByName('sipMethod', 'BYE') > cdr.setComponentByName('roleOfNode', 'terminating') > originHost = OriginHost() > originHost.setComponentByName('domainName', 'my.domain') > cdr.setComponentByName('originHost', originHost) > return cdr > > > def main(): > debug.setLogger(debug.Debug('all')) > cdr = CDR() > asn1 = init(cdr) > ber = encoder.encode(asn1, defMode = False) > spec = CDR() > try: > asn1 = decoder.decode(ber, asn1Spec = spec) > except: > logging.exception('decode failure.') > > if __name__ == '__main__': > main() > > > ------------------------------------------------------------------------------ > Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, > MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current > with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft > MVPs and experts. SALE $99.99 this month only -- learn more at: > http://p.sf.net/sfu/learnmore_122412_______________________________________________ > pyasn1-users mailing list > pya...@li... > https://lists.sourceforge.net/lists/listinfo/pyasn1-users |