|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2003-01-03 22:30 UTC] pollita@php.net
The following code works fine when "stream_filter_append()" is called only once. Adding the second call causes a segfault when fclose() is called.
<?php
class rot13_filter extends php_user_filter {
function read($length) {
$tempstr = parent::read($length);
for($i = 0; $i < strlen($tempstr); $i++)
if (($tempstr[$i] >= 'A' AND $tempstr[$i] <= 'M') OR
($tempstr[$i] >= 'a' AND $tempstr[$i] <= 'm')) $tempstr[$i] = chr(ord($tempstr[$i]) + 13);
else if (($tempstr[$i] >= 'N' AND $tempstr[$i] <= 'Z') OR
($tempstr[$i] >= 'n' AND $tempstr[$i] <= 'z')) $tempstr[$i] = chr(ord($tempstr[$i]) - 13);
return $tempstr;
}
function write($data) {
for($i = 0; $i < strlen($data); $i++)
if (($data[$i] >= 'A' AND $data[$i] <= 'M') OR
($data[$i] >= 'a' AND $data[$i] <= 'm')) $data[$i] = chr(ord($data[$i]) + 13);
else if (($data[$i] >= 'N' AND $data[$i] <= 'Z') OR
($data[$i] >= 'n' AND $data[$i] <= 'z')) $data[$i] = chr(ord($data[$i]) - 13);
return parent::write($data);
}
}
stream_register_filter("rot13", "rot13_filter")
or die("Failed to register filter");
$fp = fopen("foo-bar.txt", "r");
stream_filter_append($fp, "rot13");
stream_filter_append($fp, "rot13");
fwrite($fp, "Line1\n");
fwrite($fp, "Word - 2\n");
fwrite($fp, "Easy As 123\n");
fclose($fp);
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 11:00:01 2025 UTC |
Correction... Any two filters: stream_filter_append($fp, "rot13"); stream_filter_append($fp, "rot13"); or stream_filter_append($fp, "rot13"); stream_filter_append($fp, "default"); or stream_filter_append($fp, "default"); stream_filter_append($fp, "default"); all produce the same segfault when fclose()ing (presumably during the calls to write() or flush() in the filters). Note: "default" was previously registered using: stream_register_filter("default", "php_user_filter");