lib/ext
Aleksander Machniak
machniak at kolabsys.com
Fri Aug 23 19:19:04 CEST 2013
lib/ext/Syncroton/Wbxml/Abstract.php | 24 +++++++++++++++++++-----
lib/ext/Syncroton/Wbxml/Decoder.php | 2 ++
2 files changed, 21 insertions(+), 5 deletions(-)
New commits:
commit d30320b3c4eb4d2cb8310033a4718f739b8e3ee6
Author: Aleksander Machniak <alec at alec.pl>
Date: Fri Aug 23 19:15:37 2013 +0200
Fix bug in reading OPAQUE data from php://input string. Use fread() in loop
until data with specified length is fetched (Bug #1658)
diff --git a/lib/ext/Syncroton/Wbxml/Abstract.php b/lib/ext/Syncroton/Wbxml/Abstract.php
index 7fdd653..bec61f1 100644
--- a/lib/ext/Syncroton/Wbxml/Abstract.php
+++ b/lib/ext/Syncroton/Wbxml/Abstract.php
@@ -151,12 +151,26 @@ abstract class Syncroton_Wbxml_Abstract
protected function _getOpaque($_length)
{
- $string = fread($this->_stream, $_length);
-
- if($string === false) {
- throw new Syncroton_Wbxml_Exception("failed reading opaque data");
+ $string = '';
+
+ // it might happen that not complete data is read from stream.
+ // loop until all data is read or EOF
+ while ($_length) {
+ $chunk = fread($this->_stream, $_length);
+
+ if ($chunk === false) {
+ throw new Syncroton_Wbxml_Exception("failed reading opaque data");
+ }
+
+ if ($len = strlen($chunk)) {
+ $string .= $chunk;
+ $_length -= $len;
+ }
+ else if (feof($this->_stream)) {
+ break;
+ }
}
-
+
return $string;
}
diff --git a/lib/ext/Syncroton/Wbxml/Decoder.php b/lib/ext/Syncroton/Wbxml/Decoder.php
index f99b7f3..130d84f 100644
--- a/lib/ext/Syncroton/Wbxml/Decoder.php
+++ b/lib/ext/Syncroton/Wbxml/Decoder.php
@@ -129,6 +129,8 @@ class Syncroton_Wbxml_Decoder extends Syncroton_Wbxml_Abstract
case Syncroton_Wbxml_Abstract::OPAQUE:
$length = $this->_getMultibyteUInt();
if($length > 0) {
+ // @TODO: handle big data with streams
+ // E.g. in SendMail command "opaqued" <Mime> contains full email body
$opaque = $this->_getOpaque($length);
try {
// let see if we can decode it. maybe the opaque data is wbxml encoded content
More information about the commits
mailing list