Issues (7)

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/BinaryReader.php (1 issue)

Labels
Severity

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 PhpBinaryReader;
4
5
use PhpBinaryReader\Exception\InvalidDataException;
6
use PhpBinaryReader\Type\Bit;
7
use PhpBinaryReader\Type\Byte;
8
use PhpBinaryReader\Type\Int8;
9
use PhpBinaryReader\Type\Int16;
10
use PhpBinaryReader\Type\Int32;
11
use PhpBinaryReader\Type\Int64;
12
use PhpBinaryReader\Type\Single;
13
use PhpBinaryReader\Type\Str;
14
15
class BinaryReader
16
{
17
    /**
18
     * @var int
19
     */
20
    private $machineByteOrder = Endian::ENDIAN_LITTLE;
21
22
    /**
23
     * @var resource 
24
     */
25
    private $inputHandle;
26
27
    /**
28
     * @var int
29
     */
30
    private $currentBit;
31
32
    /**
33
     * @var mixed
34
     */
35
    private $nextByte;
36
37
    /**
38
     * @var int
39
     */
40
    private $position;
41
42
    /**
43
     * @var int
44
     */
45
    private $eofPosition;
46
47
    /**
48
     * @var string
49
     */
50
    private $endian;
51
52
    /**
53
     * @var \PhpBinaryReader\Type\Byte
54
     */
55
    private $byteReader;
56
57
    /**
58
     * @var \PhpBinaryReader\Type\Bit
59
     */
60
    private $bitReader;
61
62
    /**
63
     * @var \PhpBinaryReader\Type\Str
64
     */
65
    private $stringReader;
66
67
    /**
68
     * @var \PhpBinaryReader\Type\Int8
69
     */
70
    private $int8Reader;
71
72
    /**
73
     * @var \PhpBinaryReader\Type\Int16
74
     */
75
    private $int16Reader;
76
77
    /**
78
     * @var \PhpBinaryReader\Type\Int32
79
     */
80
    private $int32Reader;
81
82
    /**
83
     * @var \PhpBinaryReader\Type\Int64
84
     */
85
    private $int64Reader;
86
87
    /**
88
     * @var \PhpBinaryReader\Type\Single
89
     */
90
    private $singleReader;
91
92
    /**
93
     * @param  string|resource           $input
94
     * @param  int|string                $endian
95
     * @throws \InvalidArgumentException
96
     */
97 64
    public function __construct($input, $endian = Endian::ENDIAN_LITTLE)
98
    {
99 64
        if (!is_resource($input)) {
100 19
            $this->setInputString($input);
0 ignored issues
show
It seems like $input defined by parameter $input on line 97 can also be of type resource; however, PhpBinaryReader\BinaryReader::setInputString() does only seem to accept string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
101
        } else {
102 45
            $this->setInputHandle($input);
103
        }
104
105 64
        $this->eofPosition = fstat($this->getInputHandle())['size'];
106
107 64
        $this->setEndian($endian);
108 64
        $this->setNextByte(false);
109 64
        $this->setCurrentBit(0);
110 64
        $this->setPosition(0);
111
112 64
        $this->bitReader = new Bit();
113 64
        $this->stringReader = new Str();
114 64
        $this->byteReader = new Byte();
115 64
        $this->int8Reader = new Int8();
116 64
        $this->int16Reader = new Int16();
117 64
        $this->int32Reader = new Int32();
118 64
        $this->int64Reader = new Int64();
119 64
        $this->singleReader = new Single();
120 64
    }
121
122
    /**
123
     * @return bool
124
     */
125 2
    public function isEof()
126
    {
127 2
        return $this->position >= $this->eofPosition;
128
    }
129
130
    /**
131
     * @param int $length
132
     * @return bool
133
     */
134 134
    public function canReadBytes($length = 0)
135
    {
136 134
        return $this->position + $length <= $this->eofPosition;
137
    }
138
139
    /**
140
     * @return void
141
     */
142 14
    public function align()
143
    {
144 14
        $this->setCurrentBit(0);
145 14
        $this->setNextByte(false);
146 14
    }
147
148
    /**
149
     * @param  int $count
150
     * @return int
151
     */
152 74
    public function readBits($count)
153
    {
154 74
        return $this->bitReader->readSigned($this, $count);
155
    }
156
157
    /**
158
     * @param  int $count
159
     * @return int
160
     */
161 4
    public function readUBits($count)
162
    {
163 4
        return $this->bitReader->read($this, $count);
164
    }
165
166
    /**
167
     * @param  int $count
168
     * @return int
169
     */
170 2
    public function readBytes($count)
171
    {
172 2
        return $this->byteReader->read($this, $count);
173
    }
174
175
    /**
176
     * @return int
177
     */
178 36
    public function readInt8()
179
    {
180 36
        return $this->int8Reader->readSigned($this);
181
    }
182
183
    /**
184
     * @return int
185
     */
186 4
    public function readUInt8()
187
    {
188 4
        return $this->int8Reader->read($this);
189
    }
190
191
    /**
192
     * @return int
193
     */
194 4
    public function readInt16()
195
    {
196 4
        return $this->int16Reader->readSigned($this);
197
    }
198
199
    /**
200
     * @return string
201
     */
202 6
    public function readUInt16()
203
    {
204 6
        return $this->int16Reader->read($this);
205
    }
206
207
    /**
208
     * @return int
209
     */
210 6
    public function readInt32()
211
    {
212 6
        return $this->int32Reader->readSigned($this);
213
    }
214
215
    /**
216
     * @return int
217
     */
218 6
    public function readUInt32()
219
    {
220 6
        return $this->int32Reader->read($this);
221
    }
222
223
    /**
224
     * @return int
225
     */
226 2
    public function readInt64()
227
    {
228 2
        return $this->int64Reader->readSigned($this);
229
    }
230
231
    /**
232
     * @return int
233
     */
234 2
    public function readUInt64()
235
    {
236 2
        return $this->int64Reader->read($this);
237
    }
238
239
    /**
240
     * @return float
241
     */
242 2
    public function readSingle()
243
    {
244 2
        return $this->singleReader->read($this);
245
    }
246
247
    /**
248
     * @param  int    $length
249
     * @return string
250
     */
251 2
    public function readString($length)
252
    {
253 2
        return $this->stringReader->read($this, $length);
254
    }
255
256
    /**
257
     * @param  int    $length
258
     * @return string
259
     */
260 2
    public function readAlignedString($length)
261
    {
262 2
        return $this->stringReader->readAligned($this, $length);
263
    }
264
265
    /**
266
     * @param  int   $machineByteOrder
267
     * @return $this
268
     */
269 8
    public function setMachineByteOrder($machineByteOrder)
270
    {
271 8
        $this->machineByteOrder = $machineByteOrder;
272
273 8
        return $this;
274
    }
275
276
    /**
277
     * @return int
278
     */
279 32
    public function getMachineByteOrder()
280
    {
281 32
        return $this->machineByteOrder;
282
    }
283
284
    /**
285
     * @param  resource $inputHandle
286
     * @return $this
287
     */
288 45
    public function setInputHandle($inputHandle)
289
    {
290 45
        $this->inputHandle = $inputHandle;
291
292 45
        return $this;
293
    }
294
295
    /**
296
     * @return resource
297
     */
298 114
    public function getInputHandle()
299
    {
300 114
        return $this->inputHandle;
301
    }
302
303
    /**
304
     * @param string $inputString
305
     * @return $this
306
     */
307 21
    public function setInputString($inputString)
308
    {
309 21
        $handle = fopen('php://memory', 'br+');
310 21
        fwrite($handle, $inputString);
311 21
        rewind($handle);
312 21
        $this->inputHandle = $handle;
313
314 21
        return $this;
315
    }
316
317
    /**
318
     * @return string
319
     */
320 2
    public function getInputString()
321
    {
322 2
        $handle = $this->getInputHandle();
323 2
        $str = stream_get_contents($handle);
324 2
        rewind($handle);
325
326 2
        return $str;
327
    }
328
329
    /**
330
     * @param  mixed $nextByte
331
     * @return $this
332
     */
333 116
    public function setNextByte($nextByte)
334
    {
335 116
        $this->nextByte = $nextByte;
336
337 116
        return $this;
338
    }
339
340
    /**
341
     * @return mixed
342
     */
343 66
    public function getNextByte()
344
    {
345 66
        return $this->nextByte;
346
    }
347
348
    /**
349
     * @param  int   $position
350
     * @return $this
351
     */
352 114
    public function setPosition($position)
353
    {
354 114
        $this->position = $position;
355 114
        fseek($this->getInputHandle(), $position);
356
357 114
        return $this;
358
    }
359
360
    /**
361
     * @return int
362
     */
363 4
    public function getPosition()
364
    {
365 4
        return $this->position;
366
    }
367
368
    /**
369
     * @return int
370
     */
371 2
    public function getEofPosition()
372
    {
373 2
        return $this->eofPosition;
374
    }
375
376
    /**
377
     * @param  string               $endian
378
     * @return $this
379
     * @throws InvalidDataException
380
     */
381 68
    public function setEndian($endian)
382
    {
383 68
        if ($endian == 'big' || $endian == Endian::ENDIAN_BIG) {
384 64
            $this->endian = Endian::ENDIAN_BIG;
385 68
        } elseif ($endian == 'little' || $endian == Endian::ENDIAN_LITTLE) {
386 68
            $this->endian = Endian::ENDIAN_LITTLE;
387
        } else {
388 2
            throw new InvalidDataException('Endian must be set as big or little');
389
        }
390
391 68
        return $this;
392
    }
393
394
    /**
395
     * @return string
396
     */
397 68
    public function getEndian()
398
    {
399 68
        return $this->endian;
400
    }
401
402
    /**
403
     * @param  int   $currentBit
404
     * @return $this
405
     */
406 116
    public function setCurrentBit($currentBit)
407
    {
408 116
        $this->currentBit = $currentBit;
409
410 116
        return $this;
411
    }
412
413
    /**
414
     * @return int
415
     */
416 124
    public function getCurrentBit()
417
    {
418 124
        return $this->currentBit;
419
    }
420
421
    /**
422
     * @return \PhpBinaryReader\Type\Bit
423
     */
424 1
    public function getBitReader()
425
    {
426 1
        return $this->bitReader;
427
    }
428
429
    /**
430
     * @return \PhpBinaryReader\Type\Byte
431
     */
432 1
    public function getByteReader()
433
    {
434 1
        return $this->byteReader;
435
    }
436
437
    /**
438
     * @return \PhpBinaryReader\Type\Int8
439
     */
440 1
    public function getInt8Reader()
441
    {
442 1
        return $this->int8Reader;
443
    }
444
445
    /**
446
     * @return \PhpBinaryReader\Type\Int16
447
     */
448 1
    public function getInt16Reader()
449
    {
450 1
        return $this->int16Reader;
451
    }
452
453
    /**
454
     * @return \PhpBinaryReader\Type\Int32
455
     */
456 1
    public function getInt32Reader()
457
    {
458 1
        return $this->int32Reader;
459
    }
460
461
    /**
462
     * @return \PhpBinaryReader\Type\Int64
463
     */
464 1
    public function getInt64Reader()
465
    {
466 1
        return $this->int64Reader;
467
    }
468
469
    /**
470
     * @return \PhpBinaryReader\Type\Single
471
     */
472 1
    public function getSingleReader()
473
    {
474 1
        return $this->singleReader;
475
    }
476
477
    /**
478
     * @return \PhpBinaryReader\Type\Str
479
     */
480 1
    public function getStringReader()
481
    {
482 1
        return $this->stringReader;
483
    }
484
485
    /**
486
     * Read a length of characters from the input handle, updating the
487
     * internal position marker.
488
     *
489
     * @return string
490
     */
491 130
    public function readFromHandle($length)
492
    {
493 130
        $this->position += $length;
494 130
        return fread($this->inputHandle, $length);
495
    }
496
}
497