From e79138f3a761f6d845400b0f03f690ba03019b47 Mon Sep 17 00:00:00 2001 From: Lumir Balhar Date: Tue, 7 Jul 2026 11:11:30 +0200 Subject: [PATCH] Fix test_elementtree with Expat where CVE fixes changed behavior This fixes FTBFS in Konflux. Resolves: RHEL-183544 --- Fix-test_elementtree-with-newer-expat.patch | 100 ++++++++++++++++++++ python3.12-lxml.spec | 5 + 2 files changed, 105 insertions(+) create mode 100644 Fix-test_elementtree-with-newer-expat.patch diff --git a/Fix-test_elementtree-with-newer-expat.patch b/Fix-test_elementtree-with-newer-expat.patch new file mode 100644 index 0000000..a1bd5d7 --- /dev/null +++ b/Fix-test_elementtree-with-newer-expat.patch @@ -0,0 +1,100 @@ +From 3ccc7d583e325ceb0ebdf8fc295bbb7fc8cd404d Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= +Date: Sat, 2 Mar 2024 06:51:01 +0100 +Subject: [PATCH] Fix test_elementtree with Expat 2.6.0 (GH-407) + +Feeding the parser by too small chunks defers parsing to prevent +CVE-2023-52425. Future versions of Expat may be more reactive. + +Heavily inspired by https://github.com/python/cpython/commit/4a08e7b3431cd32a0daf22a33421cd3035343dc4 + +We cannot use a @fails_with_expat_2_6_0 decorator +because the test passes in ETreePullTestCase. + +See https://github.com/python/cpython/issues/115133 +See https://github.com/advisories/GHSA-gh68-jm46-84rf +Co-authored-by: Serhiy Storchaka +--- + src/lxml/tests/test_elementtree.py | 62 +++++++++++++++++++----------- + 1 file changed, 39 insertions(+), 23 deletions(-) + +diff --git a/src/lxml/tests/test_elementtree.py b/src/lxml/tests/test_elementtree.py +index 8ccf4442a..ef923c5ce 100644 +--- a/src/lxml/tests/test_elementtree.py ++++ b/src/lxml/tests/test_elementtree.py +@@ -10,6 +10,7 @@ + import io + import operator + import os ++import pyexpat + import re + import sys + import textwrap +@@ -4383,29 +4384,44 @@ def assert_event_tags(self, parser, expected, max_events=None): + self.assertEqual([(action, elem.tag) for action, elem in events], + expected) + +- def test_simple_xml(self): +- for chunk_size in (None, 1, 5): +- #with self.subTest(chunk_size=chunk_size): +- parser = self.etree.XMLPullParser() +- self.assert_event_tags(parser, []) +- self._feed(parser, "\n", chunk_size) +- self.assert_event_tags(parser, []) +- self._feed(parser, +- "\n text\n", chunk_size) +- self.assert_event_tags(parser, [('end', 'element')]) +- self._feed(parser, "texttail\n", chunk_size) +- self._feed(parser, "\n", chunk_size) +- self.assert_event_tags(parser, [ +- ('end', 'element'), +- ('end', 'empty-element'), +- ]) +- self._feed(parser, "\n", chunk_size) +- self.assert_event_tags(parser, [('end', 'root')]) +- root = self._close_and_return_root(parser) +- self.assertEqual(root.tag, 'root') ++ def test_simple_xml(self, chunk_size=None): ++ parser = self.etree.XMLPullParser() ++ self.assert_event_tags(parser, []) ++ self._feed(parser, "\n", chunk_size) ++ self.assert_event_tags(parser, []) ++ self._feed(parser, ++ "\n text\n", chunk_size) ++ self.assert_event_tags(parser, [('end', 'element')]) ++ self._feed(parser, "texttail\n", chunk_size) ++ self._feed(parser, "\n", chunk_size) ++ self.assert_event_tags(parser, [ ++ ('end', 'element'), ++ ('end', 'empty-element'), ++ ]) ++ self._feed(parser, "\n", chunk_size) ++ self.assert_event_tags(parser, [('end', 'root')]) ++ root = self._close_and_return_root(parser) ++ self.assertEqual(root.tag, 'root') ++ ++ def test_simple_xml_chunk_1(self): ++ if self.etree is not etree: ++ raise unittest.SkipTest( ++ "Feeding the parser by too small chunks defers parsing" ++ ) ++ self.test_simple_xml(chunk_size=1) ++ ++ def test_simple_xml_chunk_5(self): ++ if self.etree is not etree: ++ raise unittest.SkipTest( ++ "Feeding the parser by too small chunks defers parsing" ++ ) ++ self.test_simple_xml(chunk_size=5) ++ ++ def test_simple_xml_chunk_22(self): ++ self.test_simple_xml(chunk_size=22) + + def test_feed_while_iterating(self): + parser = self.etree.XMLPullParser() diff --git a/python3.12-lxml.spec b/python3.12-lxml.spec index bdc381d..f6f4b8a 100644 --- a/python3.12-lxml.spec +++ b/python3.12-lxml.spec @@ -34,6 +34,11 @@ Patch3: Skip-failing-test-test_html_prefix_nsmap.patch Patch4: https://github.com/lxml/lxml/commit/dcbc0cc1cb0cedf8019184aaca805d2a649cd8de.patch Patch5: https://github.com/lxml/lxml/commit/a03a4b3c6b906d33c5ef1a15f3d5ca5fff600c76.patch +# Fix test_elementtree with Expat where CVE fixes changed behavior +# Backported from https://github.com/lxml/lxml/commit/3ccc7d583e325ceb0ebdf8fc295bbb7fc8cd404d +# without the check for the version of expat. +Patch6: Fix-test_elementtree-with-newer-expat.patch + BuildRequires: gcc BuildRequires: libxml2-devel BuildRequires: libxslt-devel