[3.12] gh-116741: Upgrade libexpat to 2.6.2 (GH-117296) (GH-118166) · python/cpython@30725f0

1-

/* 628e24d4966bedbd4800f6ed128d06d29703765b4bce12d3b7f099f90f842fc9 (2.6.0+)

1+

/* 2a14271ad4d35e82bde8ba210b4edb7998794bcbae54deab114046a300f9639a (2.6.2+)

22

__ __ _

33

___\ \/ /_ __ __ _| |_

44

/ _ \\ /| '_ \ / _` | __|

3838

Copyright (c) 2022 Jann Horn <jannh@google.com>

3939

Copyright (c) 2022 Sean McBride <sean@rogue-research.com>

4040

Copyright (c) 2023 Owain Davies <owaind@bath.edu>

41-

Copyright (c) 2023 Sony Corporation / Snild Dolkow <snild@sony.com>

41+

Copyright (c) 2023-2024 Sony Corporation / Snild Dolkow <snild@sony.com>

4242

Licensed under the MIT license:

43434444

Permission is hereby granted, free of charge, to any person obtaining

@@ -210,7 +210,7 @@ typedef char ICHAR;

210210

#endif

211211212212

/* Round up n to be a multiple of sz, where sz is a power of 2. */

213-

#define ROUND_UP(n, sz) (((n) + ((sz)-1)) & ~((sz)-1))

213+

#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))

214214215215

/* Do safe (NULL-aware) pointer arithmetic */

216216

#define EXPAT_SAFE_PTR_DIFF(p, q) (((p) && (q)) ? ((p) - (q)) : 0)

@@ -248,7 +248,7 @@ static void copy_salt_to_sipkey(XML_Parser parser, struct sipkey *key);

248248

it odd, since odd numbers are always relative prime to a power of 2.

249249

*/

250250

#define SECOND_HASH(hash, mask, power) \

251-

((((hash) & ~(mask)) >> ((power)-1)) & ((mask) >> 2))

251+

((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2))

252252

#define PROBE_STEP(hash, mask, power) \

253253

((unsigned char)((SECOND_HASH(hash, mask, power)) | 1))

254254

@@ -629,8 +629,14 @@ static unsigned long getDebugLevel(const char *variableName,

629629

? 0 \

630630

: ((*((pool)->ptr)++ = c), 1))

631631632-

XML_Bool g_reparseDeferralEnabledDefault = XML_TRUE; // write ONLY in runtests.c

633-

unsigned int g_parseAttempts = 0; // used for testing only

632+

#if ! defined(XML_TESTING)

633+

const

634+

#endif

635+

XML_Bool g_reparseDeferralEnabledDefault

636+

= XML_TRUE; // write ONLY in runtests.c

637+

#if defined(XML_TESTING)

638+

unsigned int g_bytesScanned = 0; // used for testing only

639+

#endif

634640635641

struct XML_ParserStruct {

636642

/* The first member must be m_userData so that the XML_GetUserData

@@ -1017,7 +1023,9 @@ callProcessor(XML_Parser parser, const char *start, const char *end,

10171023

return XML_ERROR_NONE;

10181024

}

10191025

}

1020-

g_parseAttempts += 1;

1026+

#if defined(XML_TESTING)

1027+

g_bytesScanned += (unsigned)have_now;

1028+

#endif

10211029

const enum XML_Error ret = parser->m_processor(parser, start, end, endPtr);

10221030

if (ret == XML_ERROR_NONE) {

10231031

// if we consumed nothing, remember what we had on this parse attempt.

@@ -6232,7 +6240,7 @@ storeEntityValue(XML_Parser parser, const ENCODING *enc,

62326240

dtd->keepProcessing = dtd->standalone;

62336241

goto endEntityValue;

62346242

}

6235-

if (entity->open) {

6243+

if (entity->open || (entity == parser->m_declEntity)) {

62366244

if (enc == parser->m_encoding)

62376245

parser->m_eventPtr = entityTextPtr;

62386246

result = XML_ERROR_RECURSIVE_ENTITY_REF;

@@ -7779,14 +7787,18 @@ copyString(const XML_Char *s, const XML_Memory_Handling_Suite *memsuite) {

7779778777807788

static float

77817789

accountingGetCurrentAmplification(XML_Parser rootParser) {

7790+

// 1.........1.........12 => 22

7791+

const size_t lenOfShortestInclude = sizeof("<!ENTITY a SYSTEM 'b'>") - 1;

77827792

const XmlBigCount countBytesOutput

77837793

= rootParser->m_accounting.countBytesDirect

77847794

+ rootParser->m_accounting.countBytesIndirect;

77857795

const float amplificationFactor

77867796

= rootParser->m_accounting.countBytesDirect

77877797

? (countBytesOutput

77887798

/ (float)(rootParser->m_accounting.countBytesDirect))

7789-

: 1.0f;

7799+

: ((lenOfShortestInclude

7800+

+ rootParser->m_accounting.countBytesIndirect)

7801+

/ (float)lenOfShortestInclude);

77907802

assert(! rootParser->m_parentParser);

77917803

return amplificationFactor;

77927804

}