summaryrefslogtreecommitdiffstats
path: root/apps/files_encryption/lib/cryptstream.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/files_encryption/lib/cryptstream.php')
-rw-r--r--apps/files_encryption/lib/cryptstream.php17
1 files changed, 14 insertions, 3 deletions
diff --git a/apps/files_encryption/lib/cryptstream.php b/apps/files_encryption/lib/cryptstream.php
index 64fec381ded..4ef7d1e08bb 100644
--- a/apps/files_encryption/lib/cryptstream.php
+++ b/apps/files_encryption/lib/cryptstream.php
@@ -35,6 +35,7 @@ class OC_CryptStream{
private $meta=array();//header/meta for source stream
private $count;
private $writeCache;
+ private $size;
private static $rootView;
public function stream_open($path, $mode, $options, &$opened_path){
@@ -45,8 +46,14 @@ class OC_CryptStream{
if(dirname($path)=='streams' and isset(self::$sourceStreams[basename($path)])){
$this->source=self::$sourceStreams[basename($path)]['stream'];
$this->path=self::$sourceStreams[basename($path)]['path'];
+ $this->size=self::$sourceStreams[basename($path)]['size'];
}else{
$this->path=$path;
+ if($mode=='w' or $mode=='w+' or $mode=='wb' or $mode=='wb+'){
+ $this->size=0;
+ }else{
+ $this->size=self::$rootView->filesize($path,$mode);
+ }
OC_FileProxy::$enabled=false;//disable fileproxies so we can open the source file
$this->source=self::$rootView->fopen($path,$mode);
OC_FileProxy::$enabled=true;
@@ -77,14 +84,16 @@ class OC_CryptStream{
OCP\Util::writeLog('files_encryption','php bug 21641 no longer holds, decryption will not work',OCP\Util::FATAL);
die();
}
+ $pos=ftell($this->source);
$data=fread($this->source,8192);
if(strlen($data)){
$result=OC_Crypt::decrypt($data);
}else{
$result='';
}
- if($this->stream_eof()){
- $result=rtrim($result, "\0");
+ $length=$this->size-$pos;
+ if($length<8192){
+ $result=substr($result,0,$length);
}
return $result;
}
@@ -116,6 +125,8 @@ class OC_CryptStream{
$data=substr($data,8192);
}
}
+ $currentPos=ftell($this->source);
+ $this->size=max($this->size,$currentPos);
return $length;
}
@@ -159,7 +170,7 @@ class OC_CryptStream{
public function stream_close(){
$this->flush();
if($this->meta['mode']!='r' and $this->meta['mode']!='rb'){
- OC_FileCache::put($this->path,array('encrypted'=>true),'');
+ OC_FileCache::put($this->path,array('encrypted'=>true,'size'=>$this->size),'');
}
return fclose($this->source);
}