mirror of
https://github.com/d0k3/GodMode9.git
synced 2025-06-26 21:52:48 +00:00
Fix crashes when opening extensionless files. (#503)
* Set extension to an empty string when there's none
This commit is contained in:
parent
3cbbd53850
commit
8f588fa8bc
@ -32,7 +32,11 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
if (!fname) return 0;
|
if (!fname) return 0;
|
||||||
if (strncmp(fname, "._", 2) == 0) return 0;
|
if (strncmp(fname, "._", 2) == 0) return 0;
|
||||||
|
|
||||||
if (ext) ext++;
|
if (ext) {
|
||||||
|
ext++;
|
||||||
|
} else {
|
||||||
|
ext = "";
|
||||||
|
}
|
||||||
if (FileGetData(path, header, 0x200, 0) < min(0x200, fsize)) return 0;
|
if (FileGetData(path, header, 0x200, 0) < min(0x200, fsize)) return 0;
|
||||||
if (!fsize) return 0;
|
if (!fsize) return 0;
|
||||||
|
|
||||||
@ -128,7 +132,7 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
} else if ((strncasecmp(ext, "png", 4) == 0) &&
|
} else if ((strncasecmp(ext, "png", 4) == 0) &&
|
||||||
(fsize > sizeof(png_magic)) && (memcmp(data, png_magic, sizeof(png_magic)) == 0)) {
|
(fsize > sizeof(png_magic)) && (memcmp(data, png_magic, sizeof(png_magic)) == 0)) {
|
||||||
return GFX_PNG;
|
return GFX_PNG;
|
||||||
} else if (ext && ((strncasecmp(ext, "cdn", 4) == 0) || (strncasecmp(ext, "nus", 4) == 0))) {
|
} else if ((strncasecmp(ext, "cdn", 4) == 0) || (strncasecmp(ext, "nus", 4) == 0)) {
|
||||||
char path_cetk[256];
|
char path_cetk[256];
|
||||||
char* ext_cetk = path_cetk + (ext - path);
|
char* ext_cetk = path_cetk + (ext - path);
|
||||||
strncpy(path_cetk, path, 256);
|
strncpy(path_cetk, path, 256);
|
||||||
@ -146,7 +150,7 @@ u64 IdentifyFileType(const char* path) {
|
|||||||
return BIN_LEGKEY; // legacy key file
|
return BIN_LEGKEY; // legacy key file
|
||||||
} else if (ValidateText((char*) data, (fsize > 0x200) ? 0x200 : fsize)) {
|
} else if (ValidateText((char*) data, (fsize > 0x200) ? 0x200 : fsize)) {
|
||||||
u64 type = 0;
|
u64 type = 0;
|
||||||
if ((fsize <= SCRIPT_MAX_SIZE) && ext && (strncasecmp(ext, SCRIPT_EXT, strnlen(SCRIPT_EXT, 16) + 1) == 0))
|
if ((fsize <= SCRIPT_MAX_SIZE) && (strncasecmp(ext, SCRIPT_EXT, strnlen(SCRIPT_EXT, 16) + 1) == 0))
|
||||||
type |= TXT_SCRIPT; // should be a script (which is also generic text)
|
type |= TXT_SCRIPT; // should be a script (which is also generic text)
|
||||||
if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC;
|
if (fsize < STD_BUFFER_SIZE) type |= TXT_GENERIC;
|
||||||
return type;
|
return type;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user