Uploaded image for project: 'Xerces-C++'
  1. Xerces-C++
  2. XERCESC-1834

Memory leak using SAX2 with XML Schema validation

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 3.0.0
    • 3.0.1, 3.1.0
    • None
    • MS Windows XP SP3, VS 2005

    Description

      XML schema with certain elements included causes 4 memory leaks per invocation (every XML file import invokes parsing twice - once to ensure it validates completely, second to import if validation successful).

      SAX2 interface being used with the following features & properties:

      // Set non-default features
      pSAX2Parser->setFeature(XMLUni::fgSAX2CoreNameSpacePrefixes, true);
      pSAX2Parser->setFeature(XMLUni::fgSAX2CoreValidation, true);
      pSAX2Parser->setFeature(XMLUni::fgXercesDynamic, false);
      pSAX2Parser->setFeature(XMLUni::fgXercesSchemaFullChecking, true);
      pSAX2Parser->setFeature(XMLUni::fgXercesLoadExternalDTD, false);
      pSAX2Parser->setFeature(XMLUni::fgXercesSkipDTDValidation, true);

      // Set properties
      pSAX2Parser->setProperty(XMLUni::fgXercesSchemaExternalNoNameSpaceSchemaLocation,
      (void *)strXSDFileName.c_str());
      pSAX2Parser->setProperty(XMLUni::fgXercesScannerName,
      (void *)XMLUni::fgSGXMLScanner);
      pSAX2Parser->setInputBufferSize(4096);

      In the following XML Schema, the problem exists if the element "history_entries" (lines 202-216 inclusive) is present in the schema. A sample XML file is also present (couldn't find a way to attach files).

      From debug output:

      {21570}

      normal block at 0x0137ED00, 22 bytes long.
      Data: < > 12 00 00 00 00 00 CD CD CD CD CD CD CD CD CD CD

      {21569}

      normal block at 0x01382390, 48 bytes long.
      Data: <, h i s t o r > 2C 00 00 00 68 00 69 00 73 00 74 00 6F 00 72 00

      {21568}

      normal block at 0x013800D0, 48 bytes long.
      Data: <, z > 2C 00 00 00 E0 D8 12 00 CD CD CD CD 14 07 7A 00

      {21567}

      normal block at 0x0137FEB0, 52 bytes long.
      Data: <0 H-z > 30 00 00 00 E0 D8 12 00 CD CD CD CD 48 2D 7A 00

      {13007}

      normal block at 0x013A0950, 22 bytes long.
      Data: < > 12 00 00 00 00 00 CD CD CD CD CD CD CD CD CD CD

      {13006}

      normal block at 0x0139FF50, 48 bytes long.
      Data: <, h i s t o r > 2C 00 00 00 68 00 69 00 73 00 74 00 6F 00 72 00

      {13005}

      normal block at 0x0139F8D0, 48 bytes long.
      Data: <, z > 2C 00 00 00 E0 D8 12 00 CD CD CD CD 14 07 7A 00

      {13004}

      normal block at 0x013B8718, 52 bytes long.
      Data: <0 H-z > 30 00 00 00 E0 D8 12 00 CD CD CD CD 48 2D 7A 00

      XML Schema:
      --START--
      <?xml version="1.0" encoding="iso-8859-1" standalone="yes"?>
      <xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.15">

      <xs:annotation>
      <xs:documentation xml:lang="en">
      This XML Schema corresponds to V3.15 of Password Safe.
      As each new version is a 'superset' of previous versions, the current version of Password Safe
      will be able to import XML files created by all prior versions.
      However, in V3.13 element 'ltime' has been replaced by 'xtime' for the Password Expiry Time.
      Either is currently allowed, although future updates may remove the 'ltime' choice and therefore
      errors will be issued during XML Import if the 'ltime' element is present in the XML file.
      </xs:documentation>
      </xs:annotation>

      <!-- Special types to allow easier processing of Password Safe data -->
      <xs:simpleType name="characterType">
      <xs:restriction base="xs:string">
      <xs:length value="1" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="uuidType">
      <xs:restriction base="xs:hexBinary">
      <xs:length value="16" fixed="true" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="stringType">
      <xs:restriction base="xs:string">
      <xs:whiteSpace value="preserve" />
      </xs:restriction>
      </xs:simpleType>

      <xs:complexType name="datetimestampType">
      <xs:sequence>
      <xs:element name="date" type="xs:date" minOccurs="1" maxOccurs="1"/>
      <xs:element name="time" type="xs:time" minOccurs="1" maxOccurs="1"/>
      </xs:sequence>
      </xs:complexType>

      <xs:simpleType name="expirydaysType">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="1" />
      <xs:maxInclusive value="3650" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="fieldType">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="18" />
      <xs:maxExclusive value="255" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="numhashType">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="2048" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="fileuuidType">
      <xs:restriction base="xs:string">
      <xs:pattern value="[0-9a-zA-Z]

      {8}

      -[0-9a-zA-Z]

      {4}-[0-9a-zA-Z]{4}

      -[0-9a-zA-Z]

      {4}

      -[0-9a-zA­Z]

      {12}

      " />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="boolType">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="0" />
      <xs:maxInclusive value="1" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="passwordlengthType">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="4" />
      <xs:maxInclusive value="1024" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="passwordlengthType2">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="0" />
      <xs:maxInclusive value="1024" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="timeoutType">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="1" />
      <xs:maxInclusive value="120" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="displaystatusType">
      <xs:restriction base="xs:string">
      <xs:enumeration value="AllCollapsed" />
      <xs:enumeration value="AllExpanded" />
      <xs:enumeration value="AsPerLastSave" />
      </xs:restriction>
      </xs:simpleType>

      <xs:simpleType name="pwhistoryType">
      <xs:restriction base="xs:integer">
      <xs:minInclusive value="0" />
      <xs:maxInclusive value="255" />
      </xs:restriction>
      </xs:simpleType>
      <!-- End of Special types -->

      <!-- Start of proper Password Safe validation XSD -->
      <xs:element name="passwordsafe">
      <!-- Start Database -->
      <xs:complexType>
      <xs:sequence>
      <!-- Start Database Preferences -->
      <xs:element name="NumberHashIterations" type="numhashType" minOccurs="0" maxOccurs="1" />
      <xs:element name="Preferences" minOccurs="0" maxOccurs="1">
      <xs:complexType>
      <xs:all>
      <!-- Boolean Preferences -->
      <xs:element name="DisplayExpandedAddEditDlg" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="MaintainDateTimeStamps" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseDigits" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseEasyVision" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseHexDigits" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseLowercase" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseSymbols" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseUppercase" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWMakePronounceable" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="SaveImmediately" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="SavePasswordHistory" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="ShowNotesDefault" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="ShowPWDefault" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="ShowPasswordInTree" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="ShowUsernameInTree" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="SortAscending" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="UseDefaultUser" type="boolType" minOccurs="0" maxOccurs="1" />

      <!-- Integer Preferences -->
      <xs:element name="PWDefaultLength" type="passwordlengthType" minOccurs="0" maxOccurs="1" />
      <xs:element name="IdleTimeout" type="timeoutType" minOccurs="0" maxOccurs="1" />
      <xs:element name="TreeDisplayStatusAtOpen" type="displaystatusType" minOccurs="0" maxOccurs="1" />
      <xs:element name="NumPWHistoryDefault" type="pwhistoryType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWDigitMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWLowercaseMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWSymbolMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUppercaseMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />

      <!-- String Preferences -->
      <xs:element name="DefaultUsername" type="stringType" minOccurs="0" maxOccurs="1" />
      <xs:element name="DefaultAutotypeString" type="stringType" minOccurs="0" maxOccurs="1" />
      </xs:all>
      </xs:complexType>
      <!-- End Database Preferences -->
      </xs:element>
      <xs:element name="unknownheaderfields" minOccurs="0" maxOccurs="1">
      <!-- Start Database Unknown Fields -->
      <xs:complexType>
      <xs:sequence>
      <xs:element name="field" minOccurs="0" maxOccurs="unbounded">
      <xs:complexType>
      <xs:simpleContent>
      <xs:extension base="xs:base64Binary">
      <xs:attribute name="ftype" type="fieldType" use="required" />
      </xs:extension>
      </xs:simpleContent>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      <!-- End Database Unknown Fields -->
      </xs:element>
      <xs:element name="entry" minOccurs="0" maxOccurs="unbounded">
      <!-- Start Database Entries -->
      <xs:complexType>
      <xs:all>
      <xs:element name="group" type="stringType" minOccurs="0" maxOccurs="1" />
      <xs:element name="title" type="stringType" minOccurs="1" />
      <xs:element name="username" type="stringType" minOccurs="0" maxOccurs="1" />
      <xs:element name="password" type="stringType" minOccurs="1" />
      <xs:element name="url" type="stringType" minOccurs="0" maxOccurs="1" />
      <xs:element name="autotype" type="stringType" minOccurs="0" maxOccurs="1" />
      <xs:element name="notes" type="stringType" minOccurs="0" maxOccurs="1" />
      <xs:element name="uuid" type="uuidType" minOccurs="0" maxOccurs="1" />
      <xs:element name="ctime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
      <xs:element name="atime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
      <!-- ltime is depreciated and replaced by xtime
      If both present, xtime values take precedence -->
      <xs:element name="ltime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
      <xs:element name="xtime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
      <xs:element name="xtime_interval" type="expirydaysType" minOccurs="0" maxOccurs="1" />
      <xs:element name="pmtime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
      <xs:element name="rmtime" type="datetimestampType" minOccurs="0" maxOccurs="1" />
      <xs:element name="pwhistory" minOccurs="0" maxOccurs="1">
      <!-- Start Password History Fields -->
      <xs:complexType>
      <xs:all>
      <xs:element name="status" type="boolType" minOccurs="1" maxOccurs="1" />
      <xs:element name="max" type="pwhistoryType" minOccurs="1" maxOccurs="1" />
      <xs:element name="num" type="pwhistoryType" minOccurs="1" maxOccurs="1" />
      <xs:element name="history_entries" minOccurs="0" maxOccurs="1">
      <xs:complexType>
      <xs:sequence>
      <xs:element name="history_entry" minOccurs="0" maxOccurs="255">
      <xs:complexType>
      <xs:all>
      <xs:element name="changed" type="datetimestampType" minOccurs="1" maxOccurs="1" />
      <xs:element name="oldpassword" type="stringType" minOccurs="1" maxOccurs="1" />
      </xs:all>
      <xs:attribute name="num" type="xs:integer" use="optional" />
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      </xs:element>
      </xs:all>
      </xs:complexType>
      <!-- End Password History Fields -->
      </xs:element>
      <xs:element name="PasswordPolicy" minOccurs="0" maxOccurs="1">
      <!-- Start Password Policy Fields -->
      <xs:complexType>
      <xs:all>
      <xs:element name="PWLength" type="passwordlengthType" minOccurs="1" />
      <xs:element name="PWUseDigits" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseEasyVision" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseHexDigits" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseLowercase" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseSymbols" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUseUppercase" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWMakePronounceable" type="boolType" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWLowercaseMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWUppercaseMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWDigitMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />
      <xs:element name="PWSymbolMinLength" type="passwordlengthType2" minOccurs="0" maxOccurs="1" />
      </xs:all>
      </xs:complexType>
      <!-- End Password Policy Fields -->
      </xs:element>
      <xs:element name="unknownrecordfields" minOccurs="0" maxOccurs="1">
      <!-- Start Unknown Record Fields -->
      <xs:complexType>
      <xs:sequence>
      <xs:element name="field" minOccurs="0" maxOccurs="unbounded">
      <xs:complexType>
      <xs:simpleContent>
      <xs:extension base="xs:base64Binary">
      <xs:attribute name="ftype" type="fieldType" use="required" />
      </xs:extension>
      </xs:simpleContent>
      </xs:complexType>
      </xs:element>
      </xs:sequence>
      </xs:complexType>
      <!-- End Unknown Record Fields -->
      </xs:element>
      </xs:all>
      <xs:attribute name="id" type="xs:integer" use="optional" />
      <xs:attribute name="normal" type="xs:boolean" use="optional" />
      </xs:complexType>
      <!-- End Database Entries -->
      </xs:element>
      </xs:sequence>
      <!-- Start Database Attributes -->
      <xs:attribute name="delimiter" type="characterType" use="required" />
      <xs:attribute name="Database" type="stringType" use="optional" />
      <xs:attribute name="ExportTimeStamp" type="xs:dateTime" use="optional" />
      <xs:attribute name="FromDatabaseFormat" type="stringType" use="optional" />
      <xs:attribute name="WhatSaved" type="stringType" use="optional" />
      <xs:attribute name="WhoSaved" type="stringType" use="optional" />
      <xs:attribute name="WhenLastSaved" type="xs:dateTime" use="optional" />
      <xs:attribute name="Database_uuid" type="fileuuidType" use="optional" />
      <!-- End Database Attributes -->
      </xs:complexType>
      <!-- End Database -->
      </xs:element>
      </xs:schema>
      <!-- End of proper Password Safe validation XSD -->
      --END--

      Sample XML FIle:
      --START--
      <?xml version="1.0" encoding="UTF-8"?>
      <?xml-stylesheet type="text/xsl" href="pwsafe.xsl"?>

      <passwordsafe
      delimiter="»"
      Database="Sample123.psafe3"
      ExportTimeStamp="2008-10-18T09:13:49"
      FromDatabaseFormat="3.05"
      WhoSaved="David on KELVIN-HOME"
      WhatSaved="Password Safe V3.14"
      WhenLastSaved="2008-10-06T20:23:57"
      Database_uuid="5b9becc7-ab52-4ccc-9c16-0b24befcdddc"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:noNamespaceSchemaLocation="pwsafe.xsd">

      <Preferences>
      <ShowPWDefault>1</ShowPWDefault>
      <UseDefaultUser>1</UseDefaultUser>
      <SaveImmediately>0</SaveImmediately>
      <SavePasswordHistory>1</SavePasswordHistory>
      <ShowNotesDefault>1</ShowNotesDefault>
      <PWMakePronounceable>1</PWMakePronounceable>
      <PWDigitMinLength>1</PWDigitMinLength>
      <PWLowercaseMinLength>1</PWLowercaseMinLength>
      <PWSymbolMinLength>1</PWSymbolMinLength>
      <PWUppercaseMinLength>1</PWUppercaseMinLength>
      <DefaultUsername><![CDATA[ronys]]></DefaultUsername>
      </Preferences>

      <entry id="1">
      <title><![CDATA[123]]></title>
      <password><![CDATA[092629645346]]></password>
      <uuid><![CDATA[c5bfa81622914de1ae83baf1361fc34d]]></uuid>
      <ctime>
      <date>2008-06-24</date>
      <time>20:12:53</time>
      </ctime>
      <pmtime>
      <date>2008-09-22</date>
      <time>14:31:02</time>
      </pmtime>
      <rmtime>
      <date>2008-09-22</date>
      <time>14:31:02</time>
      </rmtime>
      <pwhistory>
      <status>1</status>
      <max>4</max>
      <num>4</num>
      <history_entries>
      <history_entry num="1">
      <changed>
      <date>2008-03-31</date>
      <time>16:45:48</time>
      </changed>
      <oldpassword><![CDATA[3xing5kiN]]></oldpassword>
      </history_entry>
      <history_entry num="2">
      <changed>
      <date>2008-03-31</date>
      <time>17:56:20</time>
      </changed>
      <oldpassword><![CDATA[ol0wehaph]]></oldpassword>
      </history_entry>
      <history_entry num="3">
      <changed>
      <date>2008-09-16</date>
      <time>21:17:53</time>
      </changed>
      <oldpassword><![CDATA[stionsurst]]></oldpassword>
      </history_entry>
      <history_entry num="4">
      <changed>
      <date>2008-09-22</date>
      <time>13:44:52</time>
      </changed>
      <oldpassword><![CDATA[ansimpewal]]></oldpassword>
      </history_entry>
      </history_entries>
      </pwhistory>
      <PasswordPolicy>
      <PWLength>12</PWLength>
      <PWUseDigits>1</PWUseDigits>
      <PWDigitMinLength>12</PWDigitMinLength>
      </PasswordPolicy>
      </entry>

      <entry id="2" normal="true">
      <title><![CDATA[a]]></title>
      <username><![CDATA[user]]></username>
      <password><![CDATA[:123:~]]></password>
      <url><![CDATAhttp://cnn.com]></url>
      <notes><Unable to render embedded object: File ([CDATA[nota-bene) not found.»whaddaya whaddaya!]]></notes>
      <uuid><![CDATA[0965bd56fcdc43d8914e28269929baca]]></uuid>
      <ctime>
      <date>2008-02-07</date>
      <time>05:06:02</time>
      </ctime>
      <pmtime>
      <date>2008-10-05</date>
      <time>23:02:23</time>
      </pmtime>
      <rmtime>
      <date>2008-10-05</date>
      <time>23:02:23</time>
      </rmtime>
      <pwhistory>
      <status>1</status>
      <max>4</max>
      <num>0</num>
      </pwhistory>
      </entry>

      </passwordsafe>
      --END--

      Attachments

        1. test.xml
          3 kB
          Boris Kolpackov
        2. test.xsd
          14 kB
          Boris Kolpackov

        Activity

          People

            amassari Alberto Massari
            c-273 David Kelvin
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: