3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-05-14 11:14:44 +00:00

Merge pull request #5110 from YosysHQ/emil/gzip-reject-directory

gzip: reject uncompressing directory
This commit is contained in:
KrystalDelusion 2025-05-10 09:36:13 +12:00 committed by GitHub
commit c4af97c1c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 36 additions and 25 deletions

View file

@ -102,6 +102,8 @@ gzip_istream::ibuf::~ibuf() {
// returns the original ifstream, rewound to the start. // returns the original ifstream, rewound to the start.
// Never returns nullptr or failed state istream* // Never returns nullptr or failed state istream*
std::istream* uncompressed(const std::string filename, std::ios_base::openmode mode) { std::istream* uncompressed(const std::string filename, std::ios_base::openmode mode) {
if (!check_file_exists(filename))
log_cmd_error("File `%s' not found or is a directory\n", filename.c_str());
std::ifstream* f = new std::ifstream(); std::ifstream* f = new std::ifstream();
f->open(filename, mode); f->open(filename, mode);
if (f->fail()) if (f->fail())

View file

@ -247,7 +247,7 @@ std::string make_temp_dir(std::string template_str)
#endif #endif
} }
bool check_directory_exists(const std::string& dirname) bool check_is_directory(const std::string& dirname)
{ {
#if defined(_WIN32) #if defined(_WIN32)
struct _stat info; struct _stat info;
@ -267,17 +267,26 @@ bool check_directory_exists(const std::string& dirname)
} }
#ifdef _WIN32 #ifdef _WIN32
bool check_file_exists(std::string filename, bool) bool check_accessible(const std::string& filename, bool)
{ {
return _access(filename.c_str(), 0) == 0; return _access(filename.c_str(), 0) == 0;
} }
#else #else
bool check_file_exists(std::string filename, bool is_exec) bool check_accessible(const std::string& filename, bool is_exec)
{ {
return access(filename.c_str(), is_exec ? X_OK : F_OK) == 0; return access(filename.c_str(), is_exec ? X_OK : F_OK) == 0;
} }
#endif #endif
bool check_file_exists(const std::string& filename, bool is_exec)
{
return check_accessible(filename, is_exec) && !check_is_directory(filename);
}
bool check_directory_exists(const std::string& filename, bool is_exec)
{
return check_accessible(filename, is_exec) && check_is_directory(filename);
}
bool is_absolute_path(std::string filename) bool is_absolute_path(std::string filename)
{ {
#ifdef _WIN32 #ifdef _WIN32

View file

@ -64,6 +64,23 @@ inline std::string stringf(const char *fmt, ...)
return string; return string;
} }
int readsome(std::istream &f, char *s, int n);
std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false);
std::vector<std::string> split_tokens(const std::string &text, const char *sep = " \t\r\n");
bool patmatch(const char *pattern, const char *string);
#if !defined(YOSYS_DISABLE_SPAWN)
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
#endif
std::string get_base_tmpdir();
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
bool check_file_exists(const std::string& filename, bool is_exec = false);
bool check_directory_exists(const std::string& dirname, bool is_exec = false);
bool is_absolute_path(std::string filename);
void remove_directory(std::string dirname);
bool create_directory(const std::string& dirname);
std::string escape_filename_spaces(const std::string& filename);
YOSYS_NAMESPACE_END YOSYS_NAMESPACE_END
#endif // YOSYS_IO_H #endif // YOSYS_IO_H

View file

@ -556,29 +556,29 @@ void init_share_dirname()
std::string proc_self_path = proc_self_dirname(); std::string proc_self_path = proc_self_dirname();
# if defined(_WIN32) && !defined(YOSYS_WIN32_UNIX_DIR) # if defined(_WIN32) && !defined(YOSYS_WIN32_UNIX_DIR)
std::string proc_share_path = proc_self_path + "share\\"; std::string proc_share_path = proc_self_path + "share\\";
if (check_file_exists(proc_share_path, true)) { if (check_directory_exists(proc_share_path, true)) {
yosys_share_dirname = proc_share_path; yosys_share_dirname = proc_share_path;
return; return;
} }
proc_share_path = proc_self_path + "..\\share\\"; proc_share_path = proc_self_path + "..\\share\\";
if (check_file_exists(proc_share_path, true)) { if (check_directory_exists(proc_share_path, true)) {
yosys_share_dirname = proc_share_path; yosys_share_dirname = proc_share_path;
return; return;
} }
# else # else
std::string proc_share_path = proc_self_path + "share/"; std::string proc_share_path = proc_self_path + "share/";
if (check_file_exists(proc_share_path, true)) { if (check_directory_exists(proc_share_path, true)) {
yosys_share_dirname = proc_share_path; yosys_share_dirname = proc_share_path;
return; return;
} }
proc_share_path = proc_self_path + "../share/" + proc_program_prefix()+ "yosys/"; proc_share_path = proc_self_path + "../share/" + proc_program_prefix()+ "yosys/";
if (check_file_exists(proc_share_path, true)) { if (check_directory_exists(proc_share_path, true)) {
yosys_share_dirname = proc_share_path; yosys_share_dirname = proc_share_path;
return; return;
} }
# ifdef YOSYS_DATDIR # ifdef YOSYS_DATDIR
proc_share_path = YOSYS_DATDIR "/"; proc_share_path = YOSYS_DATDIR "/";
if (check_file_exists(proc_share_path, true)) { if (check_directory_exists(proc_share_path, true)) {
yosys_share_dirname = proc_share_path; yosys_share_dirname = proc_share_path;
return; return;
} }

View file

@ -252,23 +252,6 @@ inline void memhasher() { if (memhasher_active) memhasher_do(); }
void yosys_banner(); void yosys_banner();
int ceil_log2(int x) YS_ATTRIBUTE(const); int ceil_log2(int x) YS_ATTRIBUTE(const);
int readsome(std::istream &f, char *s, int n);
std::string next_token(std::string &text, const char *sep = " \t\r\n", bool long_strings = false);
std::vector<std::string> split_tokens(const std::string &text, const char *sep = " \t\r\n");
bool patmatch(const char *pattern, const char *string);
#if !defined(YOSYS_DISABLE_SPAWN)
int run_command(const std::string &command, std::function<void(const std::string&)> process_line = std::function<void(const std::string&)>());
#endif
std::string get_base_tmpdir();
std::string make_temp_file(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
std::string make_temp_dir(std::string template_str = get_base_tmpdir() + "/yosys_XXXXXX");
bool check_file_exists(std::string filename, bool is_exec = false);
bool check_directory_exists(const std::string& dirname);
bool is_absolute_path(std::string filename);
void remove_directory(std::string dirname);
bool create_directory(const std::string& dirname);
std::string escape_filename_spaces(const std::string& filename);
template<typename T> int GetSize(const T &obj) { return obj.size(); } template<typename T> int GetSize(const T &obj) { return obj.size(); }
inline int GetSize(RTLIL::Wire *wire); inline int GetSize(RTLIL::Wire *wire);