hi,
i've made some tests with file_register_wrapper and a possible
"my-own-get-from-variable-instead-of-file-handle" wrapper, but i think
that the stream_open function handler is not binary safe.
Here a small code snip to demonstrate the problem:
<?php
class variable_stream {
var $data;
var $data_length=0;
var $pointer;
function stream_open($path, $mode, $options, &$opened_path)
{
// not really elegant, because the class don't know
// the own name
$this->data=substr($path,11);
$this->data_length=strlen($this->data);
$this->pointer=0;
return true;
}
function stream_close(){
unset($this->data, $this->pointer);
}
function stream_read($count)
{
$returnvalue=substr($this->data,$this->pointer,$count);
$this->pointer+=$count;
return $returnvalue;
}
function stream_gets()
{
$this->pointer=$this->data_length;
return $this->data;
}
}
file_register_wrapper('variable', 'variable_stream') or die('Failed to
register protocol');
$content='foo'.chr(0).'bar';
echo strlen( file_get_contents ('variable://'.$content) );
?>
results a length of 3 instead of 7.
Also when stream_read results more bytes as file_get_contents or another
command
requested, php results a segfault.
here the backtrace:
Program received signal SIGSEGV, Segmentation fault.
0x403ff2ad in zend_get_executed_lineno () at
/usr/src/php4/Zend/zend_execute_API.c:260
260 return active_opline->lineno;
(gdb) bt
#0 0x403ff2ad in zend_get_executed_lineno () at
/usr/src/php4/Zend/zend_execute_API.c:260
#1 0x4040a2e7 in zend_error (type=1, format=0x40450040 "Maximum
execution time of %d second%s exceeded")
at /usr/src/php4/Zend/zend.c:666
#2 0x40400a50 in zend_timeout (dummy=27) at
/usr/src/php4/Zend/zend_execute_API.c:688
#3 0x4009e478 in killpg () from /lib/libc.so.6
#4 0x403f602f in _efree (ptr=0x8165cec, __zend_filename=0x404514e0
"/usr/src/php4/Zend/zend_hash.c", __zend_lineno=548,
__zend_orig_filename=0x0, __zend_orig_lineno=0) at
/usr/src/php4/Zend/zend_alloc.c:213
#5 0x40410d11 in zend_hash_destroy (ht=0x8161374) at
/usr/src/php4/Zend/zend_hash.c:548
#6 0x40400306 in call_user_function_ex (function_table=0x8167440,
object_pp=0x8167648, function_name=0xbfffcef0,
retval_ptr_ptr=0xbfffceec, param_count=1, params=0xbfffcee8,
no_separation=0, symbol_table=0x0)
at /usr/src/php4/Zend/zend_execute_API.c:539
#7 0x403e89c6 in php_userstreamop_read (stream=0x8161424, buf=
0x4275982d "hallo", count=3044)
at /usr/src/php4/main/user_streams.c:321
#8 0x403de175 in _php_stream_read (stream=0x8161424, buf=0x4275982d
"hallo", size=3044) at /usr/src/php4/main/streams.c:313
#9 0x403dec57 in _php_stream_copy_to_mem (src=0x8161424, buf=
0xbfffd058, maxlen=0, persistent=0, __php_stream_call_depth=0,
__zend_filename=0x4042e000 "/usr/src/php4/ext/standard/file.c",
__zend_lineno=423, __zend_orig_filename=0x0,
__zend_orig_lineno=0) at /usr/src/php4/main/streams.c:591
#10 0x4035b14a in zif_file_get_contents (ht=1, return_value=0x816739c,
this_ptr=0x0, return_value_used=1)
at /usr/src/php4/ext/standard/file.c:423
#11 0x4041de99 in execute (op_array=0x8161194) at
/usr/src/php4/Zend/zend_execute.c:1602
#12 0x4040a99e in zend_execute_scripts (type=8, retval=0x0, file_count=
3) at /usr/src/php4/Zend/zend.c:814
Any helps?
Regards,
Steve
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, visit: http://www.php.net/unsub.php