mirror of
https://github.com/php/php-src.git
synced 2026-03-24 00:02:20 +01:00
Fix 32-bit DOM characterdata failures (#13663)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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-->
|
||||
|
||||
@@ -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-->
|
||||
@@ -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-->
|
||||
|
||||
@@ -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-->
|
||||
@@ -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";
|
||||
}
|
||||
var_dump($comment->substringData(2, -2));
|
||||
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));
|
||||
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-->
|
||||
|
||||
@@ -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-->
|
||||
Reference in New Issue
Block a user