From 355a123b922ffb55895138e3176e1a4a076e6f4f Mon Sep 17 00:00:00 2001 From: Snild Dolkow Date: Fri, 18 Aug 2023 10:06:51 +0200 Subject: [PATCH 1/4] docs: Document the importance of isFinal Before the concluding `isFinal=XML_TRUE` parse call, there is no guarantee that all input has been parsed. An application that omits that call risks missing handler callbacks and/or parsing errors. --- expat/doc/reference.html | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/expat/doc/reference.html b/expat/doc/reference.html index 131b1df6..d2b0f60c 100644 --- a/expat/doc/reference.html +++ b/expat/doc/reference.html @@ -19,6 +19,7 @@ Copyright (c) 2021 Tomas Korbar Copyright (c) 2021 Nicolas Cavallari Copyright (c) 2022 Thijs Schreijer + Copyright (c) 2023 Sony Corporation / Snild Dolkow Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -1078,6 +1079,11 @@ exceed the maximum integer value. Input data at the end of a buffer will remain unprocessed if it is part of an XML token for which the end is not part of that buffer.

+

The application must make a concluding +XML_Parse or +XML_ParseBuffer call +with isFinal set to XML_TRUE.

+

XML_Parse

 enum XML_Status XMLCALL
@@ -1104,6 +1110,10 @@ piece of the document. Frequently, the last piece is empty (i.e.
 len is zero.)
 If a parse error occurred, it returns XML_STATUS_ERROR.
 Otherwise it returns XML_STATUS_OK value.
+Note that regardless of the return value, there is no guarantee that all
+provided input has been parsed; only after the
+concluding call will all handler callbacks and parsing errors have
+happened.
 
 
 

XML_ParseBuffer

From d52b4141496bd26bd716d88c67af8f2250bd0da6 Mon Sep 17 00:00:00 2001 From: Snild Dolkow Date: Thu, 24 Aug 2023 09:31:31 +0200 Subject: [PATCH 2/4] tests: Move triplet_start_checker flag check after isFinal=1 call There is no guarantee that the callback will happen before the parse call with isFinal=XML_TRUE. Let's move the assertion to a location where we know it must have happened. --- expat/tests/ns_tests.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/expat/tests/ns_tests.c b/expat/tests/ns_tests.c index 826018b6..5ecb09ac 100644 --- a/expat/tests/ns_tests.c +++ b/expat/tests/ns_tests.c @@ -18,6 +18,7 @@ Copyright (c) 2019 David Loffredo Copyright (c) 2020 Tim Gates Copyright (c) 2021 Dong-hee Na + Copyright (c) 2023 Sony Corporation / Snild Dolkow Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -81,13 +82,13 @@ START_TEST(test_return_ns_triplet) { if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) == XML_STATUS_ERROR) xml_failure(g_parser); - if (! g_triplet_start_flag) - fail("triplet_start_checker not invoked"); /* Check that unsetting "return triplets" fails while still parsing */ XML_SetReturnNSTriplet(g_parser, XML_FALSE); if (_XML_Parse_SINGLE_BYTES(g_parser, epilog, (int)strlen(epilog), XML_TRUE) == XML_STATUS_ERROR) xml_failure(g_parser); + if (! g_triplet_start_flag) + fail("triplet_start_checker not invoked"); if (! g_triplet_end_flag) fail("triplet_end_checker not invoked"); if (get_dummy_handler_flags() From 2cee1061e2fec10633c3f02a961dabf95e85910a Mon Sep 17 00:00:00 2001 From: Snild Dolkow Date: Thu, 24 Aug 2023 14:10:58 +0200 Subject: [PATCH 3/4] tests: Set isFinal in test_column_number_after_parse Without this, parsing of the end tag may be deferred, yielding an unexpected column number. --- expat/tests/basic_tests.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/expat/tests/basic_tests.c b/expat/tests/basic_tests.c index 71a5c0d3..9a06ad55 100644 --- a/expat/tests/basic_tests.c +++ b/expat/tests/basic_tests.c @@ -18,6 +18,7 @@ Copyright (c) 2019 David Loffredo Copyright (c) 2020 Tim Gates Copyright (c) 2021 Dong-hee Na + Copyright (c) 2023 Sony Corporation / Snild Dolkow Licensed under the MIT license: Permission is hereby granted, free of charge, to any person obtaining @@ -613,7 +614,7 @@ START_TEST(test_column_number_after_parse) { const char *text = ""; XML_Size colno; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) == XML_STATUS_ERROR) xml_failure(g_parser); colno = XML_GetCurrentColumnNumber(g_parser); From d4105a9080271a8d4996d2454f89be9992cb268a Mon Sep 17 00:00:00 2001 From: Snild Dolkow Date: Thu, 31 Aug 2023 16:14:38 +0200 Subject: [PATCH 4/4] tests: Set isFinal=1 in line/column-number-after-error tests --- expat/tests/basic_tests.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/expat/tests/basic_tests.c b/expat/tests/basic_tests.c index 9a06ad55..31e02335 100644 --- a/expat/tests/basic_tests.c +++ b/expat/tests/basic_tests.c @@ -665,7 +665,7 @@ START_TEST(test_line_number_after_error) { " \n" " "; /* missing */ XML_Size lineno; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) != XML_STATUS_ERROR) fail("Expected a parse error"); @@ -685,7 +685,7 @@ START_TEST(test_column_number_after_error) { " \n" " "; /* missing */ XML_Size colno; - if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_FALSE) + if (_XML_Parse_SINGLE_BYTES(g_parser, text, (int)strlen(text), XML_TRUE) != XML_STATUS_ERROR) fail("Expected a parse error");