This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | ////////////////////////////////////////////////////////////// |
||
3 | // phpThumb() by James Heinrich <[email protected]> // |
||
4 | // available at http://phpthumb.sourceforge.net // |
||
5 | // and/or https://github.com/JamesHeinrich/phpThumb // |
||
6 | ////////////////////////////////////////////////////////////// |
||
7 | /// // |
||
8 | // phpthumb.ico.php - .ICO output format functions // |
||
9 | // /// |
||
10 | ////////////////////////////////////////////////////////////// |
||
11 | |||
12 | /** |
||
13 | * Class phpthumb_ico |
||
14 | */ |
||
15 | class phpthumb_ico |
||
16 | { |
||
17 | |||
18 | // removed for XOOPS |
||
19 | //function phpthumb_ico() { |
||
20 | // return true; |
||
21 | //} |
||
22 | |||
23 | /** |
||
24 | * @param $gd_image_array |
||
25 | * @return string |
||
26 | */ |
||
27 | public function GD2ICOstring(&$gd_image_array) |
||
28 | { |
||
29 | foreach ($gd_image_array as $key => $gd_image) { |
||
30 | $ImageWidths[$key] = imagesx($gd_image); |
||
0 ignored issues
–
show
|
|||
31 | $ImageHeights[$key] = imagesy($gd_image); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$ImageHeights was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ImageHeights = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
32 | $bpp[$key] = imageistruecolor($gd_image) ? 32 : 24; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$bpp was never initialized. Although not strictly required by PHP, it is generally a good practice to add $bpp = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
33 | $totalcolors[$key] = imagecolorstotal($gd_image); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$totalcolors was never initialized. Although not strictly required by PHP, it is generally a good practice to add $totalcolors = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
34 | |||
35 | $icXOR[$key] = ''; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$icXOR was never initialized. Although not strictly required by PHP, it is generally a good practice to add $icXOR = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
36 | for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
||
0 ignored issues
–
show
The variable
$ImageHeights does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
37 | for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
||
0 ignored issues
–
show
The variable
$ImageWidths does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
38 | $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
||
39 | $a = round(255 * ((127 - $argb['alpha']) / 127)); |
||
40 | $r = $argb['red']; |
||
41 | $g = $argb['green']; |
||
42 | $b = $argb['blue']; |
||
43 | |||
44 | if ($bpp[$key] == 32) { |
||
45 | $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
||
0 ignored issues
–
show
The variable
$icXOR does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
46 | } elseif ($bpp[$key] == 24) { |
||
0 ignored issues
–
show
The variable
$bpp does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
47 | $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
||
48 | } |
||
49 | |||
50 | if ($a < 128) { |
||
51 | @$icANDmask[$key][$y] .= '1'; |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
52 | } else { |
||
53 | @$icANDmask[$key][$y] .= '0'; |
||
0 ignored issues
–
show
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.
If you suppress an error, we recommend checking for the error condition explicitly: // For example instead of
@mkdir($dir);
// Better use
if (@mkdir($dir) === false) {
throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
![]() |
|||
54 | } |
||
55 | } |
||
56 | // mask bits are 32-bit aligned per scanline |
||
57 | while (strlen($icANDmask[$key][$y]) % 32) { |
||
58 | $icANDmask[$key][$y] .= '0'; |
||
59 | } |
||
60 | } |
||
61 | $icAND[$key] = ''; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$icAND was never initialized. Although not strictly required by PHP, it is generally a good practice to add $icAND = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
62 | foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
||
63 | for ($i = 0, $iMax = strlen($scanlinemaskbits); $i < $iMax; $i += 8) { |
||
64 | $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
||
0 ignored issues
–
show
The variable
$icAND does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
65 | } |
||
66 | } |
||
67 | } |
||
68 | |||
69 | foreach ($gd_image_array as $key => $gd_image) { |
||
70 | $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
||
71 | |||
72 | // BITMAPINFOHEADER - 40 bytes |
||
73 | $BitmapInfoHeader[$key] = ''; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
$BitmapInfoHeader was never initialized. Although not strictly required by PHP, it is generally a good practice to add $BitmapInfoHeader = array(); before regardless.
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code. Let’s take a look at an example: foreach ($collection as $item) {
$myArray['foo'] = $item->getFoo();
if ($item->hasBar()) {
$myArray['bar'] = $item->getBar();
}
// do something with $myArray
}
As you can see in this example, the array This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop. ![]() |
|||
74 | $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
||
75 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
||
76 | // The biHeight member specifies the combined |
||
77 | // height of the XOR and AND masks. |
||
78 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
||
79 | $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
||
80 | $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
||
81 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
||
82 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
||
83 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
||
84 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
||
85 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
||
86 | $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
||
87 | } |
||
88 | |||
89 | $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
||
90 | $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
||
91 | $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
||
92 | |||
93 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
||
94 | foreach ($gd_image_array as $key => $gd_image) { |
||
95 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
||
96 | |||
97 | $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
||
98 | $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
||
99 | $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
||
0 ignored issues
–
show
The variable
$totalcolors does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
100 | $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
||
101 | |||
102 | $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
||
103 | $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
||
104 | |||
105 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
||
106 | $icondata .= phpthumb_functions::LittleEndian2String($dwBytesInRes, 4); // dwBytesInRes; // How many bytes in this resource? |
||
107 | |||
108 | $icondata .= phpthumb_functions::LittleEndian2String($dwImageOffset, 4); // dwImageOffset; // Where in the file is this image? |
||
109 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
||
0 ignored issues
–
show
The variable
$BitmapInfoHeader does not seem to be defined for all execution paths leading up to this point.
If you define a variable conditionally, it can happen that it is not defined for all execution paths. Let’s take a look at an example: function myFunction($a) {
switch ($a) {
case 'foo':
$x = 1;
break;
case 'bar':
$x = 2;
break;
}
// $x is potentially undefined here.
echo $x;
}
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined. Available Fixes
![]() |
|||
110 | $dwImageOffset += strlen($icXOR[$key]); |
||
111 | $dwImageOffset += strlen($icAND[$key]); |
||
112 | } |
||
113 | |||
114 | foreach ($gd_image_array as $key => $gd_image) { |
||
115 | $icondata .= $BitmapInfoHeader[$key]; |
||
116 | $icondata .= $icXOR[$key]; |
||
117 | $icondata .= $icAND[$key]; |
||
118 | } |
||
119 | |||
120 | return $icondata; |
||
121 | } |
||
122 | } |
||
123 |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.