Skip to content

Commit fdd85c7

Browse files
authored
Merge pull request #107901 from akien-mga/3.6-cherrypicks
[3.6] Cherry-picks for the 3.6 branch (future 3.6.1) - 3rd batch
2 parents ac8b19e + 7e369e1 commit fdd85c7

9 files changed

Lines changed: 98 additions & 22 deletions

File tree

core/translation.cpp

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -359,32 +359,46 @@ String TranslationServer::standardize_locale(const String &p_locale) const {
359359
}
360360

361361
int TranslationServer::compare_locales(const String &p_locale_a, const String &p_locale_b) const {
362+
if (p_locale_a == p_locale_b) {
363+
// Exact match.
364+
return 10;
365+
}
366+
367+
const String cache_key = p_locale_a + "|" + p_locale_b;
368+
const int *cached_result = locale_compare_cache.getptr(cache_key);
369+
if (cached_result) {
370+
return *cached_result;
371+
}
372+
362373
String locale_a = standardize_locale(p_locale_a);
363374
String locale_b = standardize_locale(p_locale_b);
364375

365376
if (locale_a == locale_b) {
366377
// Exact match.
378+
locale_compare_cache.set(cache_key, 10);
367379
return 10;
368380
}
369381

370382
Vector<String> locale_a_elements = locale_a.split("_");
371383
Vector<String> locale_b_elements = locale_b.split("_");
372-
if (locale_a_elements[0] == locale_b_elements[0]) {
373-
// Matching language, both locales have extra parts.
374-
// Return number of matching elements.
375-
int matching_elements = 1;
376-
for (int i = 1; i < locale_a_elements.size(); i++) {
377-
for (int j = 1; j < locale_b_elements.size(); j++) {
378-
if (locale_a_elements[i] == locale_b_elements[j]) {
379-
matching_elements++;
380-
}
381-
}
382-
}
383-
return matching_elements;
384-
} else {
384+
if (locale_a_elements[0] != locale_b_elements[0]) {
385385
// No match.
386+
locale_compare_cache.set(cache_key, 0);
386387
return 0;
387388
}
389+
390+
// Matching language, both locales have extra parts.
391+
// Return number of matching elements.
392+
int matching_elements = 1;
393+
for (int i = 1; i < locale_a_elements.size(); i++) {
394+
for (int j = 1; j < locale_b_elements.size(); j++) {
395+
if (locale_a_elements[i] == locale_b_elements[j]) {
396+
matching_elements++;
397+
}
398+
}
399+
}
400+
locale_compare_cache.set(cache_key, matching_elements);
401+
return matching_elements;
388402
}
389403

390404
String TranslationServer::get_locale_name(const String &p_locale) const {

core/translation.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ class TranslationServer : public Object {
8787
Ref<Translation> tool_translation;
8888
Ref<Translation> doc_translation;
8989

90+
mutable HashMap<String, int> locale_compare_cache;
91+
9092
bool enabled;
9193

9294
static TranslationServer *singleton;

doc/classes/Button.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,6 @@
113113
<theme_item name="hover" data_type="style" type="StyleBox">
114114
[StyleBox] used when the [Button] is being hovered.
115115
</theme_item>
116-
<theme_item name="hover_pressed" data_type="style" type="StyleBox">
117-
[StyleBox] used when the [Button] is being hovered and pressed.
118-
</theme_item>
119116
<theme_item name="normal" data_type="style" type="StyleBox">
120117
Default [StyleBox] for the [Button].
121118
</theme_item>

drivers/wasapi/audio_driver_wasapi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737

3838
#include <functiondiscoverykeys.h>
3939

40-
#ifndef PKEY_Device_FriendlyName
40+
#ifndef PKEY_Device_FriendlyNameGodot
4141

4242
#undef DEFINE_PROPERTYKEY
4343
/* clang-format off */
4444
#define DEFINE_PROPERTYKEY(id, a, b, c, d, e, f, g, h, i, j, k, l) \
4545
const PROPERTYKEY id = { { a, b, c, { d, e, f, g, h, i, j, k, } }, l };
4646
/* clang-format on */
4747

48-
DEFINE_PROPERTYKEY(PKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);
48+
DEFINE_PROPERTYKEY(PKEY_Device_FriendlyNameGodot, 0xa45c254e, 0xdf1c, 0x4efd, 0x80, 0x20, 0x67, 0xd1, 0x46, 0xa8, 0x50, 0xe0, 14);
4949
#endif
5050

5151
const CLSID CLSID_MMDeviceEnumerator = __uuidof(MMDeviceEnumerator);
@@ -178,7 +178,7 @@ Error AudioDriverWASAPI::audio_device_init(AudioDeviceWASAPI *p_device, bool p_c
178178
PROPVARIANT propvar;
179179
PropVariantInit(&propvar);
180180

181-
hr = props->GetValue(PKEY_Device_FriendlyName, &propvar);
181+
hr = props->GetValue(PKEY_Device_FriendlyNameGodot, &propvar);
182182
ERR_BREAK(hr != S_OK);
183183

184184
if (p_device->device_name == String(propvar.pwszVal)) {
@@ -449,7 +449,7 @@ Array AudioDriverWASAPI::audio_device_get_list(bool p_capture) {
449449
PROPVARIANT propvar;
450450
PropVariantInit(&propvar);
451451

452-
hr = props->GetValue(PKEY_Device_FriendlyName, &propvar);
452+
hr = props->GetValue(PKEY_Device_FriendlyNameGodot, &propvar);
453453
ERR_BREAK(hr != S_OK);
454454

455455
list.push_back(String(propvar.pwszVal));

editor/import/resource_importer_wav.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,15 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
111111
}
112112

113113
/* GET FILESIZE */
114-
file->get_32(); // filesize
114+
115+
// The file size in header is 8 bytes less than the actual size.
116+
// See https://docs.fileformat.com/audio/wav/
117+
const int FILE_SIZE_HEADER_OFFSET = 8;
118+
uint32_t file_size_header = file->get_32() + FILE_SIZE_HEADER_OFFSET;
119+
uint64_t file_size = file->get_len();
120+
if (file_size != file_size_header) {
121+
WARN_PRINT(vformat("File size %d is %s than the expected size %d.", file_size, file_size > file_size_header ? "larger" : "smaller", file_size_header));
122+
}
115123

116124
/* CHECK WAVE */
117125

@@ -208,7 +216,12 @@ Error ResourceImporterWAV::import(const String &p_source_file, const String &p_s
208216
break;
209217
}
210218

219+
uint64_t remaining_bytes = file_size - file_pos;
211220
frames = chunksize;
221+
if (remaining_bytes < chunksize) {
222+
WARN_PRINT("Data chunk size is smaller than expected. Proceeding with actual data size.");
223+
frames = remaining_bytes;
224+
}
212225

213226
if (format_channels == 0) {
214227
file->close();

scene/resources/default_theme/default_theme.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
230230
theme->set_stylebox("normal", "Button", sb_button_normal);
231231
theme->set_stylebox("pressed", "Button", sb_button_pressed);
232232
theme->set_stylebox("hover", "Button", sb_button_hover);
233-
theme->set_stylebox("hover_pressed", "Button", sb_button_hover);
234233
theme->set_stylebox("disabled", "Button", sb_button_disabled);
235234
theme->set_stylebox("focus", "Button", sb_button_focus);
236235

thirdparty/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ Files extracted from upstream source:
220220
Important: Some files have Godot-made changes.
221221
They are marked with `// -- GODOT start --` and `// -- GODOT end --`
222222
comments.
223+
A patch is included to fix CVE-2019-2126 in libwebm.
223224

224225

225226
## libtheora

thirdparty/libsimplewebm/libwebm/mkvparser/mkvparser.cc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4232,6 +4232,7 @@ long ContentEncoding::ParseContentEncodingEntry(long long start, long long size,
42324232
new (std::nothrow) ContentEncryption*[encryption_count];
42334233
if (!encryption_entries_) {
42344234
delete[] compression_entries_;
4235+
compression_entries_ = NULL;
42354236
return -1;
42364237
}
42374238
encryption_entries_end_ = encryption_entries_;
@@ -4263,6 +4264,7 @@ long ContentEncoding::ParseContentEncodingEntry(long long start, long long size,
42634264
delete compression;
42644265
return status;
42654266
}
4267+
assert(compression_count > 0);
42664268
*compression_entries_end_++ = compression;
42674269
} else if (id == libwebm::kMkvContentEncryption) {
42684270
ContentEncryption* const encryption =
@@ -4275,6 +4277,7 @@ long ContentEncoding::ParseContentEncodingEntry(long long start, long long size,
42754277
delete encryption;
42764278
return status;
42774279
}
4280+
assert(encryption_count > 0);
42784281
*encryption_entries_end_++ = encryption;
42794282
}
42804283

@@ -4327,6 +4330,12 @@ long ContentEncoding::ParseCompressionEntry(long long start, long long size,
43274330
return status;
43284331
}
43294332

4333+
// There should be only one settings element per content compression.
4334+
if (compression->settings != NULL) {
4335+
delete[] buf;
4336+
return E_FILE_FORMAT_INVALID;
4337+
}
4338+
43304339
compression->settings = buf;
43314340
compression->settings_len = buflen;
43324341
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
diff --git a/thirdparty/libsimplewebm/libwebm/mkvparser/mkvparser.cc b/thirdparty/libsimplewebm/libwebm/mkvparser/mkvparser.cc
2+
index e7b76f7da1..820ca28bf1 100644
3+
--- a/thirdparty/libsimplewebm/libwebm/mkvparser/mkvparser.cc
4+
+++ b/thirdparty/libsimplewebm/libwebm/mkvparser/mkvparser.cc
5+
@@ -4232,6 +4232,7 @@ long ContentEncoding::ParseContentEncodingEntry(long long start, long long size,
6+
new (std::nothrow) ContentEncryption*[encryption_count];
7+
if (!encryption_entries_) {
8+
delete[] compression_entries_;
9+
+ compression_entries_ = NULL;
10+
return -1;
11+
}
12+
encryption_entries_end_ = encryption_entries_;
13+
@@ -4263,6 +4264,7 @@ long ContentEncoding::ParseContentEncodingEntry(long long start, long long size,
14+
delete compression;
15+
return status;
16+
}
17+
+ assert(compression_count > 0);
18+
*compression_entries_end_++ = compression;
19+
} else if (id == libwebm::kMkvContentEncryption) {
20+
ContentEncryption* const encryption =
21+
@@ -4275,6 +4277,7 @@ long ContentEncoding::ParseContentEncodingEntry(long long start, long long size,
22+
delete encryption;
23+
return status;
24+
}
25+
+ assert(encryption_count > 0);
26+
*encryption_entries_end_++ = encryption;
27+
}
28+
29+
@@ -4327,6 +4330,12 @@ long ContentEncoding::ParseCompressionEntry(long long start, long long size,
30+
return status;
31+
}
32+
33+
+ // There should be only one settings element per content compression.
34+
+ if (compression->settings != NULL) {
35+
+ delete[] buf;
36+
+ return E_FILE_FORMAT_INVALID;
37+
+ }
38+
+
39+
compression->settings = buf;
40+
compression->settings_len = buflen;
41+
}

0 commit comments

Comments
 (0)