Skip to content

Commit 48d0d0d

Browse files
gh-139312: Update bundled libexpat to 2.7.3 (GH-139319)
+ Blurb + Update sbom.spdx.json
1 parent 93ac352 commit 48d0d0d

File tree

7 files changed

+58
-35
lines changed

7 files changed

+58
-35
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade bundled libexpat to 2.7.3

Misc/sbom.spdx.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/expat/expat.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Copyright (c) 2023 Hanno Böck <[email protected]>
2020
Copyright (c) 2023 Sony Corporation / Snild Dolkow <[email protected]>
2121
Copyright (c) 2024 Taichi Haradaguchi <[email protected]>
22+
Copyright (c) 2025 Matthew Fernandez <[email protected]>
2223
Licensed under the MIT license:
2324
2425
Permission is hereby granted, free of charge, to any person obtaining
@@ -276,7 +277,7 @@ XML_ParserCreate_MM(const XML_Char *encoding,
276277

277278
/* Prepare a parser object to be reused. This is particularly
278279
valuable when memory allocation overhead is disproportionately high,
279-
such as when a large number of small documnents need to be parsed.
280+
such as when a large number of small documents need to be parsed.
280281
All handlers are cleared from the parser, except for the
281282
unknownEncodingHandler. The parser's external state is re-initialized
282283
except for the values of ns and ns_triplets.
@@ -1081,7 +1082,7 @@ XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
10811082
*/
10821083
# define XML_MAJOR_VERSION 2
10831084
# define XML_MINOR_VERSION 7
1084-
# define XML_MICRO_VERSION 2
1085+
# define XML_MICRO_VERSION 3
10851086

10861087
# ifdef __cplusplus
10871088
}

Modules/expat/internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@
108108
#endif
109109

110110
#include <limits.h> // ULONG_MAX
111+
#include <stddef.h> // size_t
111112

112113
#if defined(_WIN32) \
113114
&& (! defined(__USE_MINGW_ANSI_STDIO) \
@@ -153,6 +154,11 @@
153154
#define EXPAT_ALLOC_TRACKER_ACTIVATION_THRESHOLD_DEFAULT \
154155
67108864 // 64 MiB, 2^26
155156

157+
// NOTE: If function expat_alloc was user facing, EXPAT_MALLOC_ALIGNMENT would
158+
// have to take sizeof(long double) into account
159+
#define EXPAT_MALLOC_ALIGNMENT sizeof(long long) // largest parser (sub)member
160+
#define EXPAT_MALLOC_PADDING ((EXPAT_MALLOC_ALIGNMENT) - sizeof(size_t))
161+
156162
/* NOTE END */
157163

158164
#include "expat.h" // so we can use type XML_Parser below

Modules/expat/refresh.sh

Lines changed: 3 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_7_2"
16-
expected_libexpat_version="2.7.2"
17-
expected_libexpat_sha256="13d42a125897329bfeecab899cb9b5a3ec8c26072994b5cd4c41f28241f5bce7"
15+
expected_libexpat_tag="R_2_7_3"
16+
expected_libexpat_version="2.7.3"
17+
expected_libexpat_sha256="821ac9710d2c073eaf13e1b1895a9c9aa66c1157a99635c639fbff65cdbdd732"
1818

1919
expat_dir="$(realpath "$(dirname -- "${BASH_SOURCE[0]}")")"
2020
cd ${expat_dir}

Modules/expat/xmlparse.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* 60e137abb91af642d6c3988f8f133d23329b32638659c74d47125fc0faf6ddd5 (2.7.2+)
1+
/* 28bcd8b1ba7eb595d82822908257fd9c3589b4243e3c922d0369f35bfcd7b506 (2.7.3+)
22
__ __ _
33
___\ \/ /_ __ __ _| |_
44
/ _ \\ /| '_ \ / _` | __|
@@ -41,6 +41,7 @@
4141
Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <[email protected]>
4242
Copyright (c) 2024-2025 Berkay Eren Ürün <[email protected]>
4343
Copyright (c) 2024 Hanno Böck <[email protected]>
44+
Copyright (c) 2025 Matthew Fernandez <[email protected]>
4445
Licensed under the MIT license:
4546
4647
Permission is hereby granted, free of charge, to any person obtaining
@@ -850,14 +851,14 @@ static void *
850851
# endif
851852
expat_malloc(XML_Parser parser, size_t size, int sourceLine) {
852853
// Detect integer overflow
853-
if (SIZE_MAX - size < sizeof(size_t)) {
854+
if (SIZE_MAX - size < sizeof(size_t) + EXPAT_MALLOC_PADDING) {
854855
return NULL;
855856
}
856857

857858
const XML_Parser rootParser = getRootParserOf(parser, NULL);
858859
assert(rootParser->m_parentParser == NULL);
859860

860-
const size_t bytesToAllocate = sizeof(size_t) + size;
861+
const size_t bytesToAllocate = sizeof(size_t) + EXPAT_MALLOC_PADDING + size;
861862

862863
if ((XmlBigCount)-1 - rootParser->m_alloc_tracker.bytesAllocated
863864
< bytesToAllocate) {
@@ -894,7 +895,7 @@ expat_malloc(XML_Parser parser, size_t size, int sourceLine) {
894895
rootParser->m_alloc_tracker.peakBytesAllocated, sourceLine);
895896
}
896897

897-
return (char *)mallocedPtr + sizeof(size_t);
898+
return (char *)mallocedPtr + sizeof(size_t) + EXPAT_MALLOC_PADDING;
898899
}
899900

900901
# if defined(XML_TESTING)
@@ -914,8 +915,9 @@ expat_free(XML_Parser parser, void *ptr, int sourceLine) {
914915

915916
// Extract size (to the eyes of malloc_fcn/realloc_fcn) and
916917
// the original pointer returned by malloc/realloc
917-
void *const mallocedPtr = (char *)ptr - sizeof(size_t);
918-
const size_t bytesAllocated = sizeof(size_t) + *(size_t *)mallocedPtr;
918+
void *const mallocedPtr = (char *)ptr - EXPAT_MALLOC_PADDING - sizeof(size_t);
919+
const size_t bytesAllocated
920+
= sizeof(size_t) + EXPAT_MALLOC_PADDING + *(size_t *)mallocedPtr;
919921

920922
// Update accounting
921923
assert(rootParser->m_alloc_tracker.bytesAllocated >= bytesAllocated);
@@ -954,7 +956,7 @@ expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine) {
954956

955957
// Extract original size (to the eyes of the caller) and the original
956958
// pointer returned by malloc/realloc
957-
void *mallocedPtr = (char *)ptr - sizeof(size_t);
959+
void *mallocedPtr = (char *)ptr - EXPAT_MALLOC_PADDING - sizeof(size_t);
958960
const size_t prevSize = *(size_t *)mallocedPtr;
959961

960962
// Classify upcoming change
@@ -969,8 +971,13 @@ expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine) {
969971
}
970972
}
971973

974+
// NOTE: Integer overflow detection has already been done for us
975+
// by expat_heap_increase_tolerable(..) above
976+
assert(SIZE_MAX - sizeof(size_t) - EXPAT_MALLOC_PADDING >= size);
977+
972978
// Actually allocate
973-
mallocedPtr = parser->m_mem.realloc_fcn(mallocedPtr, sizeof(size_t) + size);
979+
mallocedPtr = parser->m_mem.realloc_fcn(
980+
mallocedPtr, sizeof(size_t) + EXPAT_MALLOC_PADDING + size);
974981

975982
if (mallocedPtr == NULL) {
976983
return NULL;
@@ -1001,7 +1008,7 @@ expat_realloc(XML_Parser parser, void *ptr, size_t size, int sourceLine) {
10011008
// Update in-block recorded size
10021009
*(size_t *)mallocedPtr = size;
10031010

1004-
return (char *)mallocedPtr + sizeof(size_t);
1011+
return (char *)mallocedPtr + sizeof(size_t) + EXPAT_MALLOC_PADDING;
10051012
}
10061013
#endif // XML_GE == 1
10071014

@@ -1337,7 +1344,8 @@ parserCreate(const XML_Char *encodingName,
13371344
XML_Parser parser = NULL;
13381345

13391346
#if XML_GE == 1
1340-
const size_t increase = sizeof(size_t) + sizeof(struct XML_ParserStruct);
1347+
const size_t increase
1348+
= sizeof(size_t) + EXPAT_MALLOC_PADDING + sizeof(struct XML_ParserStruct);
13411349

13421350
if (parentParser != NULL) {
13431351
const XML_Parser rootParser = getRootParserOf(parentParser, NULL);
@@ -1352,11 +1360,13 @@ parserCreate(const XML_Char *encodingName,
13521360
if (memsuite) {
13531361
XML_Memory_Handling_Suite *mtemp;
13541362
#if XML_GE == 1
1355-
void *const sizeAndParser = memsuite->malloc_fcn(
1356-
sizeof(size_t) + sizeof(struct XML_ParserStruct));
1363+
void *const sizeAndParser
1364+
= memsuite->malloc_fcn(sizeof(size_t) + EXPAT_MALLOC_PADDING
1365+
+ sizeof(struct XML_ParserStruct));
13571366
if (sizeAndParser != NULL) {
13581367
*(size_t *)sizeAndParser = sizeof(struct XML_ParserStruct);
1359-
parser = (XML_Parser)((char *)sizeAndParser + sizeof(size_t));
1368+
parser = (XML_Parser)((char *)sizeAndParser + sizeof(size_t)
1369+
+ EXPAT_MALLOC_PADDING);
13601370
#else
13611371
parser = memsuite->malloc_fcn(sizeof(struct XML_ParserStruct));
13621372
if (parser != NULL) {
@@ -1369,11 +1379,12 @@ parserCreate(const XML_Char *encodingName,
13691379
} else {
13701380
XML_Memory_Handling_Suite *mtemp;
13711381
#if XML_GE == 1
1372-
void *const sizeAndParser
1373-
= malloc(sizeof(size_t) + sizeof(struct XML_ParserStruct));
1382+
void *const sizeAndParser = malloc(sizeof(size_t) + EXPAT_MALLOC_PADDING
1383+
+ sizeof(struct XML_ParserStruct));
13741384
if (sizeAndParser != NULL) {
13751385
*(size_t *)sizeAndParser = sizeof(struct XML_ParserStruct);
1376-
parser = (XML_Parser)((char *)sizeAndParser + sizeof(size_t));
1386+
parser = (XML_Parser)((char *)sizeAndParser + sizeof(size_t)
1387+
+ EXPAT_MALLOC_PADDING);
13771388
#else
13781389
parser = malloc(sizeof(struct XML_ParserStruct));
13791390
if (parser != NULL) {
@@ -6437,6 +6448,10 @@ internalEntityProcessor(XML_Parser parser, const char *s, const char *end,
64376448
// process its possible inner entities (which are added to the
64386449
// m_openInternalEntities during doProlog or doContent calls above)
64396450
entity->hasMore = XML_FALSE;
6451+
if (! entity->is_param
6452+
&& (openEntity->startTagLevel != parser->m_tagLevel)) {
6453+
return XML_ERROR_ASYNC_ENTITY;
6454+
}
64406455
triggerReenter(parser);
64416456
return result;
64426457
} // End of entity processing, "if" block will return here
@@ -8135,7 +8150,7 @@ poolGrow(STRING_POOL *pool) {
81358150
if (bytesToAllocate == 0)
81368151
return XML_FALSE;
81378152

8138-
temp = REALLOC(pool->parser, pool->blocks, (unsigned)bytesToAllocate);
8153+
temp = REALLOC(pool->parser, pool->blocks, bytesToAllocate);
81398154
if (temp == NULL)
81408155
return XML_FALSE;
81418156
pool->blocks = temp;

Modules/expat/xmlrole.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
Copyright (c) 2000 Clark Cooper <[email protected]>
1111
Copyright (c) 2002 Karl Waclawek <[email protected]>
1212
Copyright (c) 2002 Fred L. Drake, Jr. <[email protected]>
13-
Copyright (c) 2017-2024 Sebastian Pipping <[email protected]>
13+
Copyright (c) 2017-2025 Sebastian Pipping <[email protected]>
1414
Licensed under the MIT license:
1515
1616
Permission is hereby granted, free of charge, to any person obtaining

0 commit comments

Comments
 (0)