[php-src] master: Fix 32-bit DOM characterdata failures (#13663)
| From: | Niels Dossche via GitHub | Date: | Mon, 11 Mar 2024 20:30:01 +0000 |
| Subject: | [php-src] master: Fix 32-bit DOM characterdata failures (#13663) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127702@lists.php.net to get a copy of this message | ||
Author: Niels Dossche (nielsdos)
Committer: GitHub (web-flow)
Pusher: nielsdos
Date: 2024-03-11T21:16:13+01:00
Commit: https://github.com/php/php-src/commit/3c33430d275b77ffd172ca19726558af0af424a4
Raw diff: https://github.com/php/php-src/commit/3c33430d275b77ffd172ca19726558af0af424a4.diff
Fix 32-bit DOM characterdata failures (#13663)
Changed paths:
A ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt
A ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt
A ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt
M ext/dom/characterdata.c
M ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
M ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count.phpt
M ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
Diff:
diff --git a/ext/dom/characterdata.c b/ext/dom/characterdata.c
index 6bd5811fdffa4..3e7029e8f1bd5 100644
--- a/ext/dom/characterdata.c
+++ b/ext/dom/characterdata.c
@@ -140,7 +140,7 @@ PHP_METHOD(DOMCharacterData, substringData)
RETURN_FALSE;
}
- if ((offset + count) > length) {
+ if (count > length - offset) {
count = length - offset;
}
@@ -305,7 +305,7 @@ static void dom_character_data_delete_data(INTERNAL_FUNCTION_PARAMETERS, bool re
substring = NULL;
}
- if ((offset + count) > length) {
+ if (count > length - offset) {
count = length - offset;
}
@@ -379,7 +379,7 @@ static void dom_character_data_replace_data(INTERNAL_FUNCTION_PARAMETERS, bool r
substring = NULL;
}
- if ((offset + count) > length) {
+ if (count > length - offset) {
count = length - offset;
}
diff --git a/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
index 4166c64f54495..f00625df3521c 100644
--- a/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset.phpt
@@ -5,8 +5,6 @@ dom
--FILE--
<?php
-echo "--- Modern behaviour ---\n";
-
$dom = DOM\HTMLDocument::createEmpty();
$comment = $dom->createComment("foobarbaz");
try {
@@ -15,34 +13,11 @@ try {
echo $e->getMessage(), "\n";
}
echo $dom->saveHTML($comment), "\n";
-$comment->insertData(-(2**32 - 1), "A");
-echo $dom->saveHTML($comment), "\n";
-
-echo "--- Legacy behaviour ---\n";
-
-$dom = new DOMDocument;
-$comment = $dom->createComment("foobarbaz");
-try {
- $comment->insertData(-1, "A");
-} catch (DOMException $e) {
- echo $e->getMessage(), "\n";
-}
-echo $dom->saveHTML($comment), "\n";
-try {
- $comment->insertData(-(2**32 - 1), "A");
-} catch (DOMException $e) {
- echo $e->getMessage(), "\n";
-}
+$comment->insertData(1, "A");
echo $dom->saveHTML($comment), "\n";
?>
--EXPECT--
---- Modern behaviour ---
Index Size Error
<!--foobarbaz-->
<!--fAoobarbaz-->
---- Legacy behaviour ---
-Index Size Error
-<!--foobarbaz-->
-Index Size Error
-<!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt
b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt
new file mode 100644
index 0000000000000..5c0be698bda83
--- /dev/null
+++ b/ext/dom/tests/modern/spec/CharacterData_insertData_negative_offset_mod32.phpt
@@ -0,0 +1,52 @@
+--TEST--
+insertData() negative offset (mod 32)
+--EXTENSIONS--
+dom
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE === 4) die('skip not for 32-bit');
+?>
+--FILE--
+<?php
+
+echo "--- Modern behaviour ---\n";
+
+$dom = DOM\HTMLDocument::createEmpty();
+$comment = $dom->createComment("foobarbaz");
+try {
+ $comment->insertData(-1, "A");
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+$comment->insertData(-(2**32 - 1), "A");
+echo $dom->saveHTML($comment), "\n";
+
+echo "--- Legacy behaviour ---\n";
+
+$dom = new DOMDocument;
+$comment = $dom->createComment("foobarbaz");
+try {
+ $comment->insertData(-1, "A");
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+try {
+ $comment->insertData(-(2**32 - 1), "A");
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+
+?>
+--EXPECT--
+--- Modern behaviour ---
+Index Size Error
+<!--foobarbaz-->
+<!--fAoobarbaz-->
+--- Legacy behaviour ---
+Index Size Error
+<!--foobarbaz-->
+Index Size Error
+<!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count.phpt
b/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count.phpt
index d673cb25198f0..96402847f73cf 100644
--- a/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count.phpt
@@ -5,40 +5,15 @@ dom
--FILE--
<?php
-echo "--- Modern behaviour ---\n";
-
$dom = DOM\HTMLDocument::createEmpty();
$comment = $dom->createComment("foobarbaz");
$comment->replaceData(0, -1, "A");
echo $dom->saveHTML($comment), "\n";
$comment = $dom->createComment("foobarbaz");
-$comment->replaceData(2, -(2**32 - 2), "A");
-echo $dom->saveHTML($comment), "\n";
-
-echo "--- Legacy behaviour ---\n";
-
-$dom = new DOMDocument;
-$comment = $dom->createComment("foobarbaz");
-try {
- $comment->replaceData(0, -1, "A");
-} catch (DOMException $e) {
- echo $e->getMessage(), "\n";
-}
-echo $dom->saveHTML($comment), "\n";
-try {
- $comment->replaceData(2, -(2**32 - 2), "A");
-} catch (DOMException $e) {
- echo $e->getMessage(), "\n";
-}
+$comment->replaceData(2, -2, "A");
echo $dom->saveHTML($comment), "\n";
?>
--EXPECT--
---- Modern behaviour ---
<!--A-->
-<!--foAarbaz-->
---- Legacy behaviour ---
-Index Size Error
-<!--foobarbaz-->
-Index Size Error
-<!--foobarbaz-->
+<!--foA-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt
b/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt
new file mode 100644
index 0000000000000..9382ed2549753
--- /dev/null
+++ b/ext/dom/tests/modern/spec/CharacterData_replaceData_negative_count_mod32.phpt
@@ -0,0 +1,48 @@
+--TEST--
+replaceData() negative count (mod 32)
+--EXTENSIONS--
+dom
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE === 4) die('skip not for 32-bit');
+?>
+--FILE--
+<?php
+
+echo "--- Modern behaviour ---\n";
+
+$dom = DOM\HTMLDocument::createEmpty();
+$comment = $dom->createComment("foobarbaz");
+$comment->replaceData(0, -1, "A");
+echo $dom->saveHTML($comment), "\n";
+$comment = $dom->createComment("foobarbaz");
+$comment->replaceData(2, -(2**32 - 2), "A");
+echo $dom->saveHTML($comment), "\n";
+
+echo "--- Legacy behaviour ---\n";
+
+$dom = new DOMDocument;
+$comment = $dom->createComment("foobarbaz");
+try {
+ $comment->replaceData(0, -1, "A");
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+try {
+ $comment->replaceData(2, -(2**32 - 2), "A");
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+
+?>
+--EXPECT--
+--- Modern behaviour ---
+<!--A-->
+<!--foAarbaz-->
+--- Legacy behaviour ---
+Index Size Error
+<!--foobarbaz-->
+Index Size Error
+<!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
index 756e3cf07678c..a0b5414bb8982 100644
--- a/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
+++ b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments.phpt
@@ -5,35 +5,14 @@ dom
--FILE--
<?php
-echo "--- Modern behaviour ---\n";
-
$dom = DOM\HTMLDocument::createEmpty();
$comment = $dom->createComment("foobarbaz");
var_dump($comment->substringData(0, -1));
echo $dom->saveHTML($comment), "\n";
-var_dump($comment->substringData(2, -(2**32 - 2)));
-echo $dom->saveHTML($comment), "\n";
-var_dump($comment->substringData(-(2**32 - 2), 2));
-echo $dom->saveHTML($comment), "\n";
-
-echo "--- Legacy behaviour ---\n";
-
-$dom = new DOMDocument;
-$comment = $dom->createComment("foobarbaz");
-try {
- var_dump($comment->substringData(0, -1));
-} catch (DOMException $e) {
- echo $e->getMessage(), "\n";
-}
-echo $dom->saveHTML($comment), "\n";
-try {
- var_dump($comment->substringData(2, -(2**32 - 2)));
-} catch (DOMException $e) {
- echo $e->getMessage(), "\n";
-}
+var_dump($comment->substringData(2, -2));
echo $dom->saveHTML($comment), "\n";
try {
- var_dump($comment->substringData(-(2**32 - 2), 2));
+ var_dump($comment->substringData(-2, 2));
} catch (DOMException $e) {
echo $e->getMessage(), "\n";
}
@@ -41,17 +20,9 @@ echo $dom->saveHTML($comment), "\n";
?>
--EXPECT--
---- Modern behaviour ---
string(9) "foobarbaz"
<!--foobarbaz-->
-string(2) "ob"
-<!--foobarbaz-->
-string(2) "ob"
-<!--foobarbaz-->
---- Legacy behaviour ---
-Index Size Error
-<!--foobarbaz-->
-Index Size Error
+string(7) "obarbaz"
<!--foobarbaz-->
Index Size Error
<!--foobarbaz-->
diff --git a/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt
b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt
new file mode 100644
index 0000000000000..c29eb0b779298
--- /dev/null
+++ b/ext/dom/tests/modern/spec/CharacterData_substringData_negative_arguments_mod32.phpt
@@ -0,0 +1,61 @@
+--TEST--
+substringData() negative arguments (mod 32)
+--EXTENSIONS--
+dom
+--SKIPIF--
+<?php
+if (PHP_INT_SIZE === 4) die('skip not for 32-bit');
+?>
+--FILE--
+<?php
+
+echo "--- Modern behaviour ---\n";
+
+$dom = DOM\HTMLDocument::createEmpty();
+$comment = $dom->createComment("foobarbaz");
+var_dump($comment->substringData(0, -1));
+echo $dom->saveHTML($comment), "\n";
+var_dump($comment->substringData(2, -(2**32 - 2)));
+echo $dom->saveHTML($comment), "\n";
+var_dump($comment->substringData(-(2**32 - 2), 2));
+echo $dom->saveHTML($comment), "\n";
+
+echo "--- Legacy behaviour ---\n";
+
+$dom = new DOMDocument;
+$comment = $dom->createComment("foobarbaz");
+try {
+ var_dump($comment->substringData(0, -1));
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+try {
+ var_dump($comment->substringData(2, -(2**32 - 2)));
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+try {
+ var_dump($comment->substringData(-(2**32 - 2), 2));
+} catch (DOMException $e) {
+ echo $e->getMessage(), "\n";
+}
+echo $dom->saveHTML($comment), "\n";
+
+?>
+--EXPECT--
+--- Modern behaviour ---
+string(9) "foobarbaz"
+<!--foobarbaz-->
+string(2) "ob"
+<!--foobarbaz-->
+string(2) "ob"
+<!--foobarbaz-->
+--- Legacy behaviour ---
+Index Size Error
+<!--foobarbaz-->
+Index Size Error
+<!--foobarbaz-->
+Index Size Error
+<!--foobarbaz-->