mirror of
https://github.com/libexpat/libexpat.git
synced 2025-04-07 06:04:59 +00:00
lib: Protect against billion laughs attacks (approach 3.0.21)
This commit is contained in:
parent
1e053c698b
commit
b1d039607d
6 changed files with 1132 additions and 53 deletions
2
.github/workflows/data/exported-symbols.txt
vendored
2
.github/workflows/data/exported-symbols.txt
vendored
|
@ -29,6 +29,8 @@ XML_ParserReset
|
|||
XML_ResumeParser
|
||||
XML_SetAttlistDeclHandler
|
||||
XML_SetBase
|
||||
XML_SetBillionLaughsAttackProtectionActivationThreshold
|
||||
XML_SetBillionLaughsAttackProtectionMaximumAmplification
|
||||
XML_SetCdataSectionHandler
|
||||
XML_SetCharacterDataHandler
|
||||
XML_SetCommentHandler
|
||||
|
|
|
@ -124,7 +124,9 @@ enum XML_Error {
|
|||
/* Added in 2.2.1. */
|
||||
XML_ERROR_INVALID_ARGUMENT,
|
||||
/* Added in 2.3.0. */
|
||||
XML_ERROR_NO_BUFFER
|
||||
XML_ERROR_NO_BUFFER,
|
||||
/* Added in 2.4.0. */
|
||||
XML_ERROR_AMPLIFICATION_LIMIT_BREACH
|
||||
};
|
||||
|
||||
enum XML_Content_Type {
|
||||
|
@ -1006,7 +1008,10 @@ enum XML_FeatureEnum {
|
|||
XML_FEATURE_SIZEOF_XML_LCHAR,
|
||||
XML_FEATURE_NS,
|
||||
XML_FEATURE_LARGE_SIZE,
|
||||
XML_FEATURE_ATTR_INFO
|
||||
XML_FEATURE_ATTR_INFO,
|
||||
/* Added in Expat 2.4.0. */
|
||||
XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
|
||||
XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT
|
||||
/* Additional features must be added to the end of this enum. */
|
||||
};
|
||||
|
||||
|
@ -1019,6 +1024,18 @@ typedef struct {
|
|||
XMLPARSEAPI(const XML_Feature *)
|
||||
XML_GetFeatureList(void);
|
||||
|
||||
#ifdef XML_DTD
|
||||
/* Added in Expat 2.4.0. */
|
||||
XMLPARSEAPI(XML_Bool)
|
||||
XML_SetBillionLaughsAttackProtectionMaximumAmplification(
|
||||
XML_Parser parser, float maximumAmplificationFactor);
|
||||
|
||||
/* Added in Expat 2.4.0. */
|
||||
XMLPARSEAPI(XML_Bool)
|
||||
XML_SetBillionLaughsAttackProtectionActivationThreshold(
|
||||
XML_Parser parser, unsigned long long activationThresholdBytes);
|
||||
#endif
|
||||
|
||||
/* Expat follows the semantic versioning convention.
|
||||
See http://semver.org.
|
||||
*/
|
||||
|
|
|
@ -105,10 +105,40 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
#include <limits.h> // ULONG_MAX
|
||||
|
||||
#if defined(_WIN32) && ! defined(__USE_MINGW_ANSI_STDIO)
|
||||
# define EXPAT_FMT_ULL(midpart) "%" midpart "I64u"
|
||||
# if defined(_WIN64) // Note: modifier "td" does not work for MinGW
|
||||
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "I64d"
|
||||
# else
|
||||
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
|
||||
# endif
|
||||
#else
|
||||
# define EXPAT_FMT_ULL(midpart) "%" midpart "llu"
|
||||
# if ! defined(ULONG_MAX)
|
||||
# error Compiler did not define ULONG_MAX for us
|
||||
# elif ULONG_MAX == 18446744073709551615u // 2^64-1
|
||||
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "ld"
|
||||
# else
|
||||
# define EXPAT_FMT_PTRDIFF_T(midpart) "%" midpart "d"
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef UNUSED_P
|
||||
# define UNUSED_P(p) (void)p
|
||||
#endif
|
||||
|
||||
/* NOTE BEGIN If you ever patch these defaults to greater values
|
||||
for non-attack XML payload in your environment,
|
||||
please file a bug report with libexpat. Thank you!
|
||||
*/
|
||||
#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT \
|
||||
100.0f
|
||||
#define EXPAT_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT \
|
||||
8388608 // 8 MiB, 2^23
|
||||
/* NOTE END */
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
|
|
@ -75,3 +75,6 @@ EXPORTS
|
|||
; XML_GetAttributeInfo @66
|
||||
XML_SetHashSalt @67
|
||||
; internal @68 removed with version 2.3.1
|
||||
; added with version 2.4.0
|
||||
XML_SetBillionLaughsAttackProtectionActivationThreshold @69
|
||||
XML_SetBillionLaughsAttackProtectionMaximumAmplification @70
|
||||
|
|
|
@ -75,3 +75,6 @@ EXPORTS
|
|||
; XML_GetAttributeInfo @66
|
||||
XML_SetHashSalt @67
|
||||
; internal @68 removed with version 2.3.1
|
||||
; added with version 2.4.0
|
||||
XML_SetBillionLaughsAttackProtectionActivationThreshold @69
|
||||
XML_SetBillionLaughsAttackProtectionMaximumAmplification @70
|
||||
|
|
1126
expat/lib/xmlparse.c
1126
expat/lib/xmlparse.c
File diff suppressed because it is too large
Load diff
Loading…
Add table
Reference in a new issue