Skip to content

Commit

Permalink
fix crash on invalid chars in pack filename
Browse files Browse the repository at this point in the history
  • Loading branch information
Cvolton committed Jun 17, 2024
1 parent fb6f28c commit f5d4a41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/Pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,14 @@ Pack::~Pack() {
}

Result<std::shared_ptr<Pack>> Pack::from(std::filesystem::path const& dir) {
#ifdef GEODE_IS_WINDOWS
try {
auto test = dir.filename().string();
} catch(const std::exception& e) {
return Err("Invalid path");
}
#endif

if (!std::filesystem::exists(dir)) {
return Err("Path does not exist");
}
Expand Down
7 changes: 6 additions & 1 deletion src/PackManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ size_t PackManager::loadPacks() {
for (auto& dir : std::filesystem::directory_iterator(packDir)) {
auto packRes = Pack::from(dir);
if (!packRes) {
log::warn("Unable to load pack {}: {}", dir, packRes.unwrapErr());
// calling dir can throw an exception on windows if it contains invalid characters
#ifdef GEODE_IS_WINDOWS
log::warn("Unable to load pack {}: {}", string::wideToUtf8(dir.path().wstring()), packRes.unwrapErr());
#else
log::warn("Unable to load pack {}: {}", dir, packRes.unwrapErr());
#endif
} else {
found.push_back(packRes.unwrap());
loaded++;
Expand Down

0 comments on commit f5d4a41

Please sign in to comment.