1
0
mirror of synced 2025-01-30 19:43:43 +01:00

fix: Don't pass nullptrs to libmagic

#1485
This commit is contained in:
WerWolv 2024-02-01 22:35:24 +01:00
parent 7546655695
commit 959a404e1c

View File

@ -96,6 +96,8 @@ namespace hex::magic {
}
std::string getDescription(const std::vector<u8> &data, bool firstEntryOnly) {
if (data.empty()) return "";
auto magicFiles = getMagicFiles();
if (magicFiles.has_value()) {
@ -119,6 +121,8 @@ namespace hex::magic {
}
std::string getMIMEType(const std::vector<u8> &data, bool firstEntryOnly) {
if (data.empty()) return "";
auto magicFiles = getMagicFiles();
if (magicFiles.has_value()) {
@ -134,6 +138,13 @@ namespace hex::magic {
return "";
}
std::string getMIMEType(prv::Provider *provider, size_t size, bool firstEntryOnly) {
std::vector<u8> buffer(std::min<u64>(provider->getSize(), size), 0x00);
provider->read(provider->getBaseAddress(), buffer.data(), buffer.size());
return getMIMEType(buffer, firstEntryOnly);
}
std::string getExtensions(prv::Provider *provider, size_t size, bool firstEntryOnly) {
std::vector<u8> buffer(std::min<u64>(provider->getSize(), size), 0x00);
provider->read(provider->getBaseAddress(), buffer.data(), buffer.size());
@ -142,6 +153,8 @@ namespace hex::magic {
}
std::string getExtensions(const std::vector<u8> &data, bool firstEntryOnly) {
if (data.empty()) return "";
auto magicFiles = getMagicFiles();
if (magicFiles.has_value()) {
@ -165,6 +178,8 @@ namespace hex::magic {
}
std::string getAppleCreatorType(const std::vector<u8> &data, bool firstEntryOnly) {
if (data.empty()) return "";
auto magicFiles = getMagicFiles();
if (magicFiles.has_value()) {
@ -180,13 +195,6 @@ namespace hex::magic {
return {};
}
std::string getMIMEType(prv::Provider *provider, size_t size, bool firstEntryOnly) {
std::vector<u8> buffer(std::min<u64>(provider->getSize(), size), 0x00);
provider->read(provider->getBaseAddress(), buffer.data(), buffer.size());
return getMIMEType(buffer, firstEntryOnly);
}
bool isValidMIMEType(const std::string &mimeType) {
// MIME types always contain a slash
if (!mimeType.contains("/"))