mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-09-03 11:15:20 +02:00
A crafted zip with a parent-directory ("..") entry name could escape the
destination directory during extraction, writing arbitrary files on the
host (e.g. into startup/autostart folders). ExtractZipContents built the
output path by concatenating the raw zip entry name onto the destination
with no traversal check.
Changes:
- Add HasParentDirComponent() utility in Core/Util/PathUtil and use it in
GameManager::ExtractZipContents to reject entries with a ".." component.
Guard both the directory-creation and file-writing passes.
- Expose ExtractZipContents as public for testing.
- Add unittest/TestZipSlip which crafts a zip with a "../evil.txt" entry
and verifies it is not written outside the destination directory.
44 lines
1.2 KiB
C++
44 lines
1.2 KiB
C++
#pragma once
|
|
|
|
#include <string>
|
|
#include <string_view>
|
|
|
|
#include "Common/File/Path.h"
|
|
|
|
// Use these in conjunction with GetSysDirectory.
|
|
enum PSPDirectories {
|
|
DIRECTORY_PSP,
|
|
DIRECTORY_CHEATS,
|
|
DIRECTORY_SCREENSHOT,
|
|
DIRECTORY_SYSTEM,
|
|
DIRECTORY_GAME,
|
|
DIRECTORY_SAVEDATA,
|
|
DIRECTORY_PAUTH,
|
|
DIRECTORY_DUMP,
|
|
DIRECTORY_SAVESTATE,
|
|
DIRECTORY_CACHE,
|
|
DIRECTORY_TEXTURES,
|
|
DIRECTORY_PLUGINS,
|
|
DIRECTORY_APP_CACHE, // Use the OS app cache if available
|
|
DIRECTORY_VIDEO,
|
|
DIRECTORY_AUDIO,
|
|
DIRECTORY_MEMSTICK_ROOT,
|
|
DIRECTORY_EXDATA,
|
|
DIRECTORY_CUSTOM_SHADERS,
|
|
DIRECTORY_CUSTOM_THEMES,
|
|
COUNT,
|
|
};
|
|
|
|
// Returns true if the given path (e.g. a zip entry name) contains a parent
|
|
// directory ("..") component. Used to guard against path traversal when
|
|
// extracting or writing files to disk.
|
|
bool HasParentDirComponent(std::string_view path);
|
|
|
|
Path FindConfigFile(const Path &searchPath, std::string_view baseFilename, bool *exists);
|
|
Path GetSysDirectory(PSPDirectories directoryType);
|
|
bool CreateSysDirectories();
|
|
Path GetGameConfigFilePath(const Path &searchPath, std::string_view gameId, bool *exists);
|
|
bool TryUpdateSavedPath(Path *path);
|
|
Path GetFailedBackendsDir();
|
|
std::string GetFriendlyPath(Path path, const Path &rootMatch = Path(), std::string_view rootDisplay = "ms:/");
|