diff --git a/CVE-2025-6069-quad-complex-HTMLParser.patch b/CVE-2025-6069-quad-complex-HTMLParser.patch
new file mode 100644
index 0000000..70eb744
--- /dev/null
+++ b/CVE-2025-6069-quad-complex-HTMLParser.patch
@@ -0,0 +1,237 @@
+From 1d53c3e7343bddb064182e02c21b13be9b63390f Mon Sep 17 00:00:00 2001
+From: Serhiy Storchaka
+Date: Fri, 13 Jun 2025 19:57:48 +0300
+Subject: [PATCH] [3.12] gh-135462: Fix quadratic complexity in processing
+ special input in HTMLParser (GH-135464)
+
+End-of-file errors are now handled according to the HTML5 specs --
+comments and declarations are automatically closed, tags are ignored.
+(cherry picked from commit 6eb6c5dbfb528bd07d77b60fd71fd05d81d45c41)
+
+Co-authored-by: Serhiy Storchaka
+---
+ Lib/html/parser.py | 41 +++-
+ Lib/test/test_htmlparser.py | 94 ++++++++--
+ Misc/NEWS.d/next/Security/2025-06-13-15-55-22.gh-issue-135462.KBeJpc.rst | 4
+ 3 files changed, 116 insertions(+), 23 deletions(-)
+ create mode 100644 Misc/NEWS.d/next/Security/2025-06-13-15-55-22.gh-issue-135462.KBeJpc.rst
+
+Index: Python-3.12.11/Lib/html/parser.py
+===================================================================
+--- Python-3.12.11.orig/Lib/html/parser.py 2025-07-02 17:09:00.904899297 +0200
++++ Python-3.12.11/Lib/html/parser.py 2025-07-02 17:09:12.496469955 +0200
+@@ -25,6 +25,7 @@
+ charref = re.compile('(?:[0-9]+|[xX][0-9a-fA-F]+)[^0-9a-fA-F]')
+
+ starttagopen = re.compile('<[a-zA-Z]')
++endtagopen = re.compile('[a-zA-Z]')
+ piclose = re.compile('>')
+ commentclose = re.compile(r'--\s*>')
+ # Note:
+@@ -177,7 +178,7 @@
+ k = self.parse_pi(i)
+ elif startswith("', i + 1)
+- if k < 0:
+- k = rawdata.find('<', i + 1)
+- if k < 0:
+- k = i + 1
++ if starttagopen.match(rawdata, i): # < + letter
++ pass
++ elif startswith("", i):
++ if i + 2 == n:
++ self.handle_data("")
++ elif endtagopen.match(rawdata, i): # + letter
++ pass
++ else:
++ # bogus comment
++ self.handle_comment(rawdata[i+2:])
++ elif startswith("', [('comment', '-!>')]),
++ (''
+ ''
+ ''
+ '')
+ expected = [
++ ('comment', 'ELEMENT br EMPTY'),
+ ('comment', ' not really a comment '),
+ ('comment', ' not a comment either --'),
+ ('comment', ' -- close enough --'),
+@@ -600,6 +650,26 @@
+ ('endtag', 'a'), ('data', ' bar & baz')]
+ )
+
++ @support.requires_resource('cpu')
++ def test_eof_no_quadratic_complexity(self):
++ # Each of these examples used to take about an hour.
++ # Now they take a fraction of a second.
++ def check(source):
++ parser = html.parser.HTMLParser()
++ parser.feed(source)
++ parser.close()
++ n = 120_000
++ check("
+Date: Tue, 1 Jul 2025 12:13:28 +0200
+Subject: [PATCH] Doc: Generate ids for audit_events using docname
+
+This patch generates ids for audit_events using the docname so the id is
+not global but depend on the source file. This make the doc build
+reproducible with multiple cores because it doesn't which file is parsed
+first, the id for audit_events will always be consistent independently
+of what file is parsed first.
+
+https://github.com/python/cpython/issues/130979
+---
+ Doc/tools/extensions/audit_events.py | 11 ++++++++---
+ 1 file changed, 8 insertions(+), 3 deletions(-)
+
+Index: Python-3.12.11/Doc/tools/extensions/audit_events.py
+===================================================================
+--- Python-3.12.11.orig/Doc/tools/extensions/audit_events.py 2025-07-02 16:10:55.447792590 +0200
++++ Python-3.12.11/Doc/tools/extensions/audit_events.py 2025-07-02 16:12:00.124596479 +0200
+@@ -64,8 +64,13 @@
+ logger.warning(msg)
+ return
+
+- def id_for(self, name) -> str:
+- source_count = len(self.sources.get(name, ()))
++ def _source_count(self, name, docname) -> int:
++ """Count the event name in the same source"""
++ sources = self.sources.get(name, set())
++ return len([s for s, t in sources if s == docname])
++
++ def id_for(self, name, docname) -> str:
++ source_count = self._source_count(name, docname)
+ name_clean = re.sub(r"\W", "_", name)
+ return f"audit_event_{name_clean}_{source_count}"
+
+@@ -140,7 +145,7 @@
+ except (IndexError, TypeError):
+ target = None
+ if not target:
+- target = self.env.audit_events.id_for(name)
++ target = self.env.audit_events.id_for(name, self.env.docname)
+ ids.append(target)
+ self.env.audit_events.add_event(name, args, (self.env.docname, target))
+
diff --git a/python312.changes b/python312.changes
index 4173fd7..3d0a360 100644
--- a/python312.changes
+++ b/python312.changes
@@ -1,3 +1,24 @@
+-------------------------------------------------------------------
+Wed Jul 2 14:47:20 UTC 2025 - Matej Cepl
+
+- Add CVE-2025-6069-quad-complex-HTMLParser.patch to avoid worst
+ case quadratic complexity when processing certain crafted
+ malformed inputs with HTMLParser (CVE-2025-6069, bsc#1244705).
+
+-------------------------------------------------------------------
+Wed Jul 2 13:14:28 UTC 2025 - Matej Cepl
+
+- Add bsc1243155-sphinx-non-determinism.patch (bsc#1243155) to
+ generate ids for audit_events using docname (reproducible
+ builds).
+
+-------------------------------------------------------------------
+Tue Jul 1 08:19:52 UTC 2025 - Daniel Garcia
+
+- Use one core to build doc. This will make sphinx doc build
+ reproducible.
+ bsc#1243155
+
-------------------------------------------------------------------
Mon Jun 9 19:41:07 UTC 2025 - Matej Cepl
diff --git a/python312.spec b/python312.spec
index 17fba23..5caacd0 100644
--- a/python312.spec
+++ b/python312.spec
@@ -184,6 +184,12 @@ Patch41: docs-docutils_014-Sphinx_420.patch
# PATCH-FIX-SLE doc-py38-to-py36.patch mcepl@suse.com
# Make documentation extensions working with Python 3.6
Patch44: doc-py38-to-py36.patch
+# PATCH-FIX-UPSTREAM bsc1243155-sphinx-non-determinism.patch bsc#1243155 mcepl@suse.com
+# Doc: Generate ids for audit_events using docname
+Patch45: bsc1243155-sphinx-non-determinism.patch
+# PATCH-FIX-UPSTREAM CVE-2025-6069-quad-complex-HTMLParser.patch bsc#1244705 mcepl@suse.com
+# avoid quadratic complexity when processing malformed inputs with HTMLParser
+Patch46: CVE-2025-6069-quad-complex-HTMLParser.patch
BuildRequires: autoconf-archive
BuildRequires: automake
BuildRequires: fdupes
@@ -486,7 +492,7 @@ TODAY_DATE=`date -r %{SOURCE0} "+%%B %%d, %%Y"`
cd Doc
sed -i "s/^today = .*/today = '$TODAY_DATE'/" conf.py
-%make_build -j1 html
+%make_build -j1 JOBS=1 html
# Build also devhelp files
sphinx-build -a -b devhelp . build/devhelp