Skip to content

Commit

Permalink
Merge pull request #13038 from Ferdi265/fix-rvz-clang-ub
Browse files Browse the repository at this point in the history
RVZ: Fix undefined behaviour when copying 0 bytes to a null pointer
  • Loading branch information
Tilka committed Aug 30, 2024
2 parents 39e266c + 6245dcd commit 8b7268d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Source/Core/DiscIO/WIABlob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,14 @@ bool WIARVZFileReader<RVZ>::Chunk::Decompress()
const size_t bytes_to_move = m_out.bytes_written - m_out_bytes_used_for_exceptions;

DecompressionBuffer in{std::vector<u8>(bytes_to_move), bytes_to_move};
std::memcpy(in.data.data(), m_out.data.data() + m_out_bytes_used_for_exceptions, bytes_to_move);

// Copying to a null pointer is undefined behaviour, so only copy when we
// actually have data to copy.
if (bytes_to_move > 0)
{
std::memcpy(in.data.data(), m_out.data.data() + m_out_bytes_used_for_exceptions,
bytes_to_move);
}

m_out.bytes_written = m_out_bytes_used_for_exceptions;

Expand Down

0 comments on commit 8b7268d

Please sign in to comment.