Skip to content

Commit 0c779e0

Browse files
committed
fix negative values
1 parent bff9503 commit 0c779e0

3 files changed

Lines changed: 11 additions & 4 deletions

File tree

NEWS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ PHP NEWS
2020
- DOM:
2121
. Fixed bug GH-22570 (Stack overflow when serializing a deeply nested
2222
Dom\XMLDocument). (iliaal)
23-
. Fixed Dom\DtdNamedNodeMap dimension access to throw ValueError for indexes
24-
outside the int range instead of overflowing while converting to int.
25-
(Weilin Du)
23+
. Fixed Dom\DtdNamedNodeMap integer dimension access so negative indexes
24+
return NULL and indexes outside the int range throw ValueError instead of
25+
returning the first entity or notation. (Weilin Du)
2626

2727
- Exif:
2828
. Fixed bug GH-11020 (exif_read_data() emits a spurious "Illegal IFD size"

ext/dom/dom_iterators.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ xmlNodePtr php_dom_libxml_hash_iter(xmlHashTable *ht, zend_long index)
8383
{
8484
int htsize;
8585

86+
if (index < 0) {
87+
return NULL;
88+
}
8689
if (UNEXPECTED(ZEND_LONG_INT_OVFL(index))) {
8790
zend_value_error("must be between 0 and %d", INT_MAX);
8891
return NULL;

ext/dom/tests/modern/xml/DtdNamedNodeMap_dimension_index_overflow_64.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
--TEST--
2-
Dom\DtdNamedNodeMap dimension access throws for indexes outside the int range
2+
Dom\DtdNamedNodeMap dimension access handles invalid integer indexes
33
--EXTENSIONS--
44
dom
55
--SKIPIF--
@@ -28,10 +28,14 @@ function dump_access(Closure $callback): void {
2828
}
2929
}
3030

31+
dump_access(fn() => $doc->doctype->entities[-1]);
3132
dump_access(fn() => $doc->doctype->entities[$overflow]);
3233

34+
dump_access(fn() => $doc->doctype->notations[-1]);
3335
dump_access(fn() => $doc->doctype->notations[$overflow]);
3436
?>
3537
--EXPECT--
38+
NULL
3639
must be between 0 and 2147483647
40+
NULL
3741
must be between 0 and 2147483647

0 commit comments

Comments
 (0)