python3: fix CVE-2026-15308
PATCH 1/1 python3: fix CVE-2026-15308
From: Deepak Rathore <[email protected]>
This patch applies the upstream v3.14 backport for CVE-2026-15308. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2]. The individual backported commit link is recorded in the embedded patch header.
[1] https://github.com/python/cpython/commit/07efb08123ba9367a7107325adb9d5626dca1ca9
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-15308
--- .../python/python3/CVE-2026-15308.patch | 116 ++++++++++++++++++ .../recipes-devtools/python/python3_3.14.6.bb | 1 + 2 files changed, 117 insertions(+) create mode 100644 meta/recipes-devtools/python/python3/CVE-2026-15308.patch
meta/recipes-devtools/python/python3/CVE-2026-15308.patch new file +116 -0
@@ -0,0 +1,116 @@ +From 6c0ab3784f4fc153d6a8c82564fd3138343c5b1e Mon Sep 17 00:00:00 2001 +From: "Miss Islington (bot)" + <[email protected]> +Date: Sat, 4 Jul 2026 20:08:05 +0200 +Subject: [PATCH] [3.14] gh-153030: Fix quadratic complexity in incremental + parsing in HTMLParser (GH-153031) (GH-153039) + +When an unterminated construct (e.g. a tag or comment) spanned many +feed() calls, rescanning the growing buffer and concatenating new data +onto it were both quadratic. New data is now accumulated in a list and +only joined and parsed once enough has piled up. + +CVE: CVE-2026-15308 +Upstream-Status: Backport [https://github.com/python/cpython/commit/07efb08123ba9367a7107325adb9d5626dca1ca9] + +Backport Changes: +- Omitted Misc/NEWS.d/next/Security/2026-07-04-17-00-00.gh-issue-153030.RovkP6.rst + because the target source does not carry pending NEWS fragments. + +(cherry picked from commit bcf98ddbc40ec9b3ee87da0124a5660b19b7e606) +Co-authored-by: Serhiy Storchaka <[email protected]> +Co-authored-by: Claude Opus 4.8 <[email protected]> +(cherry picked from commit 07efb08123ba9367a7107325adb9d5626dca1ca9) +Signed-off-by: Deepak Rathore <[email protected]> + +--- + Lib/html/parser.py | 32 ++++++++++++++++++++++++++++++-- + Lib/test/test_htmlparser.py | 20 ++++++++++++++++++++ + 2 files changed, 50 insertions(+), 2 deletions(-) + +diff --git a/Lib/html/parser.py b/Lib/html/parser.py +index 80fb8c3f92..f8ff4bb1fc 100644 +--- a/Lib/html/parser.py ++++ b/Lib/html/parser.py +@@ -157,6 +157,9 @@ class HTMLParser(_markupbase.ParserBase): + self.cdata_elem = None + self._support_cdata = True + self._escapable = True ++ self._pending = [] ++ self._pending_len = 0 ++ self._parse_threshold = 1 + super().reset() + + def feed(self, data): +@@ -165,11 +168,36 @@ class HTMLParser(_markupbase.ParserBase): + Call this as often as you want, with as little or as much text + as you want (may include '\n'). + """ +- self.rawdata = self.rawdata + data +- self.goahead(0) ++ # Accumulate new data in a list and only join and parse it once ++ # enough has piled up. Rescanning an unparsed buffer (e.g. an ++ # unterminated tag) and concatenating onto it on every call would ++ # both be quadratic in the input size. ++ self._pending_len += len(data) ++ if self._pending_len < self._parse_threshold: ++ self._pending.append(data) ++ else: ++ if not self._pending: ++ self.rawdata += data ++ else: ++ self._pending.append(data) ++ self.rawdata += ''.join(self._pending) ++ self._pending.clear() ++ self._pending_len = 0 ++ n = len(self.rawdata) ++ self.goahead(0) ++ if len(self.rawdata) < n: ++ # Some data was parsed; resume on the next call. ++ self._parse_threshold = 1 ++ else: ++ # Nothing was parsed; wait until the buffer doubles. ++ self._parse_threshold = len(self.rawdata) + + def close(self): + """Handle any buffered data.""" ++ if self._pending: ++ self.rawdata += ''.join(self._pending) ++ self._pending.clear() ++ self._pending_len = 0 + self.goahead(1) + + __starttag_text = None +diff --git a/Lib/test/test_htmlparser.py b/Lib/test/test_htmlparser.py +index e4eff1ea17..54bbf11f69 100644 +--- a/Lib/test/test_htmlparser.py ++++ b/Lib/test/test_htmlparser.py +@@ -1031,6 +1031,26 @@ text + check("<![CDATA[" * 9 * n) + check("<!doctype" * 35 * n) + ++ @support.requires_resource('cpu') ++ def test_incremental_no_quadratic_complexity(self): ++ # An unterminated construct fed in many small chunks used to take ++ # quadratic time, both to rescan and to concatenate the buffer. ++ # Now it takes a fraction of a second. ++ def check(prefix, chunk, suffix): ++ parser = html.parser.HTMLParser() ++ parser.feed(prefix) ++ for _ in range(200_000): ++ parser.feed(chunk) ++ parser.feed(suffix) ++ parser.close() ++ chunk = "a" * 64 ++ check("<!--", chunk, "-->") # comment ++ check("<?", chunk, ">") # processing instruction ++ check("<!doctype ", chunk, ">") # doctype ++ check("<![CDATA[", chunk, "]]>") # CDATA section ++ check("<a href='", chunk, "'>") # start tag ++ check("<script>", chunk, "</script>") # RAWTEXT element ++ + + class AttributesTestCase(TestCaseBase): + +-- +2.51.0
meta/recipes-devtools/python/python3_3.14.6.bb +1 -0
@@ -37,6 +37,7 @@ SRC_URI = "http://www.python.org/ftp/python/${PV}/Python-${PV}.tar.xz \ file://0001-prefer-valid-entrypoints.patch \ file://CVE-2026-11940.patch \ file://CVE-2026-11972.patch \ + file://CVE-2026-15308.patch \ " SRC_URI:append:class-native = " \ file://0001-Lib-sysconfig.py-use-prefix-value-from-build-configu.patch \
Signature · 1 line
2.35.6
Quoted 10 lines · Deepak Rathore via lists.openembedded.org
From: Deepak Rathore <[email protected]>
This patch applies the upstream v3.14 backport for CVE-2026-15308. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2]. The individual backported commit link is recorded in the embedded patch header.
[1] https://github.com/python/cpython/commit/07efb08123ba9367a7107325adb9d5626dca1ca9
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-15308
Quoted 6 lines
Signed-off-by Deepak Rathore <[email protected]>--- .../python/python3/CVE-2026-15308.patch | 116 ++++++++++++++++++ .../recipes-devtools/python/python3_3.14.6.bb | 1 + 2 files changed, 117 insertions(+) create mode 100644 meta/recipes-devtools/python/python3/CVE-2026-15308.patch
Hello,
As far as I can tell, this patch is not released on the 3.14 branch yet. I hold it until it is applied to master (upgrade or backport)
Regards,
Signature · 2 lines
Yoann Congal Smile ECS
Quoted 10 lines · Deepak Rathore via lists.openembedded.org
From: Deepak Rathore <[email protected]>
This patch applies the upstream v3.14 backport for CVE-2026-15308. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2]. The individual backported commit link is recorded in the embedded patch header.
[1] https://github.com/python/cpython/commit/07efb08123ba9367a7107325adb9d5626dca1ca9
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-15308
Quoted 6 lines
Signed-off-by Deepak Rathore <[email protected]>--- .../python/python3/CVE-2026-15308.patch | 116 ++++++++++++++++++ .../recipes-devtools/python/python3_3.14.6.bb | 1 + 2 files changed, 117 insertions(+) create mode 100644 meta/recipes-devtools/python/python3/CVE-2026-15308.patch
Hello,
In this case, I think we can consider upgrading to 3.14.7 (like master). Can you look into this?
I'll hold this patch for now.
Regards,
Signature · 2 lines
Yoann Congal Smile ECS
Hi Yoann,
Thanks for your review.
Upgrade is already proposed: [wrynose][PATCH] python3: upgrade 3.14.6 -> 3.14.7<https://lists.openembedded.org/g/openembedded-core/message/243216?p=%2C%2C%2C20%2C0%2C0%2C0%3A%3Acreated%2C%2Cpython3%3A+upgrade+3.14.6+-%3E+3.14.7%2C20%2C2%2C0%2C120704816> So, I am skipping upgrade now.
Regards,
Deepak
________________________________
From: [email protected] <[email protected]> on behalf of Yoann Congal via lists.openembedded.org <[email protected]>
Sent: Thursday, August 27, 2026 7:20 PM
To: Deepak Rathore -X (deeratho - E INFOCHIPS PRIVATE LIMITED at Cisco) <[email protected]>; [email protected] <[email protected]>
Subject: Re: [OE-core][wrynose][PATCH] python3: fix CVE-2026-15308
Quoted 10 lines · Deepak Rathore via lists.openembedded.org
From: Deepak Rathore <[email protected]>
This patch applies the upstream v3.14 backport for CVE-2026-15308. The upstream fix commit is referenced in [1], and the public CVE advisory is referenced in [2]. The individual backported commit link is recorded in the embedded patch header.
[1] https://github.com/python/cpython/commit/07efb08123ba9367a7107325adb9d5626dca1ca9
[2] https://nvd.nist.gov/vuln/detail/CVE-2026-15308
Quoted 6 lines
Signed-off-by Deepak Rathore <[email protected]>--- .../python/python3/CVE-2026-15308.patch | 116 ++++++++++++++++++ .../recipes-devtools/python/python3_3.14.6.bb | 1 + 2 files changed, 117 insertions(+) create mode 100644 meta/recipes-devtools/python/python3/CVE-2026-15308.patch
Hello,
In this case, I think we can consider upgrading to 3.14.7 (like master). Can you look into this?
I'll hold this patch for now.
Regards,
--
Yoann Congal
Smile ECS