Skip to content

Commit b370d7a

Browse files
[3.11] gh-158876: Update bundled Expat to 2.9.0 (GH-158881) (#160261)
(cherry picked from commit 0071fb5) (cherry picked from commit 25f598d) Co-authored-by: Petr Viktorin <encukou@gmail.com>
1 parent 6229895 commit b370d7a

17 files changed

Lines changed: 725 additions & 447 deletions

‎Makefile.pre.in‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,7 @@ LIBMPDEC_HEADERS= \
559559
# pyexpat's expat library
560560

561561
LIBEXPAT_OBJS= \
562+
Modules/expat/xcs.o \
562563
Modules/expat/xmlparse.o \
563564
Modules/expat/xmlrole.o \
564565
Modules/expat/xmltok.o
@@ -579,7 +580,7 @@ LIBEXPAT_HEADERS= \
579580
Modules/expat/pyexpatns.h \
580581
Modules/expat/siphash.h \
581582
Modules/expat/utf8tab.h \
582-
Modules/expat/xcsinc.c \
583+
Modules/expat/xcs.h \
583584
Modules/expat/xmlrole.h \
584585
Modules/expat/xmltok.h \
585586
Modules/expat/xmltok_impl.h
@@ -905,6 +906,9 @@ LIBEXPAT_CFLAGS=@LIBEXPAT_CFLAGS@ $(PY_STDMODULE_CFLAGS) $(CCSHARED)
905906
EXPAT_CFLAGS=@LIBEXPAT_CFLAGS@
906907
EXPAT_LDFLAGS=@LIBEXPAT_LDFLAGS@
907908

909+
Modules/expat/xcs.o: $(srcdir)/Modules/expat/xcs.c $(LIBEXPAT_HEADERS) $(PYTHON_HEADERS)
910+
$(CC) -c $(LIBEXPAT_CFLAGS) -o $@ $(srcdir)/Modules/expat/xcs.c
911+
908912
Modules/expat/xmlparse.o: $(srcdir)/Modules/expat/xmlparse.c $(LIBEXPAT_HEADERS) $(PYTHON_HEADERS)
909913
$(CC) -c $(LIBEXPAT_CFLAGS) -o $@ $(srcdir)/Modules/expat/xmlparse.c
910914

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

‎Modules/expat/expat.h‎

Lines changed: 72 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
#ifndef Expat_INCLUDED
4949
# define Expat_INCLUDED 1
5050

51-
# include <stdint.h> // for uint8_t
51+
# include <stdint.h> // for int64_t, uint8_t, uint64_t
5252
# include <stdlib.h>
5353
# include "expat_external.h"
5454

@@ -140,6 +140,26 @@ enum XML_Error {
140140
XML_ERROR_NOT_STARTED,
141141
};
142142

143+
/* Added in 2.9.0. */
144+
enum XML_Prop_Error {
145+
XML_PROP_ERROR_NONE = 0, // i.e. success
146+
147+
XML_PROP_ERROR_INVALID_KEY = 1, // i.e. the property is not known at all
148+
XML_PROP_ERROR_INVALID_TYPE = 2, // i.e. the property is known but expects a
149+
// different type (so a different
150+
// getter/setter would need to be called)
151+
XML_PROP_ERROR_INVALID_VALUE = 3, // i.e. the value is invalid (with a setter
152+
// function) or a NULL-pointer (with a
153+
// getter function)
154+
155+
XML_PROP_ERROR_PARSER_NULL = 4, // i.e. the parser argument is NULL
156+
XML_PROP_ERROR_PARSER_NOT_ROOT = 5, // i.e. the parser is not a root parser
157+
// but a subparser (and a root parser is
158+
// needed)
159+
160+
/* potentially more error codes upcoming here */
161+
};
162+
143163
enum XML_Content_Type {
144164
XML_CTYPE_EMPTY = 1,
145165
XML_CTYPE_ANY,
@@ -757,29 +777,6 @@ XML_GetSpecifiedAttributeCount(XML_Parser parser);
757777
XMLPARSEAPI(int)
758778
XML_GetIdAttributeIndex(XML_Parser parser);
759779

760-
# ifdef XML_ATTR_INFO
761-
/* Source file byte offsets for the start and end of attribute names and values.
762-
The value indices are exclusive of surrounding quotes; thus in a UTF-8 source
763-
file an attribute value of "blah" will yield:
764-
info->valueEnd - info->valueStart = 4 bytes.
765-
*/
766-
typedef struct {
767-
XML_Index nameStart; /* Offset to beginning of the attribute name. */
768-
XML_Index nameEnd; /* Offset after the attribute name's last byte. */
769-
XML_Index valueStart; /* Offset to beginning of the attribute value. */
770-
XML_Index valueEnd; /* Offset after the attribute value's last byte. */
771-
} XML_AttrInfo;
772-
773-
/* Returns an array of XML_AttrInfo structures for the attribute/value pairs
774-
passed in last call to the XML_StartElementHandler that were specified
775-
in the start-tag rather than defaulted. Each attribute/value pair counts
776-
as 1; thus the number of entries in the array is
777-
XML_GetSpecifiedAttributeCount(parser) / 2.
778-
*/
779-
XMLPARSEAPI(const XML_AttrInfo *)
780-
XML_GetAttributeInfo(XML_Parser parser);
781-
# endif
782-
783780
/* Parses some input. Returns XML_STATUS_ERROR if a fatal error is
784781
detected. The last call to XML_Parse must have isFinal true; len
785782
may be zero for this call (or any other).
@@ -964,15 +961,24 @@ XML_GetErrorCode(XML_Parser parser);
964961
return 0 to indicate an error.
965962
Note: XML_GetCurrentByteIndex returns -1 to indicate an error.
966963
*/
964+
XML_ATTR_DEPRECATED("please use XML_GetCurrentLineNumber64 instead")
967965
XMLPARSEAPI(XML_Size) XML_GetCurrentLineNumber(XML_Parser parser);
966+
XMLPARSEAPI(uint64_t) XML_GetCurrentLineNumber64(XML_Parser parser);
967+
XML_ATTR_DEPRECATED("please use XML_GetCurrentColumnNumber64 instead")
968968
XMLPARSEAPI(XML_Size) XML_GetCurrentColumnNumber(XML_Parser parser);
969+
XMLPARSEAPI(uint64_t) XML_GetCurrentColumnNumber64(XML_Parser parser);
970+
XML_ATTR_DEPRECATED("please use XML_GetCurrentByteIndex64 instead")
969971
XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
972+
XMLPARSEAPI(int64_t) XML_GetCurrentByteIndex64(XML_Parser parser);
970973

971974
/* Return the number of bytes in the current event.
972975
Returns 0 if the event is in an internal entity.
973976
*/
977+
XML_ATTR_DEPRECATED("please use XML_GetCurrentByteCount64 instead")
974978
XMLPARSEAPI(int)
975979
XML_GetCurrentByteCount(XML_Parser parser);
980+
XMLPARSEAPI(uint64_t)
981+
XML_GetCurrentByteCount64(XML_Parser parser);
976982

977983
/* If XML_CONTEXT_BYTES is >=1, returns the input buffer, sets
978984
the integer pointed to by offset to the offset within this buffer
@@ -984,8 +990,11 @@ XML_GetCurrentByteCount(XML_Parser parser);
984990
NOTE: The character pointer returned should not be used outside
985991
the handler that makes the call.
986992
*/
993+
XML_ATTR_DEPRECATED("please use XML_GetInputContext64 instead")
987994
XMLPARSEAPI(const char *)
988995
XML_GetInputContext(XML_Parser parser, int *offset, int *size);
996+
XMLPARSEAPI(const char *)
997+
XML_GetInputContext64(XML_Parser parser, int64_t *offset, uint64_t *size);
989998

990999
/* For backwards compatibility with previous versions. */
9911000
# define XML_GetErrorLineNumber XML_GetCurrentLineNumber
@@ -1040,14 +1049,15 @@ enum XML_FeatureEnum {
10401049
XML_FEATURE_UNICODE_WCHAR_T,
10411050
XML_FEATURE_DTD,
10421051
XML_FEATURE_CONTEXT_BYTES,
1052+
/* Added in Expat 1.95.5, removed in Expat 2.9.0. */
10431053
XML_FEATURE_MIN_SIZE,
10441054
XML_FEATURE_SIZEOF_XML_CHAR,
10451055
XML_FEATURE_SIZEOF_XML_LCHAR,
10461056
/* Added in Expat 2.0.0. */
10471057
XML_FEATURE_NS,
10481058
/* Added in Expat 2.0.1. */
10491059
XML_FEATURE_LARGE_SIZE,
1050-
/* Added in Expat 2.1.0. */
1060+
/* Added in Expat 2.1.0, removed in Expat 2.9.0. */
10511061
XML_FEATURE_ATTR_INFO,
10521062
/* Added in Expat 2.4.0. */
10531063
XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
@@ -1069,6 +1079,41 @@ typedef struct {
10691079
XMLPARSEAPI(const XML_Feature *)
10701080
XML_GetFeatureList(void);
10711081

1082+
/* Added in Expat 2.9.0. */
1083+
enum XML_Parser_Property {
1084+
# if defined(XML_TESTING)
1085+
XML_PROP_INVALID = 0,
1086+
# endif
1087+
# if XML_GE == 1
1088+
XML_PROP_ALLOC_TRACKER_ACTIVATION_THRESHOLD = 1, // of type `uint64_t`
1089+
XML_PROP_ALLOC_TRACKER_MAXIMUM_AMPLIFICATION = 2, // of type `double`
1090+
XML_PROP_BILLION_LAUGHS_ACTIVATION_THRESHOLD = 3, // of type `uint64_t`
1091+
XML_PROP_BILLION_LAUGHS_MAXIMUM_AMPLIFICATION = 4, // of type `double`
1092+
# endif
1093+
XML_PROP_REPARSE_DEFERRAL_ENABLED = 5, // of type `XML_Bool`
1094+
/* more properties upcoming here */
1095+
};
1096+
1097+
/* Added in Expat 2.9.0. */
1098+
XMLPARSEAPI(enum XML_Prop_Error)
1099+
XML_GetPropertyBool(XML_Parser parser, enum XML_Parser_Property property,
1100+
XML_Bool *value);
1101+
XMLPARSEAPI(enum XML_Prop_Error)
1102+
XML_GetPropertyDouble(XML_Parser parser, enum XML_Parser_Property property,
1103+
double *value);
1104+
XMLPARSEAPI(enum XML_Prop_Error)
1105+
XML_GetPropertyUInt64(XML_Parser parser, enum XML_Parser_Property property,
1106+
uint64_t *value);
1107+
XMLPARSEAPI(enum XML_Prop_Error)
1108+
XML_SetPropertyBool(XML_Parser parser, enum XML_Parser_Property property,
1109+
XML_Bool value);
1110+
XMLPARSEAPI(enum XML_Prop_Error)
1111+
XML_SetPropertyDouble(XML_Parser parser, enum XML_Parser_Property property,
1112+
double value);
1113+
XMLPARSEAPI(enum XML_Prop_Error)
1114+
XML_SetPropertyUInt64(XML_Parser parser, enum XML_Parser_Property property,
1115+
uint64_t value);
1116+
10721117
# if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1)
10731118
/* Added in Expat 2.4.0 for XML_DTD defined and
10741119
* added in Expat 2.6.0 for XML_GE == 1. */
@@ -1101,8 +1146,8 @@ XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
11011146
See https://semver.org
11021147
*/
11031148
# define XML_MAJOR_VERSION 2
1104-
# define XML_MINOR_VERSION 8
1105-
# define XML_MICRO_VERSION 5
1149+
# define XML_MINOR_VERSION 9
1150+
# define XML_MICRO_VERSION 0
11061151

11071152
# ifdef __cplusplus
11081153
}

‎Modules/expat/expat_external.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ typedef char XML_LChar;
169169
# endif /* XML_UNICODE */
170170

171171
# ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */
172+
# if defined(__clang__) || defined(__GNUC__)
173+
# warning Macro XML_LARGE_SIZE is deprecated, please use the 64bit location API functions instead.
174+
# endif
172175
typedef long long XML_Index;
173176
typedef unsigned long long XML_Size;
174177
# else

‎Modules/expat/internal.h‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@
5656
#if ! defined(INTERNAL_H)
5757
# define INTERNAL_H 1
5858

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 */
59+
# if ! defined(inline)
60+
# ifdef __GNUC__
61+
# define inline __inline
62+
# endif /* __GNUC__ */
63+
# endif
6664

6765
# ifndef inline
6866
# define inline

‎Modules/expat/pyexpatns.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,22 @@
5050
#define XML_GetBase PyExpat_XML_GetBase
5151
#define XML_GetBuffer PyExpat_XML_GetBuffer
5252
#define XML_GetCurrentByteCount PyExpat_XML_GetCurrentByteCount
53+
#define XML_GetCurrentByteCount64 PyExpat_XML_GetCurrentByteCount64
5354
#define XML_GetCurrentByteIndex PyExpat_XML_GetCurrentByteIndex
55+
#define XML_GetCurrentByteIndex64 PyExpat_XML_GetCurrentByteIndex64
5456
#define XML_GetCurrentColumnNumber PyExpat_XML_GetCurrentColumnNumber
57+
#define XML_GetCurrentColumnNumber64 PyExpat_XML_GetCurrentColumnNumber64
5558
#define XML_GetCurrentLineNumber PyExpat_XML_GetCurrentLineNumber
59+
#define XML_GetCurrentLineNumber64 PyExpat_XML_GetCurrentLineNumber64
5660
#define XML_GetErrorCode PyExpat_XML_GetErrorCode
5761
#define XML_GetFeatureList PyExpat_XML_GetFeatureList
5862
#define XML_GetIdAttributeIndex PyExpat_XML_GetIdAttributeIndex
5963
#define XML_GetInputContext PyExpat_XML_GetInputContext
64+
#define XML_GetInputContext64 PyExpat_XML_GetInputContext64
6065
#define XML_GetParsingStatus PyExpat_XML_GetParsingStatus
66+
#define XML_GetPropertyBool PyExpat_XML_GetPropertyBool
67+
#define XML_GetPropertyDouble PyExpat_XML_GetPropertyDouble
68+
#define XML_GetPropertyUInt64 PyExpat_XML_GetPropertyUInt64
6169
#define XML_GetSpecifiedAttributeCount PyExpat_XML_GetSpecifiedAttributeCount
6270
#define XmlGetUtf16InternalEncoding PyExpat_XmlGetUtf16InternalEncoding
6371
#define XmlGetUtf16InternalEncodingNS PyExpat_XmlGetUtf16InternalEncodingNS
@@ -110,6 +118,9 @@
110118
#define XML_SetNotStandaloneHandler PyExpat_XML_SetNotStandaloneHandler
111119
#define XML_SetParamEntityParsing PyExpat_XML_SetParamEntityParsing
112120
#define XML_SetProcessingInstructionHandler PyExpat_XML_SetProcessingInstructionHandler
121+
#define XML_SetPropertyBool PyExpat_XML_SetPropertyBool
122+
#define XML_SetPropertyDouble PyExpat_XML_SetPropertyDouble
123+
#define XML_SetPropertyUInt64 PyExpat_XML_SetPropertyUInt64
113124
#define XML_SetReparseDeferralEnabled PyExpat_XML_SetReparseDeferralEnabled
114125
#define XML_SetReturnNSTriplet PyExpat_XML_SetReturnNSTriplet
115126
#define XML_SetSkippedEntityHandler PyExpat_XML_SetSkippedEntityHandler

‎Modules/expat/refresh.sh‎

Lines changed: 5 additions & 4 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_5"
16-
expected_libexpat_version="2.8.5"
17-
expected_libexpat_sha256="920dde485e15eda0cce8d2310b41d492c534e5e3d89ad407a0b4176dd2ff88fe"
15+
expected_libexpat_tag="R_2_9_0"
16+
expected_libexpat_version="2.9.0"
17+
expected_libexpat_sha256="16afbb9cefead2aa278105cf27d9f597bde7fbf3dbb85015857ca7ca6a4e89ba"
1818

1919
expat_dir="$(realpath "$(dirname -- "${BASH_SOURCE[0]}")")"
2020
cd ${expat_dir}
@@ -43,7 +43,8 @@ lib_files=(
4343
siphash.h
4444
utf8tab.h
4545
winconfig.h
46-
xcsinc.c
46+
xcs.c
47+
xcs.h
4748
xmlparse.c
4849
xmlrole.c
4950
xmlrole.h

‎Modules/expat/xcs.c‎

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*
2+
__ __ _
3+
___\ \/ /_ __ __ _| |_
4+
/ _ \\ /| '_ \ / _` | __|
5+
| __// \| |_) | (_| | |_
6+
\___/_/\_\ .__/ \__,_|\__|
7+
|_| XML parser
8+
9+
Copyright (c) 2022-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+
#include "xcs.h"
35+
36+
#if defined(XML_UNICODE)
37+
# if defined(XML_UNICODE_WCHAR_T)
38+
# include <wchar.h> // for wcscmp, wcslen, wcsncmp
39+
# endif
40+
#else
41+
# include <string.h> // for strcmp, strlen, strncmp
42+
#endif
43+
44+
size_t
45+
xcslen(const XML_Char *s) {
46+
#ifdef XML_UNICODE
47+
# ifdef XML_UNICODE_WCHAR_T
48+
return wcslen(s);
49+
# else
50+
// XML_Char is unsigned short
51+
size_t len = 0;
52+
while (s[len]) {
53+
len++;
54+
}
55+
return len;
56+
# endif
57+
#else
58+
return strlen(s);
59+
#endif
60+
}
61+
62+
int
63+
xcscmp(const XML_Char *a, const XML_Char *b) {
64+
#if defined(XML_UNICODE)
65+
# if defined(XML_UNICODE_WCHAR_T)
66+
return wcscmp(a, b);
67+
# else
68+
for (; a[0] && b[0] && a[0] == b[0]; a++, b++)
69+
;
70+
return a[0] - b[0];
71+
# endif
72+
#else
73+
return strcmp(a, b);
74+
#endif
75+
}
76+
77+
int
78+
xcsncmp(const XML_Char *a, const XML_Char *b, size_t len) {
79+
#if defined(XML_UNICODE)
80+
# if defined(XML_UNICODE_WCHAR_T)
81+
return wcsncmp(a, b, len);
82+
# else
83+
for (; len > 0 && a[0] && b[0] && a[0] == b[0]; len--, a++, b++) {
84+
}
85+
return (len == 0) ? 0 : (a[0] - b[0]);
86+
# endif
87+
#else
88+
return strncmp(a, b, len);
89+
#endif
90+
}

0 commit comments

Comments
 (0)