Issues (25)

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/Reader/Reader.php (2 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 CHMLib\Reader;
4
5
/**
6
 * Read data from a generic source.
7
 */
8
abstract class Reader
9
{
10
    /**
11
     * Set the current position.
12
     *
13
     * @param int $position
14
     *
15
     * @throws \Exception Throws an Exception in case of errors.
16
     */
17
    abstract public function setPosition($position);
18
19
    /**
20
     * Get the current position.
21
     *
22
     * @throws \Exception Throws an Exception in case of errors.
23
     *
24
     * @return int
25
     */
26
    abstract public function getPosition();
27
28
    /**
29
     * Get the total length of the data.
30
     *
31
     * @return int
32
     */
33
    abstract public function getLength();
34
35
    /**
36
     * Read a fixed number of bytes as a raw string.
37
     *
38
     * @param int $length The number of bytes to read.
39
     *
40
     * @throws \Exception Throws an Exception in case of errors.
41
     *
42
     * @return string
43
     */
44
    abstract public function readString($length);
45
46
    /**
47
     * Read a fixed number of bytes and return it as a byte array.
48
     *
49
     * @param int $length The number of bytes to read.
50
     *
51
     * @throws \Exception Throws an Exception in case of errors.
52
     *
53
     * @return int[]
54
     */
55 4
    public function readBytes($length)
56
    {
57 4
        $data = $this->readString($length);
58
59
        switch ($length) {
60 4
            case 0:
61
                $result = array();
62
                break;
63 4
            case 1:
64 4
                $result = array(ord($data[0]));
65 4
                break;
66
            default:
67
                $result = unpack('C*', $data);
68
                break;
69
        }
70
71 4
        return $result;
72
    }
73
74
    /**
75
     * Read a byte.
76
     *
77
     * @throws \Exception Throws an Exception in case of errors.
78
     *
79
     * @return int
80
     */
81 4
    public function readByte()
82
    {
83 4
        $bytes = $this->readBytes(1);
84
85 4
        return $bytes[0];
86
    }
87
88
    /**
89
     * Read an unsigned 16-bit integer (little endian).
90
     *
91
     * @throws \Exception Throws an Exception in case of errors.
92
     *
93
     * @return int
94
     */
95 26
    public function readUInt16()
96
    {
97 26
        $chunk = unpack('v', $this->readString(2));
98
99 26
        return array_pop($chunk);
100
    }
101
102
    /**
103
     * Read an unsigned 32-bit integer (little endian).
104
     *
105
     * @throws \Exception Throws an Exception in case of errors.
106
     *
107
     * @return int
108
     */
109 4
    public function readUInt32()
110
    {
111 4
        $bytes = $this->readString(4);
112 4
        $chunk = unpack('V', $bytes);
113 4
        $int = array_pop($chunk);
114 4 View Code Duplication
        if ($int < 0) {
0 ignored issues
show
This code seems to be duplicated across 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...
115
            $bits = decbin($int);
116
            $int = bindec(substr($bits, 0, -1)) * 2;
117
            if (substr($bits, -1) === '1') {
118
                $int += 1;
119
            }
120
        }
121
122 4
        return $int;
123
    }
124
125
    /**
126
     * Read a signed 32-bit integer (little endian).
127
     *
128
     * @throws \Exception Throws an Exception in case of errors.
129
     *
130
     * @return int
131
     */
132 4
    public function readInt32()
133
    {
134 4
        static $osIsBigEndian;
135 4
        if (!isset($osIsBigEndian)) {
136 1
            $osIsBigEndian = (pack('L', 1) === pack('N', 1)) ? true : false;
137
        }
138 4
        $data = $this->readString(4);
139 4
        if ($osIsBigEndian) {
140
            $data = strrev($data);
141
        }
142 4
        $chunk = unpack('l', $data);
143
144 4
        return array_pop($chunk);
145
    }
146
147
    /**
148
     * Read an unsigned 64-bit integer (little endian).
149
     *
150
     * @throws \Exception Throws an Exception in case of errors.
151
     *
152
     * @return int|float
153
     */
154 4
    public function readUInt64()
155
    {
156 4
        static $nativeUnpack;
157
158 4
        if (!isset($nativeUnpack)) {
159 1
            $nativeUnpack = (PHP_INT_SIZE >= 8 && version_compare(PHP_VERSION, '5.6.3') >= 0) ? true : false;
160
        }
161 4
        if ($nativeUnpack) {
162 4
            $chunk = unpack('P', $this->readString(8));
163 4
            $result = array_pop($chunk);
164 4 View Code Duplication
            if ($result < 0) {
0 ignored issues
show
This code seems to be duplicated across 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...
165
                $bits = decbin($result);
166
                $result = bindec(substr($bits, 0, -1)) * 2;
167
                if (substr($bits, -1) === '1') {
168 4
                    $result += 1;
169
                }
170
            }
171
        } else {
172
            $n1 = $this->readUInt32();
173
            $n2 = $this->readUInt32();
174
175
            $result = $n2 * 0x100000000 + $n1;
176
            if ($result <= PHP_INT_MAX) {
177
                $result = (int) $result;
178
            }
179
        }
180
181 4
        return $result;
182
    }
183
184
    /**
185
     * Read a GUID.
186
     *
187
     * @throws \Exception Throws an Exception in case of errors.
188
     *
189
     * @return string
190
     *
191
     * @example '{5D02926A-212E-11D0-9DF9-00A0C922E6EC}'
192
     */
193 4
    public function readGUID()
194
    {
195 4
        return sprintf(
196 4
            '{%1$08X-%2$04X-%3$04X-%4$02X%5$02X-%6$02X%7$02X-%8$02X%9$02X-%10$02X%11$02X}',
197 4
            $this->readUInt32(),
198 4
            $this->readUInt16(),
199 4
            $this->readUInt16(),
200 4
            $this->readByte(),
201 4
            $this->readByte(),
202 4
            $this->readByte(),
203 4
            $this->readByte(),
204 4
            $this->readByte(),
205 4
            $this->readByte(),
206 4
            $this->readByte(),
207 4
            $this->readByte()
208
        );
209
    }
210
211
    /**
212
     * Read a compressed unsigned 32-bit integer (little endian).
213
     *
214
     * @return number
215
     */
216 4
    public function readCompressedUInt32()
217
    {
218 4
        $result = 0;
219 4
        for (; ;) {
220 4
            $result <<= 7;
221 4
            $byte = $this->readByte();
222 4
            if ($byte < 0x80) {
223 4
                $result += $byte;
224 4
                break;
225
            }
226 4
            $result += $byte & 0x7f;
227
        }
228
229 4
        return $result;
230
    }
231
}
232