From 0c86ef06d6da70ed666708da2d7a879deb1fab82dc251da69b445d8de0a06dea Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Chv=C3=A1tal?= <tchvatal@suse.com>
Date: Thu, 11 Feb 2016 15:20:10 +0000
Subject: [PATCH] - Add patches for bnc#814241 upstream#1616   *
 arrays-doubling.patch   * scan-pseudo-attribute.patch

OBS-URL: https://build.opensuse.org/package/show/Java:packages/xerces-j2?expand=0&rev=43
---
 arrays-doubling.patch       | 48 +++++++++++++++++++++++++++++++++++++
 scan-pseudo-attribute.patch | 47 ++++++++++++++++++++++++++++++++++++
 xerces-j2.changes           |  7 ++++++
 xerces-j2.spec              | 11 +++++++--
 4 files changed, 111 insertions(+), 2 deletions(-)
 create mode 100644 arrays-doubling.patch
 create mode 100644 scan-pseudo-attribute.patch

diff --git a/arrays-doubling.patch b/arrays-doubling.patch
new file mode 100644
index 0000000..9f9536a
--- /dev/null
+++ b/arrays-doubling.patch
@@ -0,0 +1,48 @@
+--- xerces/src/org/apache/xerces/util/XMLStringBuffer.java	2006/09/18 05:12:57	447241
++++ xerces/src/org/apache/xerces/util/XMLStringBuffer.java	2013/07/25 18:13:37
+@@ -111,12 +111,13 @@ 
+      */
+     public void append(char c) {
+         if (this.length + 1 > this.ch.length) {
+-                    int newLength = this.ch.length*2;
+-                    if (newLength < this.ch.length + DEFAULT_SIZE)
+-                        newLength = this.ch.length + DEFAULT_SIZE;
+-                    char[] newch = new char[newLength];
+-                    System.arraycopy(this.ch, 0, newch, 0, this.length);
+-                    this.ch = newch;
++            int newLength = this.ch.length * 2;
++            if (newLength < this.ch.length + DEFAULT_SIZE) {
++                newLength = this.ch.length + DEFAULT_SIZE;
++            }
++            char[] newch = new char[newLength];
++            System.arraycopy(this.ch, 0, newch, 0, this.length);
++            this.ch = newch;
+         }
+         this.ch[this.length] = c;
+         this.length++;
+@@ -130,9 +131,10 @@ 
+     public void append(String s) {
+         int length = s.length();
+         if (this.length + length > this.ch.length) {
+-            int newLength = this.ch.length*2;
+-            if (newLength < this.length + length + DEFAULT_SIZE)
++            int newLength = this.ch.length * 2;
++            if (newLength < this.length + length + DEFAULT_SIZE) {
+                 newLength = this.ch.length + length + DEFAULT_SIZE;
++            }
+             char[] newch = new char[newLength];            
+             System.arraycopy(this.ch, 0, newch, 0, this.length);
+             this.ch = newch;
+@@ -150,7 +152,11 @@ 
+      */
+     public void append(char[] ch, int offset, int length) {
+         if (this.length + length > this.ch.length) {
+-            char[] newch = new char[this.ch.length + length + DEFAULT_SIZE];
++            int newLength = this.ch.length * 2;
++            if (newLength < this.length + length + DEFAULT_SIZE) {
++                newLength = this.ch.length + length + DEFAULT_SIZE;
++            }
++            char[] newch = new char[newLength];
+             System.arraycopy(this.ch, 0, newch, 0, this.length);
+             this.ch = newch;
+         }
diff --git a/scan-pseudo-attribute.patch b/scan-pseudo-attribute.patch
new file mode 100644
index 0000000..3996a30
--- /dev/null
+++ b/scan-pseudo-attribute.patch
@@ -0,0 +1,47 @@
+--- xerces/src/org/apache/xerces/impl/XMLScanner.java	2013/07/03 18:25:06	1499505
++++ xerces/src/org/apache/xerces/impl/XMLScanner.java	2013/07/03 18:29:43
+@@ -542,7 +542,7 @@ 
+         // document is until we scan the encoding declaration
+         // you cannot reliably read any characters outside
+         // of the ASCII range here. -- mrglavas
+-        String name = fEntityScanner.scanName();
++        String name = scanPseudoAttributeName();
+         XMLEntityManager.print(fEntityManager.getCurrentEntity());
+         if (name == null) {
+             reportFatalError("PseudoAttrNameExpected", null);
+@@ -599,6 +599,35 @@ 
+     } // scanPseudoAttribute(XMLString):String
+     
+     /**
++     * Scans the name of a pseudo attribute. The only legal names
++     * in XML 1.0/1.1 documents are 'version', 'encoding' and 'standalone'.
++     * 
++     * @return the name of the pseudo attribute or <code>null</code>
++     * if a legal pseudo attribute name could not be scanned.
++     */
++    private String scanPseudoAttributeName() throws IOException, XNIException {
++        final int ch = fEntityScanner.peekChar();
++        switch (ch) {
++            case 'v':
++                if (fEntityScanner.skipString(fVersionSymbol)) {
++                    return fVersionSymbol;
++                }
++                break;
++            case 'e':
++                if (fEntityScanner.skipString(fEncodingSymbol)) {
++                    return fEncodingSymbol;
++                }
++                break;
++            case 's':
++                if (fEntityScanner.skipString(fStandaloneSymbol)) {
++                    return fStandaloneSymbol;
++                }
++                break;
++        }
++        return null;
++    } // scanPseudoAttributeName()
++    
++    /**
+      * Scans a processing instruction.
+      * <p>
+      * <pre>
diff --git a/xerces-j2.changes b/xerces-j2.changes
index 4d6f535..e315a6e 100644
--- a/xerces-j2.changes
+++ b/xerces-j2.changes
@@ -1,3 +1,10 @@
+-------------------------------------------------------------------
+Thu Feb 11 15:12:31 UTC 2016 - tchvatal@suse.com
+
+- Add patches for bnc#814241 upstream#1616
+  * arrays-doubling.patch
+  * scan-pseudo-attribute.patch
+
 -------------------------------------------------------------------
 Mon Jul 21 09:58:48 UTC 2014 - tchvatal@suse.com
 
diff --git a/xerces-j2.spec b/xerces-j2.spec
index 187fc2a..af6ec90 100644
--- a/xerces-j2.spec
+++ b/xerces-j2.spec
@@ -1,7 +1,7 @@
 #
 # spec file for package xerces-j2
 #
-# Copyright (c) 2014 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2016 SUSE LINUX GmbH, Nuernberg, Germany.
 #
 # All modifications and additions to the file contributed by third parties
 # remain the property of their copyright owners, unless otherwise agreed
@@ -30,12 +30,15 @@ Source2:        %{name}-version.sh
 Source3:        %{name}-version.1
 Source4:        %{name}-constants.sh
 Source5:        %{name}-constants.1
+Patch0:         arrays-doubling.patch
+Patch1:         scan-pseudo-attribute.patch
+BuildRequires:  dos2unix
 # some build requirements removed to enable jpackage bootstrap. this is
 # the first package built, and we use the libraries in the tools subdir
 # for it.
-BuildRequires:  java-1_5_0-gcj-compat-devel
 #!BuildIgnore:  java-1_6_0-openjdk java-1_6_0-openjdk-devel
 #!BuildIgnore:  antlr antlr-java
+BuildRequires:  java-1_5_0-gcj-compat-devel
 BuildRequires:  javapackages-tools
 BuildRequires:  unzip
 Requires(post): update-alternatives
@@ -160,6 +163,10 @@ This package contains the APIs subproject of xml-commons.
 %setup -q -T -a 1 -D -n xerces-%{cvs_version}
 %setup -q -T -D -n xerces-%{cvs_version}
 
+find -type f -print |xargs -i dos2unix {}
+%patch0 -p1
+%patch1 -p1
+
 echo 'javac.target=1.5' > build.properties
 echo 'javac.source=1.5' >> build.properties