Subject: Re: bug#48324: 27.2; hexl-mode duplicates the UTF-8 BOM

From: Eli Zaretskii <[email-masked]>
Date: Mon, 10 May 2021 17:17:49 +0300

> Date: Sun, 9 May 2021 23:38:18 +0200
> From:  "R. Diez" via "Bug reports for GNU Emacs,
>  the Swiss army knife of text editors" <[email-masked]>
> 
> I think that hexl-mode has problems with the UTF-8 BOM byte sequence at the beginning of a text file. The steps to reproduce this issue are:
> 
> Create a text file with a single line with 3 characters: 123
> 
> Do a (set-buffer-file-coding-system 'utf-8-with-signature-dos) and save the file.
> 
> The file should now have the following contents (8 bytes):
> 
> ef bb bf 31 32 33 0d 0a
> 
> That is the UTF-8 BOM (ef bb bf), the ASCII digits 1, 2 and 3, and end-of-line sequence (CR LF).
> 
> Now change to hexl-mode, place the cursor at the '1' character (31 in hex), call hexl-insert-hex-char, and enter 00 in order to replace the '1' with a 
> binary zero (NUL character).
> 
> The result is puzzling. Instead of replacing the '1' (31) with NUL (00), the UTF-8 BOM is duplicated, the characters '1' and '2' and '3' have been 
> overwritten with the new copy of BOM, character CR has been replaced with NUL, and character LF is intact:
> 
> ef bb bf ef bb bf 00 0a
> 
> If you save, close and reload the file, it gains one byte, but that is probably not important, just a consequence of having lost the CR character:
> 
> ef bb bf ef bb bf 00 0d 0a

I cannot reproduce this.  Are you sure you are using hexl executable
which came with Emacs 27.2 and not some older/incompatible version?
Are you sure your hexl.el is the one which came with Emacs 27.2?

And on what OS is this (you have omitted all the information collected
by report-emacs-bug, so I cannot know that)?

Thanks.