Issues (40)

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/Generators/Mo.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 Gettext\Generators;
4
5
use Gettext\Translations;
6
use Gettext\Utils\HeadersGeneratorTrait;
7
8
class Mo extends Generator implements GeneratorInterface
9
{
10
    use HeadersGeneratorTrait;
11
12
    public static $options = [
13
        'includeHeaders' => true,
14
    ];
15
16
    /**
17
     * {@parentDoc}.
18
     */
19
    public static function toString(Translations $translations, array $options = [])
20
    {
21
        $options += static::$options;
22
        $messages = [];
23
24
        if ($options['includeHeaders']) {
25
            $messages[''] = static::generateHeaders($translations);
26
        }
27
28
        foreach ($translations as $translation) {
29
            if (!$translation->hasTranslation() || $translation->isDisabled()) {
30
                continue;
31
            }
32
33
            if ($translation->hasContext()) {
34
                $originalString = $translation->getContext()."\x04".$translation->getOriginal();
35
            } else {
36
                $originalString = $translation->getOriginal();
37
            }
38
39
            $messages[$originalString] = $translation;
40
        }
41
42
        ksort($messages);
43
        $numEntries = count($messages);
44
        $originalsTable = '';
45
        $translationsTable = '';
46
        $originalsIndex = [];
47
        $translationsIndex = [];
48
        $pluralForm = $translations->getPluralForms();
49
        $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null;
50
51
        foreach ($messages as $originalString => $translation) {
52
            if (is_string($translation)) {
53
                // Headers
54
                $translationString = $translation;
55
            } else {
56
                /* @var $translation \Gettext\Translation */
57
                if ($translation->hasPlural() && $translation->hasPluralTranslations(true)) {
58
                    $originalString .= "\x00".$translation->getPlural();
59
                    $translationString = $translation->getTranslation();
60
                    $translationString .= "\x00".implode("\x00", $translation->getPluralTranslations($pluralSize));
61
                } else {
62
                    $translationString = $translation->getTranslation();
63
                }
64
            }
65
66
            $originalsIndex[] = [
67
                'relativeOffset' => strlen($originalsTable),
68
                'length' => strlen($originalString)
69
            ];
70
            $originalsTable .= $originalString."\x00";
71
            $translationsIndex[] = [
72
                'relativeOffset' => strlen($translationsTable),
73
                'length' => strlen($translationString)
74
            ];
75
            $translationsTable .= $translationString."\x00";
76
        }
77
78
        // Offset of table with the original strings index: right after the header (which is 7 words)
79
        $originalsIndexOffset = 7 * 4;
80
81
        // Size of table with the original strings index
82
        $originalsIndexSize = $numEntries * (4 + 4);
83
84
        // Offset of table with the translation strings index: right after the original strings index table
85
        $translationsIndexOffset = $originalsIndexOffset + $originalsIndexSize;
86
87
        // Size of table with the translation strings index
88
        $translationsIndexSize = $numEntries * (4 + 4);
89
90
        // Hashing table starts after the header and after the index table
91
        $originalsStringsOffset = $translationsIndexOffset + $translationsIndexSize;
92
93
        // Translations start after the keys
94
        $translationsStringsOffset = $originalsStringsOffset + strlen($originalsTable);
95
96
        // Let's generate the .mo file binary data
97
        $mo = '';
98
99
        // Magic number
100
        $mo .= pack('L', 0x950412de);
101
102
        // File format revision
103
        $mo .= pack('L', 0);
104
105
        // Number of strings
106
        $mo .= pack('L', $numEntries);
107
108
        // Offset of table with original strings
109
        $mo .= pack('L', $originalsIndexOffset);
110
111
        // Offset of table with translation strings
112
        $mo .= pack('L', $translationsIndexOffset);
113
114
        // Size of hashing table: we don't use it.
115
        $mo .= pack('L', 0);
116
117
        // Offset of hashing table: it would start right after the translations index table
118
        $mo .= pack('L', $translationsIndexOffset + $translationsIndexSize);
119
120
        // Write the lengths & offsets of the original strings
121 View Code Duplication
        foreach ($originalsIndex as $info) {
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...
122
            $mo .= pack('L', $info['length']);
123
            $mo .= pack('L', $originalsStringsOffset + $info['relativeOffset']);
124
        }
125
126
        // Write the lengths & offsets of the translated strings
127 View Code Duplication
        foreach ($translationsIndex as $info) {
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...
128
            $mo .= pack('L', $info['length']);
129
            $mo .= pack('L', $translationsStringsOffset + $info['relativeOffset']);
130
        }
131
132
        // Write original strings
133
        $mo .= $originalsTable;
134
135
        // Write translation strings
136
        $mo .= $translationsTable;
137
138
        return $mo;
139
    }
140
}
141