From a9c95a1b885b0e49d3c79a675d795be174aa003b Mon Sep 17 00:00:00 2001 From: gaochao Date: Wed, 21 May 2025 17:01:14 +0800 Subject: [PATCH] blank bug fixed Signed-off-by: gaochao --- BUILD.gn | 3 +- ...OBLANKS_dropping_non-whitespace_text.patch | 127 ++++++++++++++++++ README.OpenSource | 2 +- README.md | 4 +- README_ZH.md | 4 +- install.py | 3 +- 6 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch diff --git a/BUILD.gn b/BUILD.gn index febb6d6..f565730 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -68,7 +68,8 @@ action("libxml2_install_action") { inputs += [ "Backport-CVE-2025-32414-python-Read-at-most-len-4-ch-c.patch", "Backport-CVE-2025-32415-schemas-Fix-heap-buffer-over-c.patch", - ] + "Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch", + ] args = [ "--gen-dir", diff --git a/Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch b/Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch new file mode 100644 index 0000000..ee9c9df --- /dev/null +++ b/Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch @@ -0,0 +1,127 @@ +From a5c4a6efe77f6dd6e0a092db9357b21602eedd31 Mon Sep 17 00:00:00 2001 +From: Nick Wellnhofer +Date: Fri, 28 Mar 2025 16:31:14 +0100 +Subject: [PATCH] parser: Fix XML_PARSE_NOBLANKS dropping non-whitespace text + +Regressed with 1f5b5371. + +Fixes #884. +--- + parser.c | 13 +++++++------ + testparser.c | 34 ++++++++++++++++++++++++++++++++++ + 2 files changed, 41 insertions(+), 6 deletions(-) + +diff --git a/parser.c b/parser.c +index aacaf1f8c..d8d590ffd 100644 +--- a/parser.c ++++ b/parser.c +@@ -4778,7 +4778,8 @@ static const unsigned char test_char_data[256] = { + }; + + static void +-xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size) { ++xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size, ++ int isBlank) { + int checkBlanks; + + if ((ctxt->sax == NULL) || (ctxt->disableSAX)) +@@ -4793,7 +4794,7 @@ xmlCharacters(xmlParserCtxtPtr ctxt, const xmlChar *buf, int size) { + * essentially unusable. + */ + if ((checkBlanks) && +- (areBlanks(ctxt, buf, size, 1))) { ++ (areBlanks(ctxt, buf, size, isBlank))) { + if ((ctxt->sax->ignorableWhitespace != NULL) && + (ctxt->keepBlanks)) + ctxt->sax->ignorableWhitespace(ctxt->userData, buf, size); +@@ -4855,7 +4856,7 @@ get_more_space: + const xmlChar *tmp = ctxt->input->cur; + ctxt->input->cur = in; + +- xmlCharacters(ctxt, tmp, nbchar); ++ xmlCharacters(ctxt, tmp, nbchar, 1); + } + return; + } +@@ -4891,7 +4892,7 @@ get_more: + const xmlChar *tmp = ctxt->input->cur; + ctxt->input->cur = in; + +- xmlCharacters(ctxt, tmp, nbchar); ++ xmlCharacters(ctxt, tmp, nbchar, 0); + + line = ctxt->input->line; + col = ctxt->input->col; +@@ -4958,7 +4959,7 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int partial) { + if (nbchar >= XML_PARSER_BIG_BUFFER_SIZE) { + buf[nbchar] = 0; + +- xmlCharacters(ctxt, buf, nbchar); ++ xmlCharacters(ctxt, buf, nbchar, 0); + nbchar = 0; + SHRINK; + } +@@ -4967,7 +4968,7 @@ xmlParseCharDataComplex(xmlParserCtxtPtr ctxt, int partial) { + if (nbchar != 0) { + buf[nbchar] = 0; + +- xmlCharacters(ctxt, buf, nbchar); ++ xmlCharacters(ctxt, buf, nbchar, 0); + } + /* + * cur == 0 can mean +diff --git a/testparser.c b/testparser.c +index 5cca7b679..85fee9b4c 100644 +--- a/testparser.c ++++ b/testparser.c +@@ -255,6 +255,39 @@ testCtxtParseContent(void) { + + return err; + } ++ ++static int ++testNoBlanks(void) { ++ const xmlChar xml[] = ++ "\n" ++ " \n" ++ " \n" ++ " Run tester --help for more options.\n" ++ " \n" ++ " \n" ++ "\n"; ++ const xmlChar expect[] = ++ "\n" ++ "\n" ++ " Run tester --help for more options.\n" ++ " \n"; ++ xmlDocPtr doc; ++ xmlChar *out; ++ int size; ++ int err = 0; ++ ++ doc = xmlReadDoc(xml, NULL, NULL, XML_PARSE_NOBLANKS); ++ xmlDocDumpMemory(doc, &out, &size); ++ xmlFreeDoc(doc); ++ ++ if (!xmlStrEqual(out, expect)) { ++ fprintf(stderr, "parsing with XML_PARSE_NOBLANKS failed\n"); ++ err = 1; ++ } ++ xmlFree(out); ++ ++ return err; ++} + #endif /* LIBXML_OUTPUT_ENABLED */ + + #ifdef LIBXML_SAX1_ENABLED +@@ -1123,6 +1156,7 @@ main(void) { + #endif + #ifdef LIBXML_OUTPUT_ENABLED + err |= testCtxtParseContent(); ++ err |= testNoBlanks(); + #endif + #ifdef LIBXML_SAX1_ENABLED + err |= testBalancedChunk(); +-- +GitLab + diff --git a/README.OpenSource b/README.OpenSource index ef9abca..647f3ad 100644 --- a/README.OpenSource +++ b/README.OpenSource @@ -1,6 +1,6 @@ [ { - "Name": "openEuler:libxml2", + "Name": "libxml2", "License": "MIT License", "License File": "Copyright", "Version Number": "2.14.0", diff --git a/README.md b/README.md index 46f90ab..5203e09 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# openEuler:libxml2 +# libxml2 #### Introduction & Software Architecture - [Refer to the official documentation](https://gitlab.gnome.org/GNOME/libxml2/) @@ -9,7 +9,7 @@ #### Patch Package Description -The following patches is carried by the openEuler:libnl3 open source library: +The following patches is carried by the libnl3 open source library: Fix-memleaks-in-xmlXIncludeProcessFlags.patch backport-parser-Fix-potential-memory-leak-in-xmlParseAttValue.patch diff --git a/README_ZH.md b/README_ZH.md index 1899b55..cd7952e 100755 --- a/README_ZH.md +++ b/README_ZH.md @@ -1,4 +1,4 @@ -# openEuler:libxml2 +# libxml2 #### 简介 & 软件架构 @@ -10,7 +10,7 @@ #### patch包说明 -以下patch包为openEuler:libxml2开源库本身携带 +以下patch包为libxml2开源库本身携带 Fix-memleaks-in-xmlXIncludeProcessFlags.patch backport-parser-Fix-potential-memory-leak-in-xmlParseAttValue.patch diff --git a/install.py b/install.py index 35265c1..c77e441 100755 --- a/install.py +++ b/install.py @@ -49,7 +49,8 @@ def apply_patch(patch_file, target_dir): def do_patch(args, target_dir): patch_file = [ "Backport-CVE-2025-32414-python-Read-at-most-len-4-ch-c.patch", - "Backport-CVE-2025-32415-schemas-Fix-heap-buffer-over-c.patch" + "Backport-CVE-2025-32415-schemas-Fix-heap-buffer-over-c.patch", + "Fix_XML_PARSE_NOBLANKS_dropping_non-whitespace_text.patch" ] for patch in patch_file: -- Gitee