PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Networking » Net_Sieve » Bug #7197

getScript() truncates long scripts

Details

Submitted2006-03-24 14:56 UTC
Frombluecamel at imap dot cc
Assignedamistry
StatusClosed
PackageNet_Sieve
PHP Version4.3.9
OSLinux
Roadmaps(Not assigned)

Comments

[2006-03-24 14:56 UTC] bluecamel at imap dot cc

Description:
------------
The default max sieve script size in Cyrus 2.3.1 is 32k. Net::Socket::read() called by Net::Sieve::_doCmd() uses php fread() to read a specific string length from the timsieved socket.

If the first packet returned by timsieved is smaller than the string size requested by fread() then the remainder of the string was being truncated. The result is large scripts (27k+ in my case) are truncated at about 11k.

This is correct behavior according to the php fread() manual:

fread() reads up to length bytes from the file pointer referenced by handle. Reading stops when up to length bytes have been read, EOF (end of file) is reached, (for network streams) when a packet becomes available, or (after opening userspace stream) when 8192 bytes have been read whichever comes first.

Test script:
---------------
// connect to sieve
if ( PEAR::isError( $sieve = my_sieve_connect($euser) ) ) {
return $sieve;
}
$sieve->setDebug(TRUE);
$result = $sieve->getScript($large_script);
$sieve->disconnect();
var_dump($result);

[2006-03-24 15:00 UTC] bluecamel at imap dot cc

Possible patch. Note the line wraps! Also available at http://files.bluecamel.imap.cc/

--- Sieve.php.orig 2006-03-23 19:29:39.000000000 -0500
+++ Sieve.php 2006-03-24 09:15:47.000000000 -0500
@@ -993,7 +993,11 @@
} elseif (preg_match('/^{([0-9]+)\+?}/i', $line, $matches)) {
// Matches String Responses.
//$line = str_replace("\r\n", ' ', $this->_sock->read($matches[1] + 2 ));
- $line = $this->_sock->read($matches[1] + 2 );
+ $str_size = $matches[1] + 2;
+ $line = '';
+ while (strlen($line) != $str_size) {
+ $line .= $this->_sock->read($str_size - strlen($line));
+ }
if($this->_debug){
echo "S:$line\n";
}

[2006-03-24 15:45 UTC] amistry at php dot net

I'll take a look at it this weekend. Thanks for the report.

[2006-03-26 19:22 UTC] amistry at php dot net

I've fixed this in the CVS with a slightly modified version of your patch. Please test it and let me know. Thanks.

[2006-04-01 19:27 UTC] amistry at php dot net

Any news? I'd like to cut a release this weekend and want to make sure this works for you. Thanks.

[2006-04-20 01:23 UTC] bluecamel at imap dot cc

Sorry about that. I'm a bit clueless on pear setup so am
unsure _where_ the CVS repo might be. I assume it's anonymous
pserver. What is CVSROOT for it?

[2006-04-20 03:26 UTC] amistry at php dot net

http://www.php.net/anoncvs.php

You want to checkout pear/Net_Sieve

[2006-05-21 06:37 UTC] amistry at php dot net

Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pear.php.net/get/Net_Sieve