ImHex icon indicating copy to clipboard operation
ImHex copied to clipboard

[Bug] Crash when removing all file content and fail to open empty file

Open Vizepi opened this issue 1 year ago • 3 comments

Operating System

Windows

What's the issue you encountered?

Repro rate: 100% I face two probably related issues:

  • I cannot open an empty file
  • If I remove the last byte of a file, the program crashes

I think empty content is mishandled somewhere.

How can the issue be reproduced?

For empty file:

  • Create an empty file on the disk (Windows Explorer -> Left Click -> New -> Text File
  • Open the program and drag the text file in it
  • Observe error message on file not existing For crash:
  • Using notepad, add a single space in a text file
  • Open the program and drag the text file in it
  • Left click on the first byte -> Remove -> Set
  • Observe the crash

ImHex Version

1.32.2

ImHex Build Type

  • [ ] Nightly or built from sources

Installation type

Portable

Additional context?

No response

Vizepi avatar Jan 11 '24 21:01 Vizepi

Hey This should actually be fixed in the nightly now. Up until maybe a week ago, we used mmap / MapViewOfFile to map files into memory. Resizing files to 0 bytes or opening 0 sized files was simply not possible then because you can't map an empty file into memory.

Starting with commit c89d19cd27d8917aadf430165c1c9cd410b0c5e3 I switched over to atomic file IO now which should resolve this issue entirely at the expense of being slightly slower. Please try downloading the latest nightly from https://imhex.download/#nightly and check if it still happens there for you

WerWolv avatar Jan 11 '24 21:01 WerWolv

I would like to note that it wasn't like this just a few months ago - ImHex used to work fine with the zero-sized files and resizes.

I actually thought the new atomic IO was supposed to be a necessary addition required because WerWolv found some data races in ImHex... Guess I was wrong and it's just fixing something that broke while making the whole thing slightly slower...

Nemoumbra avatar Jan 12 '24 00:01 Nemoumbra