In order to test that some code handles an invalid UTF-8 sequence properly, I need to insert an invalid UTF-8 sequence into an existing text file. However, my attempts to do so result in a valid UTF-8 sequence, not an invalid one.
The byte 0xff is always invalid in UTF-8, so I tried to insert it, following the instructions on the "Inserting Text" page of the Emacs manual:
c-q 377 <RET>
A funny-looking character got inserted into the file:
-OP INC ÿ3713 SOUTHS ^
However, when I examine the contents of the file using the Unix command
od -c <path>:
0001240 C \t 303 277 3 7 1 3 S O U T H S H ^^^ ^^^
I can see that a valid UTF-8 sequence 303 277 (octal) has been inserted, not the single byte 377 that I tried to insert.
How can I insert an invalid UTF-8 sequence into a file?