From 343594dc344e543acb7478d1283b50b299a1c110 Mon Sep 17 00:00:00 2001
From: Sebastian Pipping <sebastian@pipping.org>
Date: Fri, 19 Sep 2025 22:46:01 +0200
Subject: [PATCH] tests: Add new test test_alloc_tracker_pointer_alignment

CVE: CVE-2025-59375
Upstream-Status: Backport [https://github.com/libexpat/libexpat/commit/343594dc344e543acb7478d1283b50b299a1c110]
Signed-off-by: Peter Marko <peter.marko@siemens.com>
---
 tests/alloc_tests.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/tests/alloc_tests.c b/tests/alloc_tests.c
index 045447b0..5ae6c6a7 100644
--- a/tests/alloc_tests.c
+++ b/tests/alloc_tests.c
@@ -2132,6 +2132,22 @@ START_TEST(test_alloc_tracker_size_recorded) {
 }
 END_TEST
 
+START_TEST(test_alloc_tracker_pointer_alignment) {
+  XML_Parser parser = XML_ParserCreate(NULL);
+#if XML_GE == 1
+  assert_true(sizeof(long long) >= sizeof(size_t)); // self-test
+  long long *const ptr
+      = (long long *)expat_malloc(parser, 4 * sizeof(long long), -1);
+  ptr[0] = 0LL;
+  ptr[1] = 1LL;
+  ptr[2] = 2LL;
+  ptr[3] = 3LL;
+  expat_free(parser, ptr, -1);
+#endif
+  XML_ParserFree(parser);
+}
+END_TEST
+
 START_TEST(test_alloc_tracker_maximum_amplification) {
   if (g_reparseDeferralEnabledDefault == XML_TRUE) {
     return;
@@ -2363,6 +2379,7 @@ make_alloc_test_case(Suite *s) {
       tc_alloc, test_alloc_reset_after_external_entity_parser_create_fail);
 
   tcase_add_test__if_xml_ge(tc_alloc, test_alloc_tracker_size_recorded);
+  tcase_add_test__if_xml_ge(tc_alloc, test_alloc_tracker_pointer_alignment);
   tcase_add_test__if_xml_ge(tc_alloc, test_alloc_tracker_maximum_amplification);
   tcase_add_test__if_xml_ge(tc_alloc, test_alloc_tracker_threshold);
   tcase_add_test__if_xml_ge(tc_alloc, test_alloc_tracker_getbuffer_unlimited);
