fix: Crash when reading from modified bytes

This commit is contained in:
WerWolv
2023-05-14 22:46:19 +02:00
parent 2b765617ce
commit c50d52d0a6

View File

@@ -40,7 +40,7 @@ namespace hex::plugin::builtin {
if (overlays) [[likely]] {
for (const auto&[patchOffset, patchData] : getPatches()) {
if (patchOffset >= offset && patchOffset <= (offset + size))
if (patchOffset >= offset && patchOffset < (offset + size))
reinterpret_cast<u8 *>(buffer)[patchOffset - offset] = patchData;
}
@@ -59,13 +59,6 @@ namespace hex::plugin::builtin {
if (offset > (this->getActualSize() - size) || buffer == nullptr || size == 0)
return;
/*auto currSize = std::fs::file_size(this->m_path);
if (this->m_fileSize != currSize) [[unlikely]] {
this->m_fileSize = currSize;
this->m_file.unmap();
this->m_file.map();
}*/
std::memcpy(buffer, this->m_file.getMapping() + offset, size);
}
@@ -73,13 +66,6 @@ namespace hex::plugin::builtin {
if ((offset + size) > this->getActualSize() || buffer == nullptr || size == 0)
return;
auto currSize = std::fs::file_size(this->m_path);
if (this->m_fileSize != currSize) [[unlikely]] {
this->m_fileSize = currSize;
this->m_file.unmap();
this->m_file.map();
}
std::memcpy(this->m_file.getMapping() + offset, buffer, size);
}