Skip to content

Commit edc4325

Browse files
committed
Add NOT_SERIALIZABLE to XMLWriter, XMLReader, SNMP, tidy, and tidyNode
These classes wrap native C handles (libxml2 writer/reader, SNMP session, libTidy document/node) that cannot survive serialization. Unserializing produces a broken object with NULL internal pointers.
1 parent 9090afd commit edc4325

File tree

12 files changed

+89
-9
lines changed

12 files changed

+89
-9
lines changed

ext/snmp/snmp.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ function snmp_get_valueretrieval(): int {}
181181

182182
function snmp_read_mib(string $filename): bool {}
183183

184+
/** @not-serializable */
184185
class SNMP
185186
{
186187
/** @cvalue SNMP_VERSION_1 */

ext/snmp/snmp_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/snmp/tests/gh21682.phpt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
GH-21682 (SNMP should not be serializable)
3+
--EXTENSIONS--
4+
snmp
5+
--FILE--
6+
<?php
7+
$s = new SNMP(SNMP::VERSION_1, "localhost", "public");
8+
try {
9+
serialize($s);
10+
echo "ERROR: should have thrown\n";
11+
} catch (\Exception $e) {
12+
echo $e->getMessage() . "\n";
13+
}
14+
$s->close();
15+
?>
16+
--EXPECT--
17+
Serialization of 'SNMP' is not allowed

ext/tidy/tests/gh21682.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
GH-21682 (tidy and tidyNode should not be serializable)
3+
--EXTENSIONS--
4+
tidy
5+
--FILE--
6+
<?php
7+
$t = new tidy();
8+
try {
9+
serialize($t);
10+
echo "ERROR: should have thrown\n";
11+
} catch (\Exception $e) {
12+
echo $e->getMessage() . "\n";
13+
}
14+
15+
$t->parseString("<html><body>test</body></html>");
16+
$node = $t->body();
17+
try {
18+
serialize($node);
19+
echo "ERROR: should have thrown\n";
20+
} catch (\Exception $e) {
21+
echo $e->getMessage() . "\n";
22+
}
23+
?>
24+
--EXPECT--
25+
Serialization of 'tidy' is not allowed
26+
Serialization of 'tidyNode' is not allowed

ext/tidy/tidy.stub.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,7 @@ function tidy_get_head(tidy $tidy): ?tidyNode {}
861861

862862
function tidy_get_body(tidy $tidy): ?tidyNode {}
863863

864+
/** @not-serializable */
864865
class tidy
865866
{
866867
public ?string $errorBuffer = null;
@@ -973,6 +974,7 @@ public function html(): ?tidyNode {}
973974
public function body(): ?tidyNode {}
974975
}
975976

977+
/** @not-serializable */
976978
final class tidyNode
977979
{
978980
public readonly string $value;

ext/tidy/tidy_arginfo.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/xmlreader/php_xmlreader.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
/** @generate-class-entries */
44

5+
/** @not-serializable */
56
class XMLReader
67
{
78
/* Constants for NodeType - cannot define common types to share with dom as there are differences in these types */

ext/xmlreader/php_xmlreader_arginfo.h

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/xmlreader/tests/gh21682.phpt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
GH-21682 (XMLReader should not be serializable)
3+
--EXTENSIONS--
4+
xmlreader
5+
--FILE--
6+
<?php
7+
$r = new XMLReader();
8+
try {
9+
serialize($r);
10+
echo "ERROR: should have thrown\n";
11+
} catch (\Exception $e) {
12+
echo $e->getMessage() . "\n";
13+
}
14+
?>
15+
--EXPECT--
16+
Serialization of 'XMLReader' is not allowed

ext/xmlwriter/php_xmlwriter.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ function xmlwriter_output_memory(XMLWriter $writer, bool $flush = true): string
8686

8787
function xmlwriter_flush(XMLWriter $writer, bool $empty = true): string|int {}
8888

89+
/** @not-serializable */
8990
class XMLWriter
9091
{
9192
/**

0 commit comments

Comments
 (0)