Skip to content

Commit

Permalink
[impr-OpenMage#966] Prevent filename with null byte(s) in Varien_Io_File
Browse files Browse the repository at this point in the history
  • Loading branch information
damien-biasotto authored and edannenberg committed Aug 17, 2020
1 parent 70cce30 commit c9f2985
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions lib/Varien/Io/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,8 @@ public function write($filename, $src, $mode=null)
*/
protected function _IsValidSource($src)
{
if (is_string($src) || is_resource($src)) {
//Treat string that contains a null byte as invalid
if ((is_string($src) && strpos($src, chr(0)) === false) || is_resource($src)) {
return true;
}

Expand All @@ -505,7 +506,7 @@ protected function _isFilenameWriteable($filename)
{
$error = false;
@chdir($this->_cwd);
if (file_exists($filename)) {
if (file_exists($filename)) {
if (!is_writeable($filename)) {
$error = "File '{$this->getFilteredPath($filename)}' isn't writeable";
}
Expand All @@ -532,7 +533,7 @@ protected function _isFilenameWriteable($filename)
protected function _checkSrcIsFile($src)
{
$result = false;
if (is_string($src) && @is_readable($src) && is_file($src)) {
if (is_string($src) && is_readable($src) && is_file($src)) {
$result = true;
}

Expand Down Expand Up @@ -845,7 +846,7 @@ public function dirname($file)
{
return $this->getCleanPath(dirname($file));
}

public function getStreamHandler()
{
return $this->_streamHandler;
Expand Down

0 comments on commit c9f2985

Please sign in to comment.