CreateFromDocument crashes using binary types with zero-length data #51

evanunderscore opened this Issue Feb 29, 2016 · 2 comments


None yet

2 participants


Sample schema (this also happens with base64Binary):

<xs:schema xmlns:xs="">
    <xs:element name="test">
                <xs:element name="bin" type="xs:hexBinary"/>

Compile bindings:

pyxbgen test.xsd -m test_binding

Read document:

import test_binding

The following XML samples work:

<test><bin> </bin></test>

The following don't:



Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "", line 62, in CreateFromDocument
  File "C:\Python27\lib\xml\sax\", line 110, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "C:\Python27\lib\xml\sax\", line 123, in parse
  File "C:\Python27\lib\xml\sax\", line 213, in feed
    self._parser.Parse(data, isFinal)
  File "C:\Python27\lib\xml\sax\", line 365, in end_element_ns
    self._cont_handler.endElementNS(pair, None)
  File "pyxb\binding\", line 388, in endElementNS
    binding_object = this_state.endBindingElement()
  File "pyxb\binding\", line 226, in endBindingElement
    self.__constructElement(self.__delayedConstructor, self.__attributes, args)
  File "pyxb\binding\", line 116, in __constructElement
    self.__bindingInstance = new_object_factory(*content, **kw)
  File "pyxb\binding\", line 1600, in __call__
    rv = self.typeDefinition().Factory(*args, **kw)
  File "pyxb\binding\", line 305, in Factory
    rv = cls._DynamicCreate(*args, **kw)
  File "pyxb\binding\", line 677, in _DynamicCreate
    return ctor(*args, **kw)
  File "pyxb\binding\", line 873, in __new__
    args = cls._ConvertArguments(args, kw)
  File "pyxb\binding\", line 851, in _ConvertArguments
    return cls._ConvertArguments_vx(args, kw)
  File "pyxb\binding\", line 810, in _ConvertArguments_vx
    xmlt = args[0]
IndexError: tuple index out of range

It looks like the problem is that the SAX handler's ContentHandler.characters doesn't get called with the empty string for an empty element so args is ending up empty. The simplest fix is to handle that in hexBinary and base64Binary but I really have no idea how much more of the code is affected by this.

@pabigot pabigot added a commit that closed this issue Feb 29, 2016
@pabigot fix #51: binary type factory error with empty content
All other types appear to check for content before attempting to convert
it from lexical to value space.
@pabigot pabigot closed this in 9fced97 Feb 29, 2016
pabigot commented Feb 29, 2016

Thanks for the input. From what I can tell the issue was limited to these types.



@pabigot pabigot added this to the PyXB 1.2.5 milestone Sep 18, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment