Issues (15)

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/Imagick/Image.php (4 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
 * This file is part of the Magickly project.
4
 *
5
 * @author Daniel Schröder <[email protected]>
6
 */
7
8
namespace GravityMedia\Magickly\Imagick;
9
10
use GravityMedia\Magickly\Enum\ColorSpace;
11
use GravityMedia\Magickly\Enum\Type;
12
use GravityMedia\Magickly\Exception\RuntimeException;
13
use GravityMedia\Magickly\Image\AbstractImage;
14
use GravityMedia\Magickly\Image\ColorProfile;
15
use GuzzleHttp\Stream\Utils as StreamUtils;
16
17
/**
18
 * The image class.
19
 *
20
 * @package GravityMedia\Magickly\Imagick
21
 */
22
class Image extends AbstractImage
23
{
24
    /**
25
     * @var \Imagick
26
     */
27
    private $imagick;
28
29
    /**
30
     * @var array
31
     */
32
    protected static $typeMapping = [
33
        Type::TYPE_BILEVEL => \Imagick::IMGTYPE_BILEVEL,
34
        Type::TYPE_GRAYSCALE => \Imagick::IMGTYPE_GRAYSCALE,
35
        Type::TYPE_PALETTE => \Imagick::IMGTYPE_PALETTE,
36
        Type::TYPE_TRUECOLOR => \Imagick::IMGTYPE_TRUECOLOR,
37
        Type::TYPE_COLORSEPARATION => \Imagick::IMGTYPE_COLORSEPARATION,
38
    ];
39
40
    /**
41
     * @var array
42
     */
43
    protected static $colorSpaceMapping = [
44
        ColorSpace::COLOR_SPACE_RGB => \Imagick::COLORSPACE_RGB,
45
        ColorSpace::COLOR_SPACE_CMYK => \Imagick::COLORSPACE_CMYK,
46
        ColorSpace::COLOR_SPACE_GRAYSCALE => \Imagick::COLORSPACE_GRAY,
47
    ];
48
49
    /**
50
     * Create image object.
51
     *
52
     * @param \Imagick $imagick
53
     */
54 32
    public function __construct(\Imagick $imagick)
55
    {
56 32
        $this->imagick = $imagick;
57 32
    }
58
59
    /**
60
     * Clone image object.
61
     */
62 2
    public function __clone()
63
    {
64 2
        $this->imagick = clone $this->imagick;
65 2
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getStream()
71
    {
72
        return StreamUtils::create($this->imagick->getImagesBlob());
73
    }
74
75
    /**
76
     * {@inheritdoc}
77
     */
78 30 View Code Duplication
    public function getFormat()
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...
79
    {
80 30
        $format = $this->imagick->getImageFormat();
81 30
        if (!in_array($format, static::$supportedFormats)) {
82
            throw new RuntimeException('Unsupported image format');
83
        }
84
85 30
        return $format;
86
    }
87
88
    /**
89
     * {@inheritdoc}
90
     */
91 View Code Duplication
    public function withFormat($format)
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...
92
    {
93
        if (!in_array($format, static::$supportedFormats)) {
94
            throw new RuntimeException('Unsupported image format');
95
        }
96
97
        $image = clone $this;
98
        $image->imagick->setImageFormat($format);
99
100
        return $image;
101
    }
102
103
    /**
104
     * {@inheritdoc}
105
     */
106 30
    public function getType()
107
    {
108 30
        switch ($this->imagick->getImageType()) {
109 30
            case \Imagick::IMGTYPE_BILEVEL:
110
                return Type::TYPE_BILEVEL;
111 30
            case \Imagick::IMGTYPE_GRAYSCALE:
112 28
            case \Imagick::IMGTYPE_GRAYSCALEMATTE:
113 6
                return Type::TYPE_GRAYSCALE;
114 24
            case \Imagick::IMGTYPE_PALETTE:
115 22
            case \Imagick::IMGTYPE_PALETTEMATTE:
116 6
                if ('JPEG' === $this->getFormat() && ColorSpace::COLOR_SPACE_GRAYSCALE === $this->getColorSpace()) {
117 4
                    return Type::TYPE_GRAYSCALE;
118
                }
119 2
                return Type::TYPE_PALETTE;
120 18
            case \Imagick::IMGTYPE_TRUECOLOR:
121 14
            case \Imagick::IMGTYPE_TRUECOLORMATTE:
122 10
                return Type::TYPE_TRUECOLOR;
123 8
            case \Imagick::IMGTYPE_COLORSEPARATION:
124 4
            case \Imagick::IMGTYPE_COLORSEPARATIONMATTE:
125 8
                return Type::TYPE_COLORSEPARATION;
126
            default:
127
                throw new RuntimeException('Unsupported image type');
128
        }
129
    }
130
131
    /**
132
     * {@inheritdoc}
133
     */
134 View Code Duplication
    public function withType($type)
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...
135
    {
136
        if (!isset(static::$typeMapping[$type])) {
137
            throw new RuntimeException('Unsupported image type');
138
        }
139
140
        $image = clone $this;
141
        $image->imagick->setImageType(static::$typeMapping[$type]);
142
143
        return $image;
144
    }
145
146
    /**
147
     * {@inheritdoc}
148
     */
149 32
    public function getColorSpace()
150
    {
151 32
        switch ($this->imagick->getImageColorspace()) {
152 32
            case \Imagick::COLORSPACE_RGB:
153 32
            case \Imagick::COLORSPACE_SRGB:
154 14
                return ColorSpace::COLOR_SPACE_RGB;
155 20
            case \Imagick::COLORSPACE_CMYK:
156 10
                return ColorSpace::COLOR_SPACE_CMYK;
157 10
            case \Imagick::COLORSPACE_GRAY:
158 10
                return ColorSpace::COLOR_SPACE_GRAYSCALE;
159
            default:
160
                throw new RuntimeException('Only RGB, grayscale and CMYK color space are currently supported');
161
        }
162
    }
163
164
    /**
165
     * {@inheritdoc}
166
     */
167 2 View Code Duplication
    public function withColorSpace($colorSpace)
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...
168
    {
169 2
        if (!isset(static::$colorSpaceMapping[$colorSpace])) {
170
            throw new RuntimeException('Only RGB, grayscale and CMYK color space are currently supported');
171
        }
172
173 2
        $image = clone $this;
174 2
        $image->imagick->setImageColorspace(static::$colorSpaceMapping[$colorSpace]);
175
176 2
        return $image;
177
    }
178
179
    /**
180
     * {@inheritdoc}
181
     */
182
    public function getColorProfile()
183
    {
184
        if (!in_array('icc', $this->imagick->getImageProfiles('*', false))) {
185
            return null;
186
        }
187
188
        $data = $this->imagick->getImageProfile('icc');
189
190
        return new ColorProfile(StreamUtils::create($data));
191
    }
192
193
    /**
194
     * {@inheritdoc}
195
     */
196
    public function withColorProfile(ColorProfile $colorProfile)
197
    {
198
        $image = clone $this;
199
        $image->imagick->setImageProfile('icc', $colorProfile->getData());
200
201
        return $image;
202
    }
203
}
204