77 |_| XML parser
88
99 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10- Copyright (c) 2000-2017 Expat development team
10+ Copyright (c) 2000 Clark Cooper <[email protected] > 11+ Copyright (c) 2000-2005 Fred L. Drake, Jr. <[email protected] > 12+ Copyright (c) 2001-2002 Greg Stein <[email protected] > 13+ Copyright (c) 2002-2016 Karl Waclawek <[email protected] > 14+ Copyright (c) 2016-2024 Sebastian Pipping <[email protected] > 15+ Copyright (c) 2016 Cristian Rodríguez <[email protected] > 16+ Copyright (c) 2016 Thomas Beutlich <[email protected] > 17+ Copyright (c) 2017 Rhodri James <[email protected] > 18+ Copyright (c) 2022 Thijs Schreijer <[email protected] > 19+ Copyright (c) 2023 Hanno Böck <[email protected] > 20+ Copyright (c) 2023 Sony Corporation / Snild Dolkow <[email protected] > 21+ Copyright (c) 2024 Taichi Haradaguchi <[email protected] > 1122 Licensed under the MIT license:
1223
1324 Permission is hereby granted, free of charge, to any person obtaining
@@ -115,7 +126,13 @@ enum XML_Error {
115126 XML_ERROR_RESERVED_PREFIX_XMLNS,
116127 XML_ERROR_RESERVED_NAMESPACE_URI,
117128 /* Added in 2.2.1. */
118- XML_ERROR_INVALID_ARGUMENT
129+ XML_ERROR_INVALID_ARGUMENT,
130+ /* Added in 2.3.0. */
131+ XML_ERROR_NO_BUFFER,
132+ /* Added in 2.4.0. */
133+ XML_ERROR_AMPLIFICATION_LIMIT_BREACH,
134+ /* Added in 2.6.4. */
135+ XML_ERROR_NOT_STARTED,
119136};
120137
121138enum XML_Content_Type {
@@ -163,8 +180,10 @@ struct XML_cp {
163180};
164181
165182/* This is called for an element declaration. See above for
166- description of the model argument. It's the caller's responsibility
167- to free model when finished with it.
183+ description of the model argument. It's the user code's responsibility
184+ to free model when finished with it. See XML_FreeContentModel.
185+ There is no need to free the model from the handler, it can be kept
186+ around and freed at a later stage.
168187*/
169188typedef void (XMLCALL *XML_ElementDeclHandler)(void *userData,
170189 const XML_Char *name,
@@ -226,6 +245,17 @@ XML_ParserCreate(const XML_Char *encoding);
226245 and the local part will be concatenated without any separator.
227246 It is a programming error to use the separator '\0' with namespace
228247 triplets (see XML_SetReturnNSTriplet).
248+ If a namespace separator is chosen that can be part of a URI or
249+ part of an XML name, splitting an expanded name back into its
250+ 1, 2 or 3 original parts on application level in the element handler
251+ may end up vulnerable, so these are advised against; sane choices for
252+ a namespace separator are e.g. '\n' (line feed) and '|' (pipe).
253+
254+ Note that Expat does not validate namespace URIs (beyond encoding)
255+ against RFC 3986 today (and is not required to do so with regard to
256+ the XML 1.0 namespaces specification) but it may start doing that
257+ in future releases. Before that, an application using Expat must
258+ be ready to receive namespace URIs containing non-URI characters.
229259*/
230260XMLPARSEAPI (XML_Parser)
231261XML_ParserCreateNS(const XML_Char *encoding, XML_Char namespaceSeparator);
@@ -244,7 +274,7 @@ XML_ParserCreate_MM(const XML_Char *encoding,
244274 const XML_Memory_Handling_Suite *memsuite,
245275 const XML_Char *namespaceSeparator);
246276
247- /* Prepare a parser object to be re-used . This is particularly
277+ /* Prepare a parser object to be reused . This is particularly
248278 valuable when memory allocation overhead is disproportionately high,
249279 such as when a large number of small documnents need to be parsed.
250280 All handlers are cleared from the parser, except for the
@@ -306,7 +336,7 @@ typedef void(XMLCALL *XML_StartDoctypeDeclHandler)(void *userData,
306336 const XML_Char *pubid,
307337 int has_internal_subset);
308338
309- /* This is called for the start of the DOCTYPE declaration when the
339+ /* This is called for the end of the DOCTYPE declaration when the
310340 closing > is encountered, but after processing any external
311341 subset.
312342*/
@@ -318,7 +348,7 @@ typedef void(XMLCALL *XML_EndDoctypeDeclHandler)(void *userData);
318348
319349 For internal entities (<!ENTITY foo "bar">), value will
320350 be non-NULL and systemId, publicID, and notationName will be NULL.
321- The value string is NOT nul -terminated; the length is provided in
351+ The value string is NOT null -terminated; the length is provided in
322352 the value_length argument. Since it is legal to have zero-length
323353 values, do not use this argument to test for internal entities.
324354
@@ -513,7 +543,7 @@ typedef struct {
513543 Otherwise it must return XML_STATUS_ERROR.
514544
515545 If info does not describe a suitable encoding, then the parser will
516- return an XML_UNKNOWN_ENCODING error.
546+ return an XML_ERROR_UNKNOWN_ENCODING error.
517547*/
518548typedef int (XMLCALL *XML_UnknownEncodingHandler)(void *encodingHandlerData,
519549 const XML_Char *name,
@@ -707,7 +737,7 @@ XML_GetBase(XML_Parser parser);
707737/* Returns the number of the attribute/value pairs passed in last call
708738 to the XML_StartElementHandler that were specified in the start-tag
709739 rather than defaulted. Each attribute/value pair counts as 2; thus
710- this correspondds to an index into the atts array passed to the
740+ this corresponds to an index into the atts array passed to the
711741 XML_StartElementHandler. Returns -1 if parser == NULL.
712742*/
713743XMLPARSEAPI (int )
@@ -716,7 +746,7 @@ XML_GetSpecifiedAttributeCount(XML_Parser parser);
716746/* Returns the index of the ID attribute passed in the last call to
717747 XML_StartElementHandler, or -1 if there is no ID attribute or
718748 parser == NULL. Each attribute/value pair counts as 2; thus this
719- correspondds to an index into the atts array passed to the
749+ corresponds to an index into the atts array passed to the
720750 XML_StartElementHandler.
721751*/
722752XMLPARSEAPI (int )
@@ -926,7 +956,7 @@ XMLPARSEAPI(XML_Index) XML_GetCurrentByteIndex(XML_Parser parser);
926956XMLPARSEAPI (int )
927957XML_GetCurrentByteCount(XML_Parser parser);
928958
929- /* If XML_CONTEXT_BYTES is defined , returns the input buffer, sets
959+ /* If XML_CONTEXT_BYTES is >=1 , returns the input buffer, sets
930960 the integer pointed to by offset to the offset within this buffer
931961 of the current parse position, and sets the integer pointed to by size
932962 to the size of this buffer (the number of input bytes). Otherwise
@@ -997,7 +1027,12 @@ enum XML_FeatureEnum {
9971027 XML_FEATURE_SIZEOF_XML_LCHAR,
9981028 XML_FEATURE_NS,
9991029 XML_FEATURE_LARGE_SIZE,
1000- XML_FEATURE_ATTR_INFO
1030+ XML_FEATURE_ATTR_INFO,
1031+ /* Added in Expat 2.4.0. */
1032+ XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_MAXIMUM_AMPLIFICATION_DEFAULT,
1033+ XML_FEATURE_BILLION_LAUGHS_ATTACK_PROTECTION_ACTIVATION_THRESHOLD_DEFAULT,
1034+ /* Added in Expat 2.6.0. */
1035+ XML_FEATURE_GE
10011036 /* Additional features must be added to the end of this enum. */
10021037};
10031038
@@ -1010,12 +1045,30 @@ typedef struct {
10101045XMLPARSEAPI (const XML_Feature *)
10111046XML_GetFeatureList(void );
10121047
1048+ #if defined(XML_DTD) || (defined(XML_GE) && XML_GE == 1)
1049+ /* Added in Expat 2.4.0 for XML_DTD defined and
1050+ * added in Expat 2.6.0 for XML_GE == 1. */
1051+ XMLPARSEAPI (XML_Bool)
1052+ XML_SetBillionLaughsAttackProtectionMaximumAmplification(
1053+ XML_Parser parser, float maximumAmplificationFactor);
1054+
1055+ /* Added in Expat 2.4.0 for XML_DTD defined and
1056+ * added in Expat 2.6.0 for XML_GE == 1. */
1057+ XMLPARSEAPI (XML_Bool)
1058+ XML_SetBillionLaughsAttackProtectionActivationThreshold(
1059+ XML_Parser parser, unsigned long long activationThresholdBytes);
1060+ #endif
1061+
1062+ /* Added in Expat 2.6.0. */
1063+ XMLPARSEAPI (XML_Bool)
1064+ XML_SetReparseDeferralEnabled(XML_Parser parser, XML_Bool enabled);
1065+
10131066/* Expat follows the semantic versioning convention.
1014- See http ://semver.org.
1067+ See https ://semver.org
10151068*/
10161069#define XML_MAJOR_VERSION 2
1017- #define XML_MINOR_VERSION 2
1018- #define XML_MICRO_VERSION 8
1070+ #define XML_MINOR_VERSION 6
1071+ #define XML_MICRO_VERSION 4
10191072
10201073#ifdef __cplusplus
10211074}
0 commit comments