Fix test_elementtree with Expat 2.6.0
- Fixes: rhbz#2264859
This commit is contained in:
parent
0f51029568
commit
23cd3c2e48
98
407.patch
Normal file
98
407.patch
Normal file
@ -0,0 +1,98 @@
|
||||
From e3012a702dea2b03830fe00a5e8f7a429bbc3f42 Mon Sep 17 00:00:00 2001
|
||||
From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= <miro@hroncok.cz>
|
||||
Date: Tue, 27 Feb 2024 18:43:45 +0100
|
||||
Subject: [PATCH] Fix test_elementtree with Expat 2.6.0
|
||||
|
||||
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.
|
||||
|
||||
Co-Authored-By: Serhiy Storchaka <storchaka@gmail.com>
|
||||
---
|
||||
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, "<!-- comment -->\n", chunk_size)
|
||||
- self.assert_event_tags(parser, [])
|
||||
- self._feed(parser,
|
||||
- "<root>\n <element key='value'>text</element",
|
||||
- chunk_size)
|
||||
- self.assert_event_tags(parser, [])
|
||||
- self._feed(parser, ">\n", chunk_size)
|
||||
- self.assert_event_tags(parser, [('end', 'element')])
|
||||
- self._feed(parser, "<element>text</element>tail\n", chunk_size)
|
||||
- self._feed(parser, "<empty-element/>\n", chunk_size)
|
||||
- self.assert_event_tags(parser, [
|
||||
- ('end', 'element'),
|
||||
- ('end', 'empty-element'),
|
||||
- ])
|
||||
- self._feed(parser, "</root>\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, "<!-- comment -->\n", chunk_size)
|
||||
+ self.assert_event_tags(parser, [])
|
||||
+ self._feed(parser,
|
||||
+ "<root>\n <element key='value'>text</element",
|
||||
+ chunk_size)
|
||||
+ self.assert_event_tags(parser, [])
|
||||
+ self._feed(parser, ">\n", chunk_size)
|
||||
+ self.assert_event_tags(parser, [('end', 'element')])
|
||||
+ self._feed(parser, "<element>text</element>tail\n", chunk_size)
|
||||
+ self._feed(parser, "<empty-element/>\n", chunk_size)
|
||||
+ self.assert_event_tags(parser, [
|
||||
+ ('end', 'element'),
|
||||
+ ('end', 'empty-element'),
|
||||
+ ])
|
||||
+ self._feed(parser, "</root>\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 and pyexpat.version_info >= (2, 6, 0):
|
||||
+ 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 and pyexpat.version_info >= (2, 6, 0):
|
||||
+ 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()
|
||||
@ -16,6 +16,10 @@ URL: https://github.com/lxml/lxml
|
||||
Source0: lxml-%{version}-no-isoschematron-rng.tar.gz
|
||||
Source1: get-lxml-source.sh
|
||||
|
||||
# Fix test_elementtree with Expat 2.6.0
|
||||
# Merged upstream
|
||||
Patch: https://github.com/lxml/lxml/pull/407.patch
|
||||
|
||||
BuildRequires: gcc
|
||||
BuildRequires: libxml2-devel
|
||||
BuildRequires: libxslt-devel
|
||||
|
||||
Loading…
Reference in New Issue
Block a user