ImHex icon indicating copy to clipboard operation
ImHex copied to clipboard

[Bug] Undesirable behaviour when opened files are modified externally.

Open J0w03L opened this issue 2 years ago • 0 comments

Operating System

Linux

What's the issue you encountered?

Whilst using ImHex, I've noticed that it doesn't handle opened files being modified externally too well. A few bugs that I've noticed which demonstrate this are below:

  1. ImHex will crash if opened files are modified externally in a particular way, due to a bus error.
  2. If a file that is opened in ImHex is deleted, and the user tries to save the file in ImHex, it will look as though the file was saved but the changes are never actually written.
  3. If an opened file is written to externally, ImHex will automatically update the file's displayed contents as intended, but will not display any bytes beyond the size of the original file, behaving as though the file is the same size still.

How can the issue be reproduced?

Bug 1:

  1. Create a file called test.txt: echo 1 > test.txt
  2. Open test.txt in ImHex
  3. In a terminal, modify the file using cat: cat test.txt > test.txt (you can cat any file)
  4. ImHex crashes with Bus error (core dumped)
  5. Open test.txt in ImHex again
  6. In a terminal, modify the file using echo: echo $(cat test.txt) > test.txt
  7. Observe that modifying the file with echo did not crash ImHex

Bug 2:

  1. Create a file called test.txt: echo 1 > test.txt
  2. Open test.txt in ImHex
  3. In a terminal, delete the file: rm test.txt
  4. In ImHex, change a random byte so that ImHex gives you the option to save your changes
  5. Save your changes using Ctrl+S or by clicking on the save icon
  6. Observe that the save icon turns grey, as if your changes were written successfully
  7. In a terminal, print the file's contents: cat test.txt
  8. Observe that the command failed as the file does not exist
  9. Close the file in ImHex and observe that ImHex warns you that the file has unsaved changes

Bug 3:

  1. Create a file called test.txt: echo 12345 > test.txt
  2. Open test.txt in ImHex; ImHex displays 12345 along with a new-line character
  3. In a terminal, modify the file so that it is larger than it was originally: echo 1234567890 > test.txt
  4. Observe that ImHex has updated the displayed file's contents to show 123456, with the 6 taking the place of the old new-line character
  5. In a terminal, modify the file so that it is smaller than it was originally: echo 1 > test.txt
  6. Observe that ImHex has updated the displayed file's contents to show the character 1, a new-line character, and 4 null bytes

ImHex Version

1.27.1 f435191

ImHex Build Type

  • [ ] Nightly or built from sources

Installation type

AUR on both imhex-git and imhex-bin

Additional context?

No response

J0w03L avatar Feb 23 '23 19:02 J0w03L