1
- /* 628e24d4966bedbd4800f6ed128d06d29703765b4bce12d3b7f099f90f842fc9 (2.6.0 +)
1
+ /* 2a14271ad4d35e82bde8ba210b4edb7998794bcbae54deab114046a300f9639a (2.6.2 +)
2
2
__ __ _
3
3
___\ \/ /_ __ __ _| |_
4
4
/ _ \\ /| '_ \ / _` | __|
38
38
Copyright (c) 2022 Jann Horn <jannh@google.com>
39
39
Copyright (c) 2022 Sean McBride <sean@rogue-research.com>
40
40
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>
42
42
Licensed under the MIT license:
43
43
44
44
Permission is hereby granted, free of charge, to any person obtaining
@@ -210,7 +210,7 @@ typedef char ICHAR;
210
210
#endif
211
211
212
212
/* 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))
214
214
215
215
/* Do safe (NULL-aware) pointer arithmetic */
216
216
#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);
248
248
it odd, since odd numbers are always relative prime to a power of 2.
249
249
*/
250
250
#define SECOND_HASH (hash , mask , power ) \
251
- ((((hash) & ~(mask)) >> ((power)- 1)) & ((mask) >> 2))
251
+ ((((hash) & ~(mask)) >> ((power) - 1)) & ((mask) >> 2))
252
252
#define PROBE_STEP (hash , mask , power ) \
253
253
((unsigned char)((SECOND_HASH(hash, mask, power)) | 1))
254
254
@@ -629,8 +629,14 @@ static unsigned long getDebugLevel(const char *variableName,
629
629
? 0 \
630
630
: ((*((pool)->ptr)++ = c), 1))
631
631
632
- 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
634
640
635
641
struct XML_ParserStruct {
636
642
/* 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,
1017
1023
return XML_ERROR_NONE ;
1018
1024
}
1019
1025
}
1020
- g_parseAttempts += 1 ;
1026
+ #if defined(XML_TESTING )
1027
+ g_bytesScanned += (unsigned )have_now ;
1028
+ #endif
1021
1029
const enum XML_Error ret = parser -> m_processor (parser , start , end , endPtr );
1022
1030
if (ret == XML_ERROR_NONE ) {
1023
1031
// if we consumed nothing, remember what we had on this parse attempt.
@@ -6232,7 +6240,7 @@ storeEntityValue(XML_Parser parser, const ENCODING *enc,
6232
6240
dtd -> keepProcessing = dtd -> standalone ;
6233
6241
goto endEntityValue ;
6234
6242
}
6235
- if (entity -> open ) {
6243
+ if (entity -> open || ( entity == parser -> m_declEntity ) ) {
6236
6244
if (enc == parser -> m_encoding )
6237
6245
parser -> m_eventPtr = entityTextPtr ;
6238
6246
result = XML_ERROR_RECURSIVE_ENTITY_REF ;
@@ -7779,14 +7787,18 @@ copyString(const XML_Char *s, const XML_Memory_Handling_Suite *memsuite) {
7779
7787
7780
7788
static float
7781
7789
accountingGetCurrentAmplification (XML_Parser rootParser ) {
7790
+ // 1.........1.........12 => 22
7791
+ const size_t lenOfShortestInclude = sizeof ("<!ENTITY a SYSTEM 'b'>" ) - 1 ;
7782
7792
const XmlBigCount countBytesOutput
7783
7793
= rootParser -> m_accounting .countBytesDirect
7784
7794
+ rootParser -> m_accounting .countBytesIndirect ;
7785
7795
const float amplificationFactor
7786
7796
= rootParser -> m_accounting .countBytesDirect
7787
7797
? (countBytesOutput
7788
7798
/ (float )(rootParser -> m_accounting .countBytesDirect ))
7789
- : 1.0f ;
7799
+ : ((lenOfShortestInclude
7800
+ + rootParser -> m_accounting .countBytesIndirect )
7801
+ / (float )lenOfShortestInclude );
7790
7802
assert (! rootParser -> m_parentParser );
7791
7803
return amplificationFactor ;
7792
7804
}
0 commit comments