Skip to content

Commit

Permalink
[Pseudolocalization] Prevent out of bounds reads.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Jan 5, 2024
1 parent 179dfdc commit e7bdb60
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions core/string/translation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,7 @@ StringName TranslationServer::tool_pseudolocalize(const StringName &p_message) c

String TranslationServer::get_override_string(String &p_message) const {
String res;
for (int i = 0; i < p_message.size(); i++) {
for (int i = 0; i < p_message.length(); i++) {
if (pseudolocalization_skip_placeholders_enabled && is_placeholder(p_message, i)) {
res += p_message[i];
res += p_message[i + 1];
Expand All @@ -895,7 +895,7 @@ String TranslationServer::get_override_string(String &p_message) const {

String TranslationServer::double_vowels(String &p_message) const {
String res;
for (int i = 0; i < p_message.size(); i++) {
for (int i = 0; i < p_message.length(); i++) {
if (pseudolocalization_skip_placeholders_enabled && is_placeholder(p_message, i)) {
res += p_message[i];
res += p_message[i + 1];
Expand All @@ -913,7 +913,7 @@ String TranslationServer::double_vowels(String &p_message) const {

String TranslationServer::replace_with_accented_string(String &p_message) const {
String res;
for (int i = 0; i < p_message.size(); i++) {
for (int i = 0; i < p_message.length(); i++) {
if (pseudolocalization_skip_placeholders_enabled && is_placeholder(p_message, i)) {
res += p_message[i];
res += p_message[i + 1];
Expand All @@ -936,7 +936,7 @@ String TranslationServer::wrap_with_fakebidi_characters(String &p_message) const
char32_t fakebidisuffix = U'\u202c';
res += fakebidiprefix;
// The fake bidi unicode gets popped at every newline so pushing it back at every newline.
for (int i = 0; i < p_message.size(); i++) {
for (int i = 0; i < p_message.length(); i++) {
if (p_message[i] == '\n') {
res += fakebidisuffix;
res += p_message[i];
Expand Down Expand Up @@ -978,7 +978,7 @@ const char32_t *TranslationServer::get_accented_version(char32_t p_character) co
}

bool TranslationServer::is_placeholder(String &p_message, int p_index) const {
return p_index < p_message.size() - 1 && p_message[p_index] == '%' &&
return p_index < p_message.length() - 1 && p_message[p_index] == '%' &&
(p_message[p_index + 1] == 's' || p_message[p_index + 1] == 'c' || p_message[p_index + 1] == 'd' ||
p_message[p_index + 1] == 'o' || p_message[p_index + 1] == 'x' || p_message[p_index + 1] == 'X' || p_message[p_index + 1] == 'f');
}
Expand Down

0 comments on commit e7bdb60

Please sign in to comment.