fix: crash on empty dialog extensions array on Windows (#48659)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2025-10-27 09:16:59 +01:00 committed by GitHub
commit 45aa5396a9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -44,8 +44,7 @@ void ConvertFilters(const Filters& filters,
std::vector<std::wstring>* buffer, std::vector<std::wstring>* buffer,
std::vector<COMDLG_FILTERSPEC>* filterspec) { std::vector<COMDLG_FILTERSPEC>* filterspec) {
if (filters.empty()) { if (filters.empty()) {
COMDLG_FILTERSPEC spec = {L"All Files (*.*)", L"*.*"}; filterspec->push_back({L"All Files (*.*)", L"*.*"});
filterspec->push_back(spec);
return; return;
} }
@ -55,11 +54,16 @@ void ConvertFilters(const Filters& filters,
buffer->push_back(base::UTF8ToWide(filter.first)); buffer->push_back(base::UTF8ToWide(filter.first));
spec.pszName = buffer->back().c_str(); spec.pszName = buffer->back().c_str();
std::vector<std::string> extensions(filter.second); if (filter.second.empty()) {
for (std::string& extension : extensions) buffer->push_back(L"*.*");
extension.insert(0, "*."); spec.pszSpec = buffer->back().c_str();
buffer->push_back(base::UTF8ToWide(base::JoinString(extensions, ";"))); } else {
spec.pszSpec = buffer->back().c_str(); std::vector<std::string> extensions(filter.second);
for (std::string& extension : extensions)
extension.insert(0, "*.");
buffer->push_back(base::UTF8ToWide(base::JoinString(extensions, ";")));
spec.pszSpec = buffer->back().c_str();
}
filterspec->push_back(spec); filterspec->push_back(spec);
} }