From nobody Fri Nov 06 01:19:28 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jLLtt22tBz6xdlv for ; Fri, 06 Nov 2026 01:19:34 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id 4jLLtt0KJGz3Dr2 for ; Fri, 06 Nov 2026 01:19:34 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793927974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mCl0nfI2DJYhRmVtgT2YnFIw3AvcppPYKewLhEpXadI=; b=FXpRFEF6JUr6Yetiam18BWoJ/1wU1YYzC1YX7HT7XQtP9VfVuvAxaVRwTJXvyc+aHzEj2d YHqptVXlp6LAzjcgu4+QfSRGSYzcUq3dIuhs14f9DawSuhcOw5TC3RpiKrbq6h8560AlfA KghSmctfqmxtxz18eVj4+ZkMYsV1YbvJHzrMK7lZ79VVSPnlBMvaDZAiZePYFFQGbD3rKz 1/N08nmFQO5g+Cofps7TZUPQaL0QjWzlzF0cHD4CsOScAccBdQhKAsneFDG7UHxB3Ixf9O v3b8TylVGJAhneFAyMy851azQmNDOX+YqiPutPzUik38mDw9TZUbT3yxPOwGGQ== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1793927974; b=gV4qjD2QFOC+FUD4wFDyMVu9l1pto6yRfNcChTIJ3r4jy5b5O37rN57qNlKzE9YJ4lB7VO DOOFm+kAD67MpdVdfpuZxzjxZXfxIOANuwFB1Hen1TPrz7fpyyYNkr8+KYSctFLXJVFjdF qjJfmqU3hNeEPyDUiNvmIzyudqolqhyBfJQMY7ZG67EtVfDdELpkqBWwUei8MQg5L0D2z4 hsaQkzWIcXvqvp6ox5yK0f3naFy9SgGiWOhCaCLEId/MA3EWvjmBba4WeZt/euJmjiBdp3 Q3aR8KmHf7rVO+g1hSDlVj+WEz8Fu/1mik6z4pqbf3oOG5q6TlubKWK5u4vl/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1793927974; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=mCl0nfI2DJYhRmVtgT2YnFIw3AvcppPYKewLhEpXadI=; b=IWkNGLtvi+gZRX/aku7q3MakGSwSdUvHT+/jyb8Wa/UhSOoemg8d6o+r2fvh9mgBGeF+rs 7vB23IpK1rb9wpyEvnzLxr2WcGM3QLZaV6HsndIVlFXkBlfHgOTJYXEs4DDHK1m6XcJDHT Wy/hXYvTsCiQTV4y89kUX1vBzSYfKNqCXvCIDqe6e+U3xAppMA54uPN6X1QThCLOrHB+EH 6E6xRn6zvwqgdQy511RzNGpEiOHzzFwz5kXSYtotweFd59g91RduGUD4O/ckHjSS0FHLHz Mel0+ent0/91UQT+8HVAjcCgPIkBNnQwiS+7SLhwavj1Qcjg6VWuh8c25LT8SQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jLLts6rLjzF5f for ; Fri, 06 Nov 2026 01:19:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 44766 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Fri, 06 Nov 2026 01:19:28 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Philip Paeps Subject: git: 27d5ac65db13 - stable/15 - contrib/expat: import expat 2.10.0 List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: philip X-Git-Repository: src X-Git-Refname: refs/heads/stable/15 X-Git-Reftype: branch X-Git-Commit: 27d5ac65db13ac8813bde701deb0d21169ffb90c Auto-Submitted: auto-generated Date: Fri, 06 Nov 2026 01:19:28 +0000 Message-Id: <6aed2b20.44766.21acfca7@gitrepo.freebsd.org> The branch stable/15 has been updated by philip: URL: https://cgit.FreeBSD.org/src/commit/?id=27d5ac65db13ac8813bde701deb0d21169ffb90c commit 27d5ac65db13ac8813bde701deb0d21169ffb90c Author: Philip Paeps AuthorDate: 2026-11-02 15:11:05 +0000 Commit: Philip Paeps CommitDate: 2026-11-06 00:27:48 +0000 contrib/expat: import expat 2.10.0 Changes: https://github.com/libexpat/libexpat/blob/R_2_10_0/expat/Changes Security: CVE-2026-115506 Security: CVE-2026-117610 Security: CVE-2026-118370 (cherry picked from commit 765f30b9f3af67a1db9619ff18862dc74ac72674) (cherry picked from commit a377d25bd25c0739d50c4dfe34ec2066821018d3) --- contrib/expat/Changes | 89 ++++ contrib/expat/README.md | 2 +- contrib/expat/configure.ac | 2 +- contrib/expat/doc/reference.html | 8 +- contrib/expat/doc/xmlwf.1 | 2 +- contrib/expat/doc/xmlwf.xml | 2 +- contrib/expat/lib/Makefile.am | 5 +- contrib/expat/lib/Makefile.in | 7 +- contrib/expat/lib/ascii.h | 3 +- contrib/expat/lib/entities.h | 99 ++++ contrib/expat/lib/expat.h | 5 +- contrib/expat/lib/expat_external.h | 2 +- contrib/expat/lib/internal.h | 8 +- contrib/expat/lib/xcs.c | 21 + contrib/expat/lib/xcs.h | 3 + contrib/expat/lib/xmlparse.c | 871 +++++++++++++++++++++++++++++------ contrib/expat/lib/xmltok.h | 4 +- contrib/expat/lib/xmltok_impl.c | 6 +- contrib/expat/tests/Makefile.am | 7 +- contrib/expat/tests/Makefile.in | 31 +- contrib/expat/tests/acc_tests.c | 32 ++ contrib/expat/tests/alloc_tests.c | 42 ++ contrib/expat/tests/basic_tests.c | 63 ++- contrib/expat/tests/common.c | 12 + contrib/expat/tests/common.h | 2 + contrib/expat/tests/dummy.h | 3 + contrib/expat/tests/entities_tests.c | 246 ++++++++++ contrib/expat/tests/entities_tests.h | 41 ++ contrib/expat/tests/handlers.h | 1 + contrib/expat/tests/misc_tests.c | 181 +++++++- contrib/expat/tests/runtests.c | 2 + contrib/expat/tests/xcs_tests.c | 23 + contrib/expat/xmlwf/Makefile.am | 5 +- contrib/expat/xmlwf/Makefile.in | 5 +- lib/libexpat/expat_config.h | 6 +- lib/libexpat/libbsdxml.3 | 4 +- 36 files changed, 1647 insertions(+), 198 deletions(-) diff --git a/contrib/expat/Changes b/contrib/expat/Changes index 91513379bb49..0124f81edbdd 100644 --- a/contrib/expat/Changes +++ b/contrib/expat/Changes @@ -21,6 +21,86 @@ // Sebastian Pipping -- Berlin, 2026-09-22 // /////////////////////////////////////////////////////////////////////////////// +Release 2.10.0 Mon November 2 2026 + Security fixes: + #1431 CVE-2026-113351 -- Fix denial of service with use of + `XML_ParserReset` + #1433 #1436 .. + #1438 #1439 .. + #1442 CVE-2026-115506 -- Detect billion laughs attacks quicker + and more of its variations. Related payload fuzzer at: + https://github.com/hannob/lololol + Please note that a layer of compression around XML can + significantly reduce the minimum attack payload size. + In case of backporting, please note pull request #1439 + in particular. + #1444 CVE-2026-117610 -- Fix initial non-final empty subparser + parse calls. Was segfaulting previously. + #1450 CVE-2026-118370 -- Protect `attIndex` and `nPrefixes` in + function `storeAtts` from signed integer overflow + + Bug fixes: + #1452 lib: Initialize `m_parsingStatus.finalBuffer` in `parserInit` + to fix calling `XML_GetParsingStatus` right after + parser creation + #1457 #1459 lib: Improve `XML_Parse` for `XML_CONTEXT_BYTES == 0` + including NULL pointer arithmetic undefined behavior + and uninitialized variable access + #1458 lib: Use C99 length modifiers for `ptrdiff_t` and `size_t` + to fix support for CHERI-RISC-V + #1461 lib: Check `isCalledFromInsideHandler` first in `XML_Parse` + #1467 lib: Add missing check for a character handler reset + + Other changes: + #1441 Autotools: Move `-lm` from LDFLAGS to LIBADD/LDADD + to better support compilation with `-Wl,--as-needed` + #1412 CMake: Support repeated `find_package` calls + #1413 lib: Address warning `XML_GE is not defined [-Werror=undef]` + #1415 lib: Stop delaying `callStoreEntityValue` error handling + #1415 lib: Add missing call to `poolDiscard` + #1437 lib: Add missing `NULL` check for `m_startDoctypeDeclHandler` + #1417 lib: Migrate `ENTITY.textLen` and `ENTITY.processed` from + `int` to `size_t` + #1463 lib: Fix integer truncation in `XmlGetAttributes`/`getAtts` + #1420 lib: Some more `XML_Bool` to `bool` migration + #1449 #1460 lib: Document the memory reuse black magic that function + `storeAtts` is doing + #1453 lib: Document failure to reject bad redefinitions of + predefined entities + #1432 tests: Replace `XML_SetHashSalt` with + `XML_SetHashSalt16Bytes` + #1416 #1435 Version info bumped from 14:0:13 (libexpat*.so.1.13.0) + to 14:1:13 (libexpat*.so.1.13.1); see https://verbump.de/ + for what these numbers do + + Infrastructure: + #1414 CI: Stop using about-to-be-removed image "macos-14" + #1418 #1434 CI: Bump MinGW Clang from 23.1.2 to 23.1.4 + #1443 CI: Bump Fil-C from 0.686 to 0.687 + #1456 Drop a `lib/xcsinc.c` leftover + + Special thanks to: + Alexander Bluhm + Bartłomiej Dmitruk + Berkay Eren Ürün + Brooks Davis + brspoon + Funda Wang + Hanno Böck + Matthew Fernandez + Minkyung Park + Mirko Swillus + Pu Cheng + Scott Moore + Shani Yosef + Xisco Fauli + and + City of Munich Open Source Sabbatical + echo.ai + Siemens + Striga + VulnCheck + Release 2.9.0 Mon October 5 2026 Security fixes: #1392 CVE-2026-102633 -- Integer overflow in function @@ -106,6 +186,7 @@ Release 2.9.0 Mon October 5 2026 Wade Sparks III and City of Munich Open Source Sabbatical + Siemens VulnCheck Release 2.8.5 Tue September 22 2026 @@ -239,6 +320,7 @@ Release 2.8.4 Mon August 31 2026 and City of Munich Open Source Sabbatical Moonshot AI + Siemens VulnCheck Z.ai @@ -425,6 +507,8 @@ Release 2.8.1 Sun May 10 2026 Matthew Fernandez Nick Wellnhofer Tania Somanna + and + Siemens Release 2.8.0 Fri April 24 2026 Security fixes: @@ -537,6 +621,7 @@ Release 2.7.5 Tue March 17 2026 AddressSanitizer Buttercup OSS-Fuzz / ClusterFuzz + Siemens Trail of Bits Release 2.7.4 Sat January 31 2026 @@ -678,6 +763,7 @@ Release 2.7.3 Wed September 24 2025 and Clang/GCC UndefinedBehaviorSanitizer OSS-Fuzz / ClusterFuzz + Siemens Z3 Theorem Prover Release 2.7.2 Tue September 16 2025 @@ -791,6 +877,7 @@ Release 2.7.1 Thu March 27 2025 Matthew Fernandez and Perl XML::Parser + Siemens Release 2.7.0 Thu March 13 2025 Security fixes: @@ -950,6 +1037,8 @@ Release 2.6.3 Wed September 4 2024 Dag-Erling Smørgrav Ferenc Géczi TaiYou + and + Siemens Release 2.6.2 Wed March 13 2024 Security fixes: diff --git a/contrib/expat/README.md b/contrib/expat/README.md index 1951645e8285..27e0dd481b18 100644 --- a/contrib/expat/README.md +++ b/contrib/expat/README.md @@ -17,7 +17,7 @@ > Thank you! :heart: :pray: -# Expat, Release 2.9.0 +# Expat, Release 2.10.0 This is Expat, a C99 library for parsing [XML 1.0 Fourth Edition](https://www.w3.org/TR/2006/REC-xml-20060816/), started by diff --git a/contrib/expat/configure.ac b/contrib/expat/configure.ac index 6d80021cf0a9..cf61d6e47c6d 100644 --- a/contrib/expat/configure.ac +++ b/contrib/expat/configure.ac @@ -104,7 +104,7 @@ dnl If the API changes incompatibly set LIBAGE back to 0 dnl LIBCURRENT=14 # sync -LIBREVISION=0 # with +LIBREVISION=1 # with LIBAGE=13 # CMakeLists.txt! AC_CONFIG_HEADERS([expat_config.h]) diff --git a/contrib/expat/doc/reference.html b/contrib/expat/doc/reference.html index 2f892fd20b82..ebd5cf1913cf 100644 --- a/contrib/expat/doc/reference.html +++ b/contrib/expat/doc/reference.html @@ -53,7 +53,7 @@

- The Expat XML Parser Release 2.9.0 + The Expat XML Parser Release 2.10.0

@@ -2862,6 +2862,12 @@ typedef void The notationName argument will have a non-NULL value only for unparsed entity declarations.

+ +

+ Note: Length value_length can wrap around on + platforms where int is smaller than size_t including + x86_64. +

diff --git a/contrib/expat/doc/xmlwf.1 b/contrib/expat/doc/xmlwf.1 index 22ca1d387b5f..ee683977cb26 100644 --- a/contrib/expat/doc/xmlwf.1 +++ b/contrib/expat/doc/xmlwf.1 @@ -5,7 +5,7 @@ \\$2 \(la\\$1\(ra\\$3 .. .if \n(.g .mso www.tmac -.TH XMLWF 1 "October 5, 2026" "" "" +.TH XMLWF 1 "November 2, 2026" "" "" .SH NAME xmlwf \- Determines if an XML document is well-formed .SH SYNOPSIS diff --git a/contrib/expat/doc/xmlwf.xml b/contrib/expat/doc/xmlwf.xml index 06880749583b..801bd35b2bf1 100644 --- a/contrib/expat/doc/xmlwf.xml +++ b/contrib/expat/doc/xmlwf.xml @@ -21,7 +21,7 @@ "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [ Scott"> Bronson"> - October 5, 2026"> + November 2, 2026"> 1"> bronson@rinspin.com"> diff --git a/contrib/expat/lib/Makefile.am b/contrib/expat/lib/Makefile.am index e4211b4dd3f9..97e7afa28493 100644 --- a/contrib/expat/lib/Makefile.am +++ b/contrib/expat/lib/Makefile.am @@ -12,6 +12,7 @@ # Copyright (c) 2026 Gordon Messmer # Copyright (c) 2026 Nick Begg # Copyright (c) 2026 Matthew Fernandez +# Copyright (c) 2026 Funda Wang # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -45,13 +46,14 @@ endif libexpat_la_LDFLAGS = \ @AM_LDFLAGS@ \ - @LIBM@ \ -no-undefined \ -version-info @LIBCURRENT@:@LIBREVISION@:@LIBAGE@ if HAVE_VSCRIPT libexpat_la_LDFLAGS += $(VSCRIPT_LDFLAGS),@builddir@/libexpat.map endif +libexpat_la_LIBADD = @LIBM@ + libexpat_la_SOURCES = \ xcs.c \ xmlparse.c \ @@ -113,6 +115,7 @@ uninstall-local: EXTRA_DIST = \ ascii.h \ asciitab.h \ + entities.h \ expat_external.h \ expat.h \ fallthrough.h \ diff --git a/contrib/expat/lib/Makefile.in b/contrib/expat/lib/Makefile.in index 4e5bb0bfd966..73ac70448b65 100644 --- a/contrib/expat/lib/Makefile.in +++ b/contrib/expat/lib/Makefile.in @@ -28,6 +28,7 @@ # Copyright (c) 2026 Gordon Messmer # Copyright (c) 2026 Nick Begg # Copyright (c) 2026 Matthew Fernandez +# Copyright (c) 2026 Funda Wang # Licensed under the MIT license: # # Permission is hereby granted, free of charge, to any person obtaining @@ -205,7 +206,7 @@ am__uninstall_files_from_dir = { \ am__installdirs = "$(DESTDIR)$(libdir)" "$(DESTDIR)$(docdir)" \ "$(DESTDIR)$(includedir)" LTLIBRARIES = $(lib_LTLIBRARIES) $(noinst_LTLIBRARIES) -libexpat_la_LIBADD = +libexpat_la_DEPENDENCIES = am__libexpat_la_SOURCES_DIST = xcs.c xmlparse.c xmltok.c xmlrole.c \ random_arc4random.c random_arc4random.h \ random_arc4random_buf.c random_arc4random_buf.h \ @@ -493,8 +494,9 @@ include_HEADERS = \ lib_LTLIBRARIES = libexpat.la @WITH_TESTS_TRUE@noinst_LTLIBRARIES = libtestpat.la -libexpat_la_LDFLAGS = @AM_LDFLAGS@ @LIBM@ -no-undefined -version-info \ +libexpat_la_LDFLAGS = @AM_LDFLAGS@ -no-undefined -version-info \ @LIBCURRENT@:@LIBREVISION@:@LIBAGE@ $(am__append_1) +libexpat_la_LIBADD = @LIBM@ libexpat_la_SOURCES = xcs.c xmlparse.c xmltok.c xmlrole.c \ $(am__append_2) $(am__append_3) $(am__append_4) \ $(am__append_5) $(am__append_6) $(am__append_7) @@ -507,6 +509,7 @@ doc_DATA = \ EXTRA_DIST = \ ascii.h \ asciitab.h \ + entities.h \ expat_external.h \ expat.h \ fallthrough.h \ diff --git a/contrib/expat/lib/ascii.h b/contrib/expat/lib/ascii.h index 1d9cf70bf695..d5d82bf41e82 100644 --- a/contrib/expat/lib/ascii.h +++ b/contrib/expat/lib/ascii.h @@ -10,7 +10,7 @@ Copyright (c) 2000 Clark Cooper Copyright (c) 2002 Fred L. Drake, Jr. Copyright (c) 2007 Karl Waclawek - Copyright (c) 2017 Sebastian Pipping + Copyright (c) 2017-2026 Sebastian Pipping Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -113,6 +113,7 @@ #define ASCII_LT 0x3C #define ASCII_EQUALS 0x3D #define ASCII_GT 0x3E +#define ASCII_QUEST 0x3F #define ASCII_LSQB 0x5B #define ASCII_RSQB 0x5D #define ASCII_UNDERSCORE 0x5F diff --git a/contrib/expat/lib/entities.h b/contrib/expat/lib/entities.h new file mode 100644 index 000000000000..51e3ed5c151b --- /dev/null +++ b/contrib/expat/lib/entities.h @@ -0,0 +1,99 @@ +/* Internal helpers related to entities + __ __ _ + ___\ \/ /_ __ __ _| |_ + / _ \\ /| '_ \ / _` | __| + | __// \| |_) | (_| | |_ + \___/_/\_\ .__/ \__,_|\__| + |_| XML parser + + Copyright (c) 2026 Sebastian Pipping + Licensed under the MIT license: + + Permission is hereby granted, free of charge, to any person obtaining + a copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to permit + persons to whom the Software is furnished to do so, subject to the + following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + USE OR OTHER DEALINGS IN THE SOFTWARE. + + SPDX-License-Identifier: MIT +*/ + +#if ! defined(EXPAT_ENTITIES_H) +# define EXPAT_ENTITIES_H 1 + +# include "expat_config.h" // for XML_GE +# include "expat_external.h" // for XML_Char +# include "internal.h" // for XML_NONTESTING_STATIC +# include // for size_t +# include // for size_t + +typedef struct { + const XML_Char *name; + const XML_Char *textPtr; + size_t textLen; /* length in XML_Chars */ + size_t processed; /* # of processed bytes - when suspended */ + const XML_Char *systemId; + const XML_Char *base; + const XML_Char *publicId; + const XML_Char *notation; + bool open; + bool hasMore; /* true if entity has not been completely processed */ + /* An entity can be open while being already completely processed (!hasMore). + The reason is the delayed closing of entities until their inner + entities are processed and closed */ + bool is_param; + bool is_internal; /* true if declared in internal subset outside PE */ +# if XML_GE == 1 + /* Indirect accounting bytes charged when this entity is expanded: 1 per text + character, plus each reference's "&name;"/"%name;" token length and its own + expansion. Matches XML_ACCOUNT_ENTITY_EXPANSION, so it is not the + replacement-text size. 0 means "not computed yet" (an empty entity is 0 + too, told apart by textLen == 0). */ + XmlBigCount expandedSize; + bool beingAnalyzed; /* on the resolveEntityClosureExpandedSize depth-first + search stack; used for cycle detection */ + const XML_Char + *scanPtr; /* cursor position into the entity's replacement text; NULL when + `textPtr` is NULL, else a pointer into the entity value, + ranging from `.textPtr` to `.textPtr + .textLen`. */ +# endif /* XML_GE == 1 */ +} ENTITY; + +# if XML_GE == 1 +/* How a scanEntityText call ended. */ +enum EntityScanResult { + ENTITY_SCAN_COMPLETE, /* reached end of text; *expandedSize is final */ + ENTITY_SCAN_BLOCKED, /* stopped at a defined entity whose expanded + size has not been computed yet; *blockerOut + names the entity whose size to compute + first */ + ENTITY_SCAN_OVERFLOW /* the expanded size would exceed XmlBigCount; + callers must abort parsing */ +}; + +XML_NONTESTING_STATIC int isCDataCommentOrPIStart(const XML_Char *pos, + size_t maxLen, + size_t *openTextLen); + +XML_NONTESTING_STATIC int isPredefinedEntityName(const XML_Char *name, + size_t nameLen); + +XML_NONTESTING_STATIC enum EntityScanResult +scanEntityText(XML_Parser parser, ENTITY *entity, const XML_Char **posPtr, + XmlBigCount *expandedSize, ENTITY **blockerOut); +# endif /* XML_GE == 1 */ + +#endif // ! defined(EXPAT_ENTITIES_H) diff --git a/contrib/expat/lib/expat.h b/contrib/expat/lib/expat.h index 1b2852dd76cb..5756ed31936c 100644 --- a/contrib/expat/lib/expat.h +++ b/contrib/expat/lib/expat.h @@ -21,6 +21,7 @@ Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp> Copyright (c) 2025 Matthew Fernandez Copyright (c) 2026 Braian Plaku + Copyright (c) 2026 Xisco Fauli Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -1084,7 +1085,7 @@ enum XML_Parser_Property { # if defined(XML_TESTING) XML_PROP_INVALID = 0, # endif -# if XML_GE == 1 +# if defined(XML_GE) && XML_GE == 1 XML_PROP_ALLOC_TRACKER_ACTIVATION_THRESHOLD = 1, // of type `uint64_t` XML_PROP_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION = 2, // of type `double` XML_PROP_BILLION_LAUGHS_ACTIVATION_THRESHOLD = 3, // of type `uint64_t` @@ -1146,7 +1147,7 @@ XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled); See https://semver.org */ # define XML_MAJOR_VERSION 2 -# define XML_MINOR_VERSION 9 +# define XML_MINOR_VERSION 10 # define XML_MICRO_VERSION 0 # ifdef __cplusplus diff --git a/contrib/expat/lib/expat_external.h b/contrib/expat/lib/expat_external.h index 0620fe47ed3c..66be69ce3fe7 100644 --- a/contrib/expat/lib/expat_external.h +++ b/contrib/expat/lib/expat_external.h @@ -12,7 +12,7 @@ Copyright (c) 2001-2002 Greg Stein Copyright (c) 2002-2006 Karl Waclawek Copyright (c) 2016 Cristian Rodríguez - Copyright (c) 2016-2025 Sebastian Pipping + Copyright (c) 2016-2026 Sebastian Pipping Copyright (c) 2017 Rhodri James Copyright (c) 2018 Yury Gribov Copyright (c) 2026 Matthew Fernandez diff --git a/contrib/expat/lib/internal.h b/contrib/expat/lib/internal.h index de34cd7dfc55..3c50a1e404ab 100644 --- a/contrib/expat/lib/internal.h +++ b/contrib/expat/lib/internal.h @@ -29,6 +29,7 @@ Copyright (c) 2026 Matthew Wozniczka Copyright (c) 2026 Braian Plaku Copyright (c) 2026 Florian Schmaus + Copyright (c) 2026 Brooks Davis Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -90,11 +91,10 @@ # define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u" # endif # else -# include // PRIdPTR, PRIuPTR # define EXPAT_FMT_LLX(midpart) "%" midpart "llx" # define EXPAT_FMT_ULL(midpart) "%" midpart "llu" -# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart PRIdPTR -# define EXPAT_FMT_SIZE_T(midpart) "%" midpart PRIuPTR +# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "td" +# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "zu" # endif # ifndef UNUSED_P @@ -127,6 +127,8 @@ union expat_align { # include "expat.h" // so we can use type XML_Parser below +typedef unsigned long long XmlBigCount; + void _INTERNAL_trim_to_complete_utf8_characters(const char *from, const char **fromLimRef); diff --git a/contrib/expat/lib/xcs.c b/contrib/expat/lib/xcs.c index ae5e042d778f..a97647fa9d69 100644 --- a/contrib/expat/lib/xcs.c +++ b/contrib/expat/lib/xcs.c @@ -88,3 +88,24 @@ xcsncmp(const XML_Char *a, const XML_Char *b, size_t len) { return strncmp(a, b, len); #endif } + +// A port of `strnstr(3bsd)` to `XML_Char` +const XML_Char * +xcsnstr(const XML_Char *haystack, const XML_Char *needle, size_t maxLen) { + // NOTE: We are not calling `xcsnlen(haystack, maxLen)` because + // `haystack` could be long and `xcsnlen` could be used in a loop + // and we need to avoid quadratic runtime behavior. + if (! *needle) + return haystack; // i.e. empty needle is always a match + const size_t needleLen = xcslen(needle); + if (needleLen > maxLen) + return NULL; + const size_t maxTries = (maxLen - needleLen) + 1; + for (size_t i = 0; i < maxTries && haystack[i]; i++) { + if (haystack[i] == needle[0] + && xcsncmp(haystack + i, needle, needleLen) == 0) { + return haystack + i; + } + } + return NULL; +} diff --git a/contrib/expat/lib/xcs.h b/contrib/expat/lib/xcs.h index 1b942647d333..9fbc4fe4c851 100644 --- a/contrib/expat/lib/xcs.h +++ b/contrib/expat/lib/xcs.h @@ -41,4 +41,7 @@ extern size_t xcslen(const XML_Char *s); extern int xcscmp(const XML_Char *a, const XML_Char *b); extern int xcsncmp(const XML_Char *a, const XML_Char *b, size_t len); +extern const XML_Char *xcsnstr(const XML_Char *haystack, const XML_Char *needle, + size_t maxLen); + #endif // ! defined(EXPAT_XCS_H) diff --git a/contrib/expat/lib/xmlparse.c b/contrib/expat/lib/xmlparse.c index 41288b6ad418..5b4c60545fe3 100644 --- a/contrib/expat/lib/xmlparse.c +++ b/contrib/expat/lib/xmlparse.c @@ -1,4 +1,4 @@ -/* e3ca845466942140c9af531ac57808c4650116df5d6dbeda3b6546d2548a586e (2.9.0+) +/* d0712c5efef760b5355ed61473a927256c6474aecb853016d2e335e571c64b0c (2.10.0+) __ __ _ ___\ \/ /_ __ __ _| |_ / _ \\ /| '_ \ / _` | __| @@ -58,6 +58,8 @@ Copyright (c) 2026 Braian Plaku Copyright (c) 2026 Filippo Tedeschi Copyright (c) 2026 Junki Lee + Copyright (c) 2026 Shani Yosef + Copyright (c) 2026 Pu Cheng Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -227,11 +229,13 @@ typedef char ICHAR; /* Do safe (NULL-aware) pointer arithmetic */ #define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0) +#define EXPAT_SAFE_PTR_ADD(p, a) ((p) ? ((p) + (a)) : NULL) #define EXPAT_MIN(a, b) (((a) < (b)) ? (a) : (b)) #include "internal.h" #include "hash_table.h" +#include "entities.h" #include "xmltok.h" #include "xmlrole.h" @@ -309,24 +313,6 @@ typedef struct tag { BINDING *bindings; } TAG; -typedef struct { - const XML_Char *name; - const XML_Char *textPtr; - int textLen; /* length in XML_Chars */ - int processed; /* # of processed bytes - when suspended */ - const XML_Char *systemId; - const XML_Char *base; - const XML_Char *publicId; - const XML_Char *notation; - bool open; - bool hasMore; /* true if entity has not been completely processed */ - /* An entity can be open while being already completely processed (!hasMore). - The reason is the delayed closing of entities until their inner - entities are processed and closed */ - bool is_param; - bool is_internal; /* true if declared in internal subset outside PE */ -} ENTITY; - typedef struct { enum XML_Content_Type type; enum XML_Content_Quant quant; @@ -365,7 +351,7 @@ typedef struct attribute_id { typedef struct { const ATTRIBUTE_ID *id; - XML_Bool isCdata; + bool isCdata; const XML_Char *value; } DEFAULT_ATTRIBUTE; @@ -455,7 +441,6 @@ enum XML_Account { }; #if XML_GE == 1 -typedef unsigned long long XmlBigCount; typedef struct accounting { XmlBigCount countBytesDirect; XmlBigCount countBytesIndirect; @@ -467,6 +452,7 @@ typedef struct accounting { typedef struct MALLOC_TRACKER { size_t bytesAllocated; size_t peakBytesAllocated; // updated live only for debug level >=2 + size_t bytesAllocatedWhenLastReset; unsigned long debugLevel; float maximumAmplificationFactor; // >=1.0 XmlBigCount activationThresholdBytes; @@ -478,6 +464,13 @@ typedef struct entity_stats { unsigned int maximumDepthSeen; unsigned long debugLevel; } ENTITY_STATS; + +/* One pending entity-analysis task on the explicit stack used by + resolveEntityClosureExpandedSize's depth-first search over the entity + reference graph. */ +typedef struct { + ENTITY *entity; /* entity currently being scanned */ +} ENTITY_ANALYSIS_TASK; #endif /* XML_GE == 1 */ typedef enum XML_Error Processor(XML_Parser parser, const char *start, @@ -537,15 +530,15 @@ static enum XML_Error addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId, const XML_Char *uri, BINDING **bindingsPtr); static int defineAttribute(ELEMENT_TYPE *type, ATTRIBUTE_ID *attId, - XML_Bool isCdata, XML_Bool isId, - const XML_Char *value, XML_Parser parser); + bool isCdata, bool isId, const XML_Char *value, + XML_Parser parser); static enum XML_Error storeAttributeValue(XML_Parser parser, - const ENCODING *enc, XML_Bool isCdata, + const ENCODING *enc, bool isCdata, const char *ptr, const char *end, STRING_POOL *pool, enum XML_Account account); static enum XML_Error -appendAttributeValue(XML_Parser parser, const ENCODING *enc, XML_Bool isCdata, +appendAttributeValue(XML_Parser parser, const ENCODING *enc, bool isCdata, const char *ptr, const char *end, STRING_POOL *pool, enum XML_Account account, const char **nextPtr); static ATTRIBUTE_ID *getAttributeId(XML_Parser parser, const ENCODING *enc, @@ -560,6 +553,9 @@ static enum XML_Error callStoreEntityValue(XML_Parser parser, const ENCODING *enc, const char *start, const char *end, enum XML_Account account); +static enum XML_Error resolveEntityClosureExpandedSize(XML_Parser parser, + HASH_TABLE *table, + ENTITY *root); #else static enum XML_Error storeSelfEntityValue(XML_Parser parser, ENTITY *entity); #endif @@ -597,7 +593,7 @@ static const XML_Char *poolCopyString(STRING_POOL *pool, const XML_Char *s); static const XML_Char *poolCopyStringNoFinish(STRING_POOL *pool, const XML_Char *s); static const XML_Char *poolCopyStringN(STRING_POOL *pool, const XML_Char *s, - int n); + size_t n); static const XML_Char *poolAppendString(STRING_POOL *pool, const XML_Char *s); static int nextScaffoldPart(XML_Parser parser); @@ -615,12 +611,17 @@ static XML_Parser parserCreate(const XML_Char *encodingName, const XML_Char *nameSep, DTD *dtd, XML_Parser parentParser); -static void parserInit(XML_Parser parser, const XML_Char *encodingName); +static void parserInit(XML_Parser parser, const XML_Char *encodingName, + bool isReset); #if XML_GE == 1 -static float accountingGetCurrentAmplification(XML_Parser rootParser); -static void accountingReportStats(XML_Parser originParser, const char *epilog); -static void accountingOnAbort(XML_Parser originParser); +static float accountingGetCurrentAmplification(XML_Parser rootParser, + XmlBigCount extraIndirectBytes); +static void accountingReportStats(XML_Parser originParser, const char *epilog, + XmlBigCount extraIndirectBytes, + int sourceLine); +static void accountingOnAbort(XML_Parser originParser, + XmlBigCount extraIndirectBytes, int sourceLine); static void accountingReportDiff(XML_Parser rootParser, unsigned int levelsAwayFromRootParser, const char *before, const char *after, @@ -630,6 +631,9 @@ static XML_Bool accountingDiffTolerated(XML_Parser originParser, int tok, const char *before, const char *after, int source_line, enum XML_Account account); +static XML_Bool +accountingCurrentAmplificationTolerated(XML_Parser rootParser, + XmlBigCount extraIndirectBytes); static void entityTrackingReportStats(XML_Parser parser, ENTITY *entity, const char *action, int sourceLine); @@ -637,6 +641,10 @@ static void entityTrackingOnOpen(XML_Parser parser, ENTITY *entity, int sourceLine); static void entityTrackingOnClose(XML_Parser parser, ENTITY *entity, int sourceLine); +static void entityTrackingOnScanStart(XML_Parser parser, ENTITY *entity, + int sourceLine); +static void entityTrackingOnScanStop(XML_Parser parser, ENTITY *entity, + int sourceLine); #endif /* XML_GE == 1 */ static XML_Parser getRootParserOf(XML_Parser parser, @@ -792,8 +800,8 @@ struct XML_ParserStruct { const XML_Char *m_declNotationPublicId; ELEMENT_TYPE *m_declElementType; ATTRIBUTE_ID *m_declAttributeId; - XML_Bool m_declAttributeIsCdata; - XML_Bool m_declAttributeIsId; + bool m_declAttributeIsCdata; + bool m_declAttributeIsId; DTD *m_dtd; const XML_Char *m_curBase; TAG *m_tagStack; @@ -865,11 +873,22 @@ expat_heap_increase_tolerable(XML_Parser rootParser, size_t increase, size_t newTotal = 0; bool tolerable = true; + // The idea is to subtract the amount of memory that was already + // allocated the last time that `XML_ParserReset` was called for + // this parser, the memory use of one document could skew the + // memory statso of the next document. + const size_t bytesAllocated + = (rootParser->m_alloc_tracker.bytesAllocatedWhenLastReset + > rootParser->m_alloc_tracker.bytesAllocated) + ? 0 + : (rootParser->m_alloc_tracker.bytesAllocated + - rootParser->m_alloc_tracker.bytesAllocatedWhenLastReset); + // Detect integer overflow - if (SIZE_MAX - rootParser->m_alloc_tracker.bytesAllocated < increase) { + if (SIZE_MAX - bytesAllocated < increase) { tolerable = false; } else { - newTotal = rootParser->m_alloc_tracker.bytesAllocated + increase; + newTotal = bytesAllocated + increase; if (newTotal >= rootParser->m_alloc_tracker.activationThresholdBytes) { assert(newTotal > 0); @@ -1449,7 +1468,7 @@ parserCreate(const XML_Char *encodingName, poolInit(&parser->m_tempPool, parser); poolInit(&parser->m_temp2Pool, parser); - parserInit(parser, encodingName); + parserInit(parser, encodingName, /*isReset=*/false); if (encodingName && ! parser->m_protocolEncodingName) { if (dtd) { @@ -1476,7 +1495,7 @@ parserCreate(const XML_Char *encodingName, } static void -parserInit(XML_Parser parser, const XML_Char *encodingName) { +parserInit(XML_Parser parser, const XML_Char *encodingName, bool isReset) { parser->m_processor = prologInitProcessor; XmlPrologStateInit(&parser->m_prologState); if (encodingName != NULL) { @@ -1524,8 +1543,8 @@ parserInit(XML_Parser parser, const XML_Char *encodingName) { parser->m_declAttributeType = NULL; parser->m_declNotationName = NULL; parser->m_declNotationPublicId = NULL; - parser->m_declAttributeIsCdata = XML_FALSE; - parser->m_declAttributeIsId = XML_FALSE; + parser->m_declAttributeIsCdata = false; + parser->m_declAttributeIsId = false; memset(&parser->m_position, 0, sizeof(POSITION)); parser->m_errorCode = XML_ERROR_NONE; parser->m_eventPtr = NULL; @@ -1544,6 +1563,7 @@ parserInit(XML_Parser parser, const XML_Char *encodingName) { parser->m_unknownEncodingRelease = NULL; parser->m_unknownEncodingData = NULL; parser->m_parsingStatus.parsing = XML_INITIALIZED; + parser->m_parsingStatus.finalBuffer = XML_FALSE; // Reentry can only be triggered inside m_processor calls parser->m_reenter = XML_FALSE; parser->m_handlerCallDepth = 0; @@ -1557,15 +1577,24 @@ parserInit(XML_Parser parser, const XML_Char *encodingName) { parser->m_hash_secret_salt_set = XML_FALSE; #if XML_GE == 1 - memset(&parser->m_accounting, 0, sizeof(ACCOUNTING)); - parser->m_accounting.debugLevel = getDebugLevel("EXPAT_ACCOUNTING_DEBUG", 0u); - parser->m_accounting.maximumAmplificationFactor - = EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT; - parser->m_accounting.activationThresholdBytes - = EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT; - - memset(&parser->m_entity_stats, 0, sizeof(ENTITY_STATS)); - parser->m_entity_stats.debugLevel = getDebugLevel("EXPAT_ENTITY_DEBUG", 0u); + parser->m_accounting.countBytesDirect = 0; + parser->m_accounting.countBytesIndirect = 0; + if (! isReset) { + parser->m_accounting.debugLevel + = getDebugLevel("EXPAT_ACCOUNTING_DEBUG", 0u); + parser->m_accounting.maximumAmplificationFactor + = EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT; + parser->m_accounting.activationThresholdBytes + = EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT; + } + + parser->m_entity_stats.countEverOpened = 0; + parser->m_entity_stats.currentDepth = 0; + parser->m_entity_stats.maximumDepthSeen = 0; + if (! isReset) + parser->m_entity_stats.debugLevel = getDebugLevel("EXPAT_ENTITY_DEBUG", 0u); +#else + UNUSED_P(isReset); #endif } @@ -1628,8 +1657,16 @@ XML_ParserReset(XML_Parser parser, const XML_Char *encodingName) { poolClear(&parser->m_temp2Pool); FREE(parser, (void *)parser->m_protocolEncodingName); parser->m_protocolEncodingName = NULL; - parserInit(parser, encodingName); + parserInit(parser, encodingName, /*isReset=*/true); dtdReset(parser->m_dtd, parser); + +#if XML_GE == 1 + parser->m_alloc_tracker.bytesAllocatedWhenLastReset + = parser->m_alloc_tracker.bytesAllocated; +#endif + + // NOTE: This effectively checks for `copyString` having failed during the + // call to `parserInit` above if (encodingName && ! parser->m_protocolEncodingName) { parser->m_errorCode = XML_ERROR_NO_MEMORY; return XML_FALSE; @@ -2299,13 +2336,12 @@ XML_SetHashSalt16Bytes(XML_Parser parser, const uint8_t entropy[16]) { enum XML_Status XMLCALL XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { - if ((parser == NULL) || (len < 0) || ((s == NULL) && (len != 0))) { - if (parser != NULL) - parser->m_errorCode = XML_ERROR_INVALID_ARGUMENT; + if (parser == NULL || isCalledFromInsideHandler(parser)) return XML_STATUS_ERROR; - } - if (isCalledFromInsideHandler(parser)) + if ((len < 0) || ((s == NULL) && (len != 0))) { + parser->m_errorCode = XML_ERROR_INVALID_ARGUMENT; return XML_STATUS_ERROR; + } switch (parser->m_parsingStatus.parsing) { case XML_SUSPENDED: parser->m_errorCode = XML_ERROR_SUSPENDED; @@ -2325,8 +2361,15 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { #if XML_CONTEXT_BYTES == 0 if (parser->m_bufferPtr == parser->m_bufferEnd) { - const char *end; - int nLeftOver; + // This null-object trick allows us to stop worrying about case `s == NULL` + // within this branch, e.g. with `s + len - end`. + const char *const empty = ""; + if (s == NULL) { + assert(len == 0); + s = empty; + } + const char *end = s + len; + size_t nLeftOver; enum XML_Status result; /* Detect overflow (a+b > MAX <==> b > MAX-a) */ if ((uint64_t)len > UINT64_MAX - parser->m_parseEndByteIndex) { @@ -2343,7 +2386,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { parser->m_parsingStatus.finalBuffer = (XML_Bool)isFinal; parser->m_errorCode - = callProcessor(parser, s, parser->m_parseEndPtr = s + len, &end); + = callProcessor(parser, s, parser->m_parseEndPtr = end, &end); if (parser->m_errorCode != XML_ERROR_NONE) { parser->m_eventEndPtr = parser->m_eventPtr; @@ -2373,8 +2416,14 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { // Back up and restore the parsing status to avoid XML_ERROR_SUSPENDED // (and XML_ERROR_FINISHED) from XML_GetBuffer. const enum XML_Parsing originalStatus = parser->m_parsingStatus.parsing; + if (nLeftOver > INT_MAX) { + parser->m_errorCode = XML_ERROR_NO_MEMORY; + parser->m_eventPtr = parser->m_eventEndPtr = NULL; + parser->m_processor = errorProcessor; + return XML_STATUS_ERROR; + } parser->m_parsingStatus.parsing = XML_PARSING; - void *const temp = XML_GetBuffer(parser, nLeftOver); + void *const temp = XML_GetBuffer(parser, (int)nLeftOver); parser->m_parsingStatus.parsing = originalStatus; // GetBuffer may have overwritten this, but we want to remember what the // app requested, not how many bytes were left over after parsing. @@ -2392,7 +2441,7 @@ XML_Parse(XML_Parser parser, const char *s, int len, int isFinal) { memcpy(parser->m_buffer, end, nLeftOver); } parser->m_bufferPtr = parser->m_buffer; - parser->m_bufferEnd = parser->m_buffer + nLeftOver; + parser->m_bufferEnd = EXPAT_SAFE_PTR_ADD(parser->m_buffer, nLeftOver); parser->m_positionPtr = parser->m_bufferPtr; parser->m_parseEndPtr = parser->m_bufferEnd; parser->m_eventPtr = parser->m_bufferPtr; @@ -3474,7 +3523,7 @@ externalEntityInitProcessor2(XML_Parser parser, const char *start, #if XML_GE == 1 if (! accountingDiffTolerated(parser, tok, start, next, __LINE__, XML_ACCOUNT_DIRECT)) { - accountingOnAbort(parser); + accountingOnAbort(parser, 0, __LINE__); *** 2310 LINES SKIPPED ***