Commit 6e5d3e83 authored by Etienne CHAMPETIER's avatar Etienne CHAMPETIER

ZP-797 WBXMLEncoder remove possible endless loop/improve multipart handling.

Released under the Affero GNU General Public License (AGPL) version 3.

(if $bp isn't a ressource, !feof($bp) === true ...)
check $bp with is_ressource()
fclose $bp
use stream_copy_to_stream (more efficient)
parent 5accbeef
...@@ -223,6 +223,8 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -223,6 +223,8 @@ class WBXMLEncoder extends WBXMLDefs {
* @return void * @return void
*/ */
public function addBodypartStream($bp) { public function addBodypartStream($bp) {
if (!is_resource($bp))
throw new WBXMLException("WBXMLEncoder->addBodypartStream(): trying to add a ".gettype($bp)." instead of a stream");
if ($this->multipart) if ($this->multipart)
$this->bodyparts[] = $bp; $this->bodyparts[] = $bp;
} }
...@@ -536,25 +538,20 @@ class WBXMLEncoder extends WBXMLDefs { ...@@ -536,25 +538,20 @@ class WBXMLEncoder extends WBXMLDefs {
$nrBodyparts = $this->getBodypartsCount(); $nrBodyparts = $this->getBodypartsCount();
$blockstart = (($nrBodyparts + 1) * 2) * 4 + 4; $blockstart = (($nrBodyparts + 1) * 2) * 4 + 4;
$data = pack("iii", ($nrBodyparts + 1), $blockstart, $len); fwrite($this->_out, pack("iii", ($nrBodyparts + 1), $blockstart, $len));
ob_start(null, 1048576);
foreach ($this->bodyparts as $bp) { foreach ($this->bodyparts as $bp) {
$blockstart = $blockstart + $len; $blockstart = $blockstart + $len;
$len = fstat($bp); $len = fstat($bp);
$len = (isset($len['size'])) ? $len['size'] : 0; $len = (isset($len['size'])) ? $len['size'] : 0;
$data .= pack("ii", $blockstart, $len); fwrite($this->_out, pack("ii", $blockstart, $len));
} }
fwrite($this->_out, $data);
fwrite($this->_out, $buffer); fwrite($this->_out, $buffer);
foreach($this->bodyparts as $bp) { foreach($this->bodyparts as $bp) {
while (!feof($bp)) { stream_copy_to_stream($bp, $this->_out);
$out = fread($bp, 4096); fclose($bp);
fwrite($this->_out, $out);
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment