Commit 5ec9164e596 for php
commit 5ec9164e5966ec93368296ff716b4d7cfd5489c8
Author: Marc Bennewitz <marc@mabe.berlin>
Date: Fri Sep 25 06:34:12 2026 +0200
Fix Bug-81481 XML_GetCurrentByteIndex() truncation on Windows x64
The fix for https://bugs.php.net/bug.php?id=81481 made the libxml
compatibility wrapper return long, which is still 32-bit on Windows x64,
so byte indexes beyond 2 GiB turned negative there. Return zend_long
instead and run the test on Windows too.
Closes GH-23901.
diff --git a/NEWS b/NEWS
index 7d3d54540a3..44acf0104b5 100644
--- a/NEWS
+++ b/NEWS
@@ -106,6 +106,10 @@ PHP NEWS
. Fix casing of enum cases in UriHostType and UrlHostType to match the RFC
and PHP’s naming policy. (timwolla)
+- XML:
+ . Fixed xml_get_current_byte_index() returning negative values for byte
+ indexes beyond 2 GiB on Windows x64. (Marc Bennewitz)
+
- Zlib:
. Fixed inflate_init() dropping the preset dictionary for raw streams with
a non-default window. (Ilia Alshanetsky)
diff --git a/ext/xml/compat.c b/ext/xml/compat.c
index 10bfa19af7a..6fe0552ca22 100644
--- a/ext/xml/compat.c
+++ b/ext/xml/compat.c
@@ -635,11 +635,13 @@ XML_GetCurrentColumnNumber(XML_Parser parser)
return parser->parser->input->col;
}
-PHP_XML_API long
+PHP_XML_API zend_long
XML_GetCurrentByteIndex(XML_Parser parser)
{
- return parser->parser->input->consumed +
- (parser->parser->input->cur - parser->parser->input->base);
+ /* consumed is unsigned long; widen before adding so it does not wrap
+ * or turn negative where long is narrower than zend_long */
+ return (zend_long) parser->parser->input->consumed +
+ (zend_long) (parser->parser->input->cur - parser->parser->input->base);
}
PHP_XML_API void
diff --git a/ext/xml/expat_compat.h b/ext/xml/expat_compat.h
index 721bad71080..c16fa4a932f 100644
--- a/ext/xml/expat_compat.h
+++ b/ext/xml/expat_compat.h
@@ -144,7 +144,7 @@ PHP_XML_API int XML_GetErrorCode(XML_Parser);
PHP_XML_API const XML_Char *XML_ErrorString(int);
PHP_XML_API int XML_GetCurrentLineNumber(XML_Parser);
PHP_XML_API int XML_GetCurrentColumnNumber(XML_Parser);
-PHP_XML_API long XML_GetCurrentByteIndex(XML_Parser);
+PHP_XML_API zend_long XML_GetCurrentByteIndex(XML_Parser);
PHP_XML_API void XML_ParserFree(XML_Parser);
#elif defined(HAVE_LIBEXPAT)
diff --git a/ext/xml/tests/bug81481.phpt b/ext/xml/tests/bug81481.phpt
index ee37cacfa31..e6bd3aa045e 100644
--- a/ext/xml/tests/bug81481.phpt
+++ b/ext/xml/tests/bug81481.phpt
@@ -13,7 +13,6 @@
skipif(want_expat: false);
if (getenv("SKIP_SLOW_TESTS")) die("skip slow test");
if (PHP_INT_SIZE != 8) die("skip 64-bit only");
-if (PHP_OS_FAMILY == 'Windows') die('skip not for Windows');
?>
--FILE--
<?php