[php-src] master: Fix Bug-81481 XML_GetCurrentByteIndex() truncation on Windows x64
| From: | Marc Bennewitz via ndossche | Date: | Mon, 05 Oct 2026 17:43:32 +0000 |
| Subject: | [php-src] master: Fix Bug-81481 XML_GetCurrentByteIndex() truncation on Windows x64 | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-141970@lists.php.net to get a copy of this message | ||
Author: Marc Bennewitz (marc-mabe)
Committer: ndossche (ndossche)
Date: 2026-10-05T19:42:59+02:00
Commit: https://github.com/php/php-src/commit/5ec9164e5966ec93368296ff716b4d7cfd5489c8
Raw diff: https://github.com/php/php-src/commit/5ec9164e5966ec93368296ff716b4d7cfd5489c8.diff
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.
Changed paths:
M NEWS
M ext/xml/compat.c
M ext/xml/expat_compat.h
M ext/xml/tests/bug81481.phpt
Diff:
diff --git a/NEWS b/NEWS
index 7d3d54540a3a..44acf0104b54 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 10bfa19af7af..6fe0552ca229 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 721bad71080b..c16fa4a932f3 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 ee37cacfa314..e6bd3aa045e7 100644
--- a/ext/xml/tests/bug81481.phpt
+++ b/ext/xml/tests/bug81481.phpt
@@ -13,7 +13,6 @@ require __DIR__ . '/libxml_expat_skipif.inc';
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