From a45a9428f5c0e92832c4bd1f570228fbb0f17422 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jurko=20Gospodneti=C4=87?= Date: Sun, 26 Jul 2015 15:05:08 +0200 Subject: [PATCH] fix looking for a type in an XSD with recursive type definition Fixes an infinite recursion bug encountered when looking for an XSD type in an XSD schema that does not contain it but itself defines a type referencing a recursively defined type from an imported XSD schema. Kudos to Kevin Pors (krpors on BitBucket) for detecting, analysing & reporting the issue, plus preparing a working quick-fix. Updated README.rst. --- README.rst | 39 +++++++++++++++++++++++++++++++++++++++ suds/xsd/sxbase.py | 22 +++++++++++++++++----- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index 5739465..b47447f 100644 --- a/README.rst +++ b/README.rst @@ -164,6 +164,13 @@ version 0.7 (development) * Fixed loading recursive WSDL imports. * Fixed loading recursive XSD imports/includes. +* Fixed an infinite recursion bug encountered when looking for an XSD type in an + XSD schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. + + * Kudos to Kevin Pors (`krpors` on BitBucket) for detecting, analysing & + reporting the issue, plus preparing a working quick-fix. + * Made ``suds`` no longer eat up, log & ignore exceptions raised from registered user plugins (detected & reported by Ezequiel Ruiz & Bouke Haarsma, patch & test case contributed by Bouke Haarsma). @@ -543,6 +550,9 @@ version 0.6 (2014-01-24) considered unqualified. * Loading recursive WSDL imports is broken. * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. version 0.5 (2013-11-25) ------------------------ @@ -610,6 +620,9 @@ version 0.5 (2013-11-25) considered unqualified. * Loading recursive WSDL imports is broken. * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. version 0.4.1 jurko 5 (2013-11-11) ---------------------------------- @@ -766,6 +779,9 @@ version 0.4.1 jurko 5 (2013-11-11) considered unqualified. * Loading recursive WSDL imports is broken. * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. version 0.4.1 jurko 4 (2012-04-17) ---------------------------------- @@ -808,6 +824,9 @@ version 0.4.1 jurko 4 (2012-04-17) considered unqualified. * Loading recursive WSDL imports is broken. * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. version 0.4.1 jurko 3 (2011-12-26) ---------------------------------- @@ -851,6 +870,9 @@ version 0.4.1 jurko 3 (2011-12-26) considered unqualified. * Loading recursive WSDL imports is broken. * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. version 0.4.1 jurko 2 (2011-12-24) ---------------------------------- @@ -893,6 +915,9 @@ version 0.4.1 jurko 2 (2011-12-24) considered unqualified. * Loading recursive WSDL imports is broken. * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. version 0.4.1 jurko 1 (2011-12-24) ---------------------------------- @@ -979,6 +1004,9 @@ version 0.4.1 jurko 1 (2011-12-24) considered unqualified. * Loading recursive WSDL imports is broken. * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. Original suds library release notes @@ -989,7 +1017,18 @@ Original suds library release notes * * Known defects. + * SOAP request parameter XML elements constructed in incorrect namespaces in + case they have been defined by XSD schema elements referencing XSD schema + elements with a different target namespace. * Security issue CVE-2013-2217 - using fixed default cache location. + * Incorrect referencing XSD element's ``form`` attribute value handling - + global XSD elements (i.e. top-level + reference elements) sometimes + considered unqualified. + * Loading recursive WSDL imports is broken. + * Loading recursive XSD imports/includes is broken. + * Infinite recursion bug encountered when looking for an XSD type in an XSD + schema that does not contain it but itself defines a type referencing a + recursively defined type from an imported XSD schema. **version 0.4 (2010-09-08)** diff --git a/suds/xsd/sxbase.py b/suds/xsd/sxbase.py index aed605f..95e98c5 100644 --- a/suds/xsd/sxbase.py +++ b/suds/xsd/sxbase.py @@ -339,14 +339,21 @@ class SchemaObject(UnicodeMixin): """Get whether the object has I{mixed} content.""" return False - def find(self, qref, classes=()): + def find(self, qref, classes=[], ignore=None): """ - Find a referenced type in self or children. + Find a referenced type in self or children. Return None if not found. + + Qualified references for all schema objects checked in this search will + be added to the set of ignored qualified references to avoid the find + operation going into an infinite loop in case of recursively defined + structures. @param qref: A qualified reference. @type qref: qref - @param classes: A list of classes used to qualify the match. - @type classes: [I{class},...] + @param classes: A collection of classes used to qualify the match. + @type classes: Collection(I{class},...), e.g. [I(class),...] + @param ignore: A set of qualified references to ignore in this search. + @type ignore: {qref,...} @return: The referenced type. @rtype: L{SchemaObject} @see: L{qualify()} @@ -354,10 +361,15 @@ class SchemaObject(UnicodeMixin): """ if not len(classes): classes = (self.__class__,) + if ignore is None: + ignore = set() + if self.qname in ignore: + return + ignore.add(self.qname) if self.qname == qref and self.__class__ in classes: return self for c in self.rawchildren: - p = c.find(qref, classes) + p = c.find(qref, classes, ignore=ignore) if p is not None: return p