fix: Handle errors in Tar::readVector() (#1059)

This commit is contained in:
iTrooz 2023-05-05 21:57:37 +02:00 committed by GitHub
parent 5680b90549
commit 980e4cad06
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -42,6 +42,7 @@ namespace hex {
private:
mtar_t m_ctx = { };
std::fs::path m_path;
bool m_valid = false;
};

View File

@ -1,6 +1,7 @@
#include <hex/helpers/tar.hpp>
#include <hex/helpers/literals.hpp>
#include <hex/helpers/fs.hpp>
#include <hex/helpers/logger.hpp>
#include <wolv/io/file.hpp>
@ -27,6 +28,7 @@ namespace hex {
else
error = MTAR_EFAILURE;
this->m_path = path;
this->m_valid = (error == MTAR_ESUCCESS);
}
@ -36,6 +38,7 @@ namespace hex {
Tar::Tar(hex::Tar &&other) noexcept {
this->m_ctx = other.m_ctx;
this->m_path = other.m_path;
this->m_valid = other.m_valid;
other.m_ctx = { };
@ -46,6 +49,8 @@ namespace hex {
this->m_ctx = other.m_ctx;
other.m_ctx = { };
this->m_path = other.m_path;
this->m_valid = other.m_valid;
other.m_valid = false;
@ -91,8 +96,13 @@ namespace hex {
#if defined(OS_WINDOWS)
std::replace(fixedPath.begin(), fixedPath.end(), '\\', '/');
#endif
mtar_find(&this->m_ctx, fixedPath.c_str(), &header);
int ret = mtar_find(&this->m_ctx, fixedPath.c_str(), &header);
if(ret != MTAR_ESUCCESS){
log::debug("Failed to read vector from path {} in tarred file {}: {}",
path.string(), this->m_path.string(), mtar_strerror(ret));
return {};
}
std::vector<u8> result(header.size, 0x00);
mtar_read_data(&this->m_ctx, result.data(), result.size());