jovibor / HexCtrl

Fully-featured Hex Control written in C++/MFC.
Other
167 stars 58 forks source link

Exception in CHexCtrl::SnapshotUndo() #54

Closed datasynergyuk closed 3 years ago

datasynergyuk commented 3 years ago

I found found a strange exception in SnapshotUndo(). It is easy to reproduce but I cannot re-create it with the stock sample application with either in-memory data or memory mapped file. This leads me to think it maybe related to DATA_VIRTUAL mode.

To reproduce:

  1. Open a 4MB file e.g. 4,194,304 bytes with DATA_VIRTUAL
  2. Right click
  3. Select Modify / Fill with Data / Random

The problem occurs towards the end of SnapshotUndo() in the call to std::copy_n() when the data is copied into the newly allocated undo buffer.

datasynergyuk commented 3 years ago

I did some more digging on this problem. The cause of the issue is related to DATA_VIRTUAL. The problem occurs because, if the selection is large, GetData() can return a smaller amount of data than anticipated due to the current cache size. However, the loop at the end of SnapshotUndo() fails to handle this situation. I would suggest it possibly needs another inner loop adding for the DATA_VIRTUAL case to handle the copy in cache sized chunks.

There are a couple of other similar calls to std::copy_n() e.g. ModifyData(). Could these have the same problem?

jovibor commented 3 years ago

I'm aware of this issue. The fix will be deployed when testing is complete.

datasynergyuk commented 3 years ago

Thank you. Confirmed fixed.