Issues (33)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Stream/StreamSeeker.php (3 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Dazzle\Stream;
4
5
use Dazzle\Event\BaseEventEmitter;
6
use Dazzle\Throwable\Exception\Runtime\ReadException;
7
use Dazzle\Throwable\Exception\Runtime\WriteException;
8
use Dazzle\Throwable\Exception\Logic\InvalidArgumentException;
9
use Error;
10
use Exception;
11
12
class StreamSeeker extends BaseEventEmitter implements StreamSeekerInterface
13
{
14
    /**
15
     * @var resource
16
     */
17
    protected $resource;
18
19
    /**
20
     * @var bool
21
     */
22
    protected $autoClose;
23
24
    /**
25
     * @var bool
26
     */
27
    protected $closing;
28
29
    /**
30
     * @param resource $resource
31
     * @param bool $autoClose
32
     * @throws InvalidArgumentException
33
     */
34 115
    public function __construct($resource, $autoClose = true)
35
    {
36 115
        if (!is_resource($resource))
37
        {
38 7
             throw new InvalidArgumentException('First parameter must be a valid resource.');
39
        }
40
41 108
        $this->resource = $resource;
42 108
        $this->autoClose = $autoClose;
43 108
        $this->closing = false;
44
45 108
        if (function_exists('stream_set_blocking'))
46
        {
47 108
            stream_set_blocking($this->resource, 0);
48
        }
49 108
    }
50
51
    /**
52
     *
53
     */
54 89
    public function __destruct()
55
    {
56 89
        $this->handleClose();
57
58 89
        parent::__destruct();
59
60 89
        unset($this->resource);
61 89
        unset($this->autoClose);
62 89
        unset($this->closing);
63 89
    }
64
65
    /**
66
     * @override
67
     * @inheritDoc
68
     */
69 36
    public function getResource()
70
    {
71 36
        return $this->resource;
72
    }
73
74
    /**
75
     * @override
76
     * @inheritDoc
77
     */
78 7
    public function getResourceId()
79
    {
80 7
        return (int) $this->resource;
81
    }
82
83
    /**
84
     * @override
85
     * @inheritDoc
86
     */
87 40
    public function getMetadata()
88
    {
89 40
        return stream_get_meta_data($this->resource);
90
    }
91
92
    /**
93
     * @override
94
     * @inheritDoc
95
     */
96
    public function getStreamType()
97
    {
98
        return $this->getMetadata()['stream_type'];
99
    }
100
101
    /**
102
     * @override
103
     * @inheritDoc
104
     */
105
    public function getWrapperType()
106
    {
107
        return $this->getMetadata()['wrapper_type'];
108
    }
109
110
    /**
111
     * @override
112
     * @inheritDoc
113
     */
114 21
    public function isOpen()
115
    {
116 21
        return !$this->closing;
117
    }
118
119
    /**
120
     * @override
121
     * @inheritDoc
122
     */
123 33
    public function isSeekable()
124
    {
125 33
        return $this->getMetadata()['seekable'];
126
    }
127
128
    /**
129
     * @override
130
     * @inheritDoc
131
     */
132 14
    public function tell()
133
    {
134 14
        if (!$this->isSeekable())
135
        {
136
            throw new ReadException('Cannt tell offset of this kind of stream.');
137
        }
138
139 14
        $ret = ftell($this->resource);
140 14
        if ($ret === false)
141
        {
142
            throw new ReadException('Cannot tell offset of stream.');
143
        }
144
145 14
        return $ret;
146
    }
147
148
    /**
149
     * @override
150
     * @inheritDoc
151
     */
152 7
    public function seek($offset, $whence = SEEK_SET)
153
    {
154 7
        if (!$this->isSeekable())
155
        {
156
            throw new WriteException('Cannt seek on this kind of stream.');
157
        }
158
159 7
        $pointer = fseek($this->resource, $offset, $whence);
160 7
        if ($pointer === false)
161
        {
162
            throw new WriteException('Cannot seek on stream.');
163
        }
164
165 7
        $this->emit('seek', [ $this, $pointer ]);
166 7
    }
167
168
    /**
169
     * @override
170
     * @inheritDoc
171
     */
172 12
    public function rewind()
173
    {
174 12
        if (!$this->isSeekable())
175
        {
176
            throw new WriteException('Cannt rewind this kind of stream.');
177
        }
178
179 12
        if (false === rewind($this->resource))
180
        {
181
            throw new WriteException('Cannot rewind stream.');
182
        }
183 12
    }
184
185
    /**
186
     * @override
187
     * @inheritDoc
188
     */
189 6 View Code Duplication
    public function close()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
190
    {
191 6
        if ($this->closing)
192
        {
193
            return;
194
        }
195
196 6
        $this->closing = true;
197 6
        $this->readable = false;
0 ignored issues
show
The property readable does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
198 6
        $this->writable = false;
0 ignored issues
show
The property writable does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
199
200 6
        $this->emit('close', [ $this ]);
201 6
        $this->handleClose();
202 6
        $this->emit('done', [ $this ]);
203 6
    }
204
205
    /**
206
     * Emit error event and the throws it too.
207
     *
208
     * @param Error|Exception $ex
209
     * @return null
210
     * @throws Error|Exception
211
     */
212
    protected function throwAndEmitException($ex)
213
    {
214
        $this->emit('error', [ $this, $ex ]);
215
        throw $ex;
216
    }
217
218
    /**
219
     * Handle the close of the stream object.
220
     *
221
     * @internal
222
     */
223 100
    public function handleClose()
224
    {
225 100
        if ($this->autoClose === true && is_resource($this->resource))
226
        {
227 100
            fclose($this->resource);
228
        }
229 100
    }
230
}
231