mirror of https://github.com/WerWolv/ImHex.git
fix: Handle errors in Tar::readVector() (#1059)
This commit is contained in:
parent
5680b90549
commit
980e4cad06
|
@ -42,6 +42,7 @@ namespace hex {
|
|||
|
||||
private:
|
||||
mtar_t m_ctx = { };
|
||||
std::fs::path m_path;
|
||||
|
||||
bool m_valid = false;
|
||||
};
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
Loading…
Reference in New Issue