Skip to content

Commit 4fda068

Browse files
[3.10] gh-157953: Update bundled Expat to 2.8.5 (GH-157957) (#158327)
(cherry picked from commit 5f1f218) (cherry picked from commit 721007e)
1 parent 812b4df commit 4fda068

18 files changed

Lines changed: 538 additions & 431 deletions

Misc/NEWS.d/next/Security/2026-08-31-16-47-33.gh-issue-156723.KxCF5N.rst renamed to Misc/NEWS.d/next/Security/2026-08-31-16-47-33.gh-issue-157953.KxCF5N.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Update bundled `libexpat <https://libexpat.github.io/>`_ to version 2.8.4.
1+
Update bundled `libexpat <https://libexpat.github.io/>`_ to version 2.8.5.

‎Modules/expat/expat.h‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>
2121
Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp>
2222
Copyright (c) 2025 Matthew Fernandez <matthew.fernandez@gmail.com>
23+
Copyright (c) 2026 Braian Plaku <braianplaku@gmail.com>
2324
Licensed under the MIT license:
2425
2526
Permission is hereby granted, free of charge, to any person obtaining
@@ -921,7 +922,9 @@ XML_SetParamEntityParsing(XML_Parser parser,
921922
Returns 1 if successful, 0 when called after parsing has started.
922923
Note: If parser == NULL, the function will do nothing and return 0.
923924
DEPRECATED since Expat 2.8.0.
925+
Please use XML_SetHashSalt16Bytes instead.
924926
*/
927+
XML_ATTR_DEPRECATED("please use XML_SetHashSalt16Bytes instead")
925928
XMLPARSEAPI(int)
926929
XML_SetHashSalt(XML_Parser parser, unsigned long hash_salt);
927930

@@ -1040,8 +1043,11 @@ enum XML_FeatureEnum {
10401043
XML_FEATURE_MIN_SIZE,
10411044
XML_FEATURE_SIZEOF_XML_CHAR,
10421045
XML_FEATURE_SIZEOF_XML_LCHAR,
1046+
/* Added in Expat 2.0.0. */
10431047
XML_FEATURE_NS,
1048+
/* Added in Expat 2.0.1. */
10441049
XML_FEATURE_LARGE_SIZE,
1050+
/* Added in Expat 2.1.0. */
10451051
XML_FEATURE_ATTR_INFO,
10461052
/* Added in Expat 2.4.0. */
10471053
XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
@@ -1096,7 +1102,7 @@ XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
10961102
*/
10971103
# define XML_MAJOR_VERSION 2
10981104
# define XML_MINOR_VERSION 8
1099-
# define XML_MICRO_VERSION 4
1105+
# define XML_MICRO_VERSION 5
11001106

11011107
# ifdef __cplusplus
11021108
}

‎Modules/expat/expat_external.h‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Copyright (c) 2017 Rhodri James <rhodri@wildebeest.org.uk>
1717
Copyright (c) 2018 Yury Gribov <tetra2005@gmail.com>
1818
Copyright (c) 2026 Matthew Fernandez <matthew.fernandez@gmail.com>
19+
Copyright (c) 2026 Braian Plaku <braianplaku@gmail.com>
1920
Licensed under the MIT license:
2021
2122
Permission is hereby granted, free of charge, to any person obtaining
@@ -128,6 +129,17 @@
128129
# define XML_ATTR_ALLOC_SIZE(x)
129130
# endif
130131

132+
/* Marks a function that Expat still provides but that callers should move off
133+
of. */
134+
# if defined(__clang__) || defined(__GNUC__)
135+
# define XML_ATTR_DEPRECATED(message) \
136+
__attribute__((__deprecated__(message)))
137+
# elif defined(_MSC_VER)
138+
# define XML_ATTR_DEPRECATED(message) __declspec(deprecated(message))
139+
# else
140+
# define XML_ATTR_DEPRECATED(message) // empty i.e. no deprecation
141+
# endif
142+
131143
# define XMLPARSEAPI(type) XMLIMPORT type XMLCALL
132144

133145
# ifdef __cplusplus

‎Modules/expat/hash_table.h‎

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/* Hash table related internal API
2+
__ __ _
3+
___\ \/ /_ __ __ _| |_
4+
/ _ \\ /| '_ \ / _` | __|
5+
| __// \| |_) | (_| | |_
6+
\___/_/\_\ .__/ \__,_|\__|
7+
|_| XML parser
8+
9+
Copyright (c) 2026 Sebastian Pipping <sebastian@pipping.org>
10+
Licensed under the MIT license:
11+
12+
Permission is hereby granted, free of charge, to any person obtaining
13+
a copy of this software and associated documentation files (the
14+
"Software"), to deal in the Software without restriction, including
15+
without limitation the rights to use, copy, modify, merge, publish,
16+
distribute, sublicense, and/or sell copies of the Software, and to permit
17+
persons to whom the Software is furnished to do so, subject to the
18+
following conditions:
19+
20+
The above copyright notice and this permission notice shall be included
21+
in all copies or substantial portions of the Software.
22+
23+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
26+
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
27+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
28+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
29+
USE OR OTHER DEALINGS IN THE SOFTWARE.
30+
31+
SPDX-License-Identifier: MIT
32+
*/
33+
34+
#if ! defined(HASH_TABLE_H)
35+
# define HASH_TABLE_H 1
36+
37+
# include "expat.h" // for XML_Bool, XML_Parser
38+
# include "internal.h" // for XML_NONTESTING_STATIC
39+
40+
# include <stddef.h> // for size_t
41+
42+
typedef const XML_Char *KEY;
43+
44+
typedef struct {
45+
KEY name;
46+
} NAMED;
47+
48+
typedef struct {
49+
NAMED **v;
50+
unsigned char power;
51+
size_t size;
52+
size_t used;
53+
XML_Parser parser;
54+
} HASH_TABLE;
55+
56+
typedef struct {
57+
NAMED **p;
58+
NAMED **end;
59+
} HASH_TABLE_ITER;
60+
61+
XML_NONTESTING_STATIC NAMED *lookupWithLength(XML_Parser parser,
62+
HASH_TABLE *table, KEY name,
63+
size_t nameLen,
64+
size_t createSize);
65+
XML_NONTESTING_STATIC NAMED *lookup(XML_Parser parser, HASH_TABLE *table,
66+
KEY name, size_t createSize);
67+
68+
XML_NONTESTING_STATIC void hashTableInit(HASH_TABLE *table, XML_Parser parser);
69+
XML_NONTESTING_STATIC void hashTableClear(HASH_TABLE *table);
70+
XML_NONTESTING_STATIC void hashTableDestroy(HASH_TABLE *table);
71+
XML_NONTESTING_STATIC void hashTableIterInit(HASH_TABLE_ITER *iter,
72+
const HASH_TABLE *table);
73+
XML_NONTESTING_STATIC NAMED *hashTableIterNext(HASH_TABLE_ITER *iter);
74+
75+
XML_NONTESTING_STATIC XML_Bool keyeq(KEY s1, size_t s1len, KEY s2);
76+
XML_NONTESTING_STATIC size_t keylen(KEY s);
77+
78+
#endif // ! defined(HASH_TABLE_H)

‎Modules/expat/internal.h‎

Lines changed: 68 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
The following calling convention macros are defined for frequently
77
called functions:
88
9-
FASTCALL - Used for those internal functions that have a simple
10-
body and a low number of arguments and local variables.
11-
12-
PTRCALL - Used for functions called though function pointers.
13-
14-
PTRFASTCALL - Like PTRCALL, but for low number of arguments.
15-
169
inline - Used for selected internal functions for which inlining
1710
may improve performance on some platforms.
1811
@@ -34,6 +27,8 @@
3427
Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com>
3528
Copyright (c) 2024 Taichi Haradaguchi <20001722@ymail.ne.jp>
3629
Copyright (c) 2026 Matthew Wozniczka <mattheww@simba.com>
30+
Copyright (c) 2026 Braian Plaku <braianplaku@gmail.com>
31+
Copyright (c) 2026 Florian Schmaus <florian.schmaus@codasip.com>
3732
Licensed under the MIT license:
3833
3934
Permission is hereby granted, free of charge, to any person obtaining
@@ -58,132 +53,104 @@
5853
SPDX-License-Identifier: MIT
5954
*/
6055

61-
#if defined(__GNUC__) && defined(__i386__) && ! defined(__MINGW32__)
62-
/* We'll use this version by default only where we know it helps.
63-
64-
regparm() generates warnings on Solaris boxes. See SF bug #692878.
65-
66-
Instability reported with egcs on a RedHat Linux 7.3.
67-
Let's comment out:
68-
#define FASTCALL __attribute__((stdcall, regparm(3)))
69-
and let's try this:
70-
*/
71-
# define FASTCALL __attribute__((regparm(3)))
72-
# define PTRFASTCALL __attribute__((regparm(3)))
73-
#endif
74-
75-
/* Using __fastcall seems to have an unexpected negative effect under
76-
MS VC++, especially for function pointers, so we won't use it for
77-
now on that platform. It may be reconsidered for a future release
78-
if it can be made more effective.
79-
Likely reason: __fastcall on Windows is like stdcall, therefore
80-
the compiler cannot perform stack optimizations for call clusters.
81-
*/
82-
83-
/* Make sure all of these are defined if they aren't already. */
84-
85-
#ifndef FASTCALL
86-
# define FASTCALL
87-
#endif
56+
#if ! defined(INTERNAL_H)
57+
# define INTERNAL_H 1
8858

89-
#ifndef PTRCALL
90-
# define PTRCALL
91-
#endif
92-
93-
#ifndef PTRFASTCALL
94-
# define PTRFASTCALL
95-
#endif
96-
97-
#ifndef XML_MIN_SIZE
98-
# if ! defined(__cplusplus) && ! defined(inline)
99-
# ifdef __GNUC__
100-
# define inline __inline
101-
# endif /* __GNUC__ */
102-
# endif
103-
#endif /* XML_MIN_SIZE */
59+
# ifndef XML_MIN_SIZE
60+
# if ! defined(inline)
61+
# ifdef __GNUC__
62+
# define inline __inline
63+
# endif /* __GNUC__ */
64+
# endif
65+
# endif /* XML_MIN_SIZE */
10466

105-
#ifdef __cplusplus
106-
# define inline inline
107-
#else
10867
# ifndef inline
10968
# define inline
11069
# endif
111-
#endif
112-
113-
#include <limits.h> // ULONG_MAX
114-
#include <stddef.h> // size_t
115-
116-
#if defined(_WIN32) \
117-
&& (! defined(__USE_MINGW_ANSI_STDIO) \
118-
|| (1 - __USE_MINGW_ANSI_STDIO - 1 == 0))
119-
# define EXPAT_FMT_LLX(midpart) "%" midpart "I64x"
120-
# define EXPAT_FMT_ULL(midpart) "%" midpart "I64u"
121-
# if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW
122-
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d"
123-
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u"
70+
71+
# if ! defined(XML_NONTESTING_STATIC)
72+
# if defined(XML_TESTING)
73+
# define XML_NONTESTING_STATIC // empty i.e. not static
74+
# else
75+
# define XML_NONTESTING_STATIC static
76+
# endif
77+
# endif
78+
79+
# include <limits.h> // ULONG_MAX
80+
# include <stddef.h> // size_t
81+
82+
# if defined(_WIN32) \
83+
&& (! defined(__USE_MINGW_ANSI_STDIO) \
84+
|| (1 - __USE_MINGW_ANSI_STDIO - 1 == 0))
85+
# define EXPAT_FMT_LLX(midpart) "%" midpart "I64x"
86+
# define EXPAT_FMT_ULL(midpart) "%" midpart "I64u"
87+
# if defined(_WIN64) // Note: modifiers "td" and "zu" do not work for MinGW
88+
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d"
89+
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "I64u"
90+
# else
91+
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
92+
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
93+
# endif
12494
# else
125-
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
126-
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart "u"
95+
# include <inttypes.h> // PRIdPTR, PRIuPTR
96+
# define EXPAT_FMT_LLX(midpart) "%" midpart "llx"
97+
# define EXPAT_FMT_ULL(midpart) "%" midpart "llu"
98+
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart PRIdPTR
99+
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart PRIuPTR
100+
# endif
101+
102+
# ifndef UNUSED_P
103+
# define UNUSED_P(p) (void)p
127104
# endif
128-
#else
129-
# include <inttypes.h> // PRIdPTR, PRIuPTR
130-
# define EXPAT_FMT_LLX(midpart) "%" midpart "llx"
131-
# define EXPAT_FMT_ULL(midpart) "%" midpart "llu"
132-
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart PRIdPTR
133-
# define EXPAT_FMT_SIZE_T(midpart) "%" midpart PRIuPTR
134-
#endif
135-
136-
#ifndef UNUSED_P
137-
# define UNUSED_P(p) (void)p
138-
#endif
139105

140106
/* NOTE BEGIN If you ever patch these defaults to greater values
141107
for non-attack XML payload in your environment,
142108
please file a bug report with libexpat. Thank you!
143109
*/
144-
#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \
145-
100.0f
146-
#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \
147-
8388608 // 8 MiB, 2^23
110+
# define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \
111+
100.0f
112+
# define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \
113+
8388608 // 8 MiB, 2^23
148114

149-
#define EXPAT_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION_DEFAULT 100.0f
150-
#define EXPAT_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT \
151-
67108864 // 64 MiB, 2^26
115+
# define EXPAT_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION_DEFAULT 100.0f
116+
# define EXPAT_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT \
117+
67108864 // 64 MiB, 2^26
152118

153119
// NOTE: If function expat_alloc was user facing, EXPAT_MALLOC_ALIGNMENT would
154120
// have to take sizeof(long double) into account
155-
#define EXPAT_MALLOC_ALIGNMENT sizeof(long long) // largest parser (sub)member
156-
#define EXPAT_MALLOC_PADDING ((EXPAT_MALLOC_ALIGNMENT) - sizeof(size_t))
121+
union expat_align {
122+
long long l;
123+
void *p;
124+
};
125+
# define EXPAT_MALLOC_ALIGNMENT sizeof(union expat_align)
126+
# define EXPAT_MALLOC_PADDING ((EXPAT_MALLOC_ALIGNMENT) - sizeof(size_t))
157127

158128
/* NOTE END */
159129

160-
#include "expat.h" // so we can use type XML_Parser below
161-
162-
#ifdef __cplusplus
163-
extern "C" {
164-
#endif
130+
# include "expat.h" // so we can use type XML_Parser below
165131

166132
void _INTERNAL_trim_to_complete_utf8_characters(const char *from,
167133
const char **fromLimRef);
168134

169-
#if defined(XML_GE) && XML_GE == 1
135+
# if defined(XML_GE) && XML_GE == 1
170136
unsigned long long testingAccountingGetCountBytesDirect(XML_Parser parser);
171137
unsigned long long testingAccountingGetCountBytesIndirect(XML_Parser parser);
172138
const char *unsignedCharToPrintable(unsigned char c);
173-
#endif
139+
# endif
174140

175141
extern
176-
#if ! defined(XML_TESTING)
142+
# if ! defined(XML_TESTING)
177143
const
178-
#endif
144+
# endif
179145
XML_Bool g_reparseDeferralEnabledDefault; // written ONLY in runtests.c
180-
#if defined(XML_TESTING)
146+
# if defined(XML_TESTING)
147+
148+
int xmlSetHashSalt(XML_Parser parser, unsigned long hash_salt);
149+
181150
void *expat_malloc(XML_Parser parser, size_t size, int sourceLine);
182151
void expat_free(XML_Parser parser, void *ptr, int sourceLine);
183152
void *expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine);
184153
extern unsigned int g_bytesScanned; // used for testing only
185-
#endif
154+
# endif
186155

187-
#ifdef __cplusplus
188-
}
189-
#endif
156+
#endif // not defined INTERNAL_H

‎Modules/expat/refresh.sh‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ fi
1212

1313
# Update this when updating to a new version after verifying that the changes
1414
# the update brings in are good. These values are used for verifying the SBOM, too.
15-
expected_libexpat_tag="R_2_8_4"
16-
expected_libexpat_version="2.8.4"
17-
expected_libexpat_sha256="b8ece2437692dad44d851c4532723390a5a330990007706be9c8d2b90d294f36"
15+
expected_libexpat_tag="R_2_8_5"
16+
expected_libexpat_version="2.8.5"
17+
expected_libexpat_sha256="920dde485e15eda0cce8d2310b41d492c534e5e3d89ad407a0b4176dd2ff88fe"
1818

1919
expat_dir="$(realpath "$(dirname -- "${BASH_SOURCE[0]}")")"
2020
cd ${expat_dir}
@@ -34,6 +34,7 @@ lib_files=(
3434
expat.h
3535
expat_external.h
3636
fallthrough.h
37+
hash_table.h
3738
iasciitab.h
3839
internal.h
3940
latin1tab.h

0 commit comments

Comments
 (0)