After some further testing and code review of the Bug#77135 fixes, I came up with some additional patches, which I just now installed on Emacs master on Savannah. The goal is to make insert-file-contents a little bit less messy, and a little less buggy in unlikely situations and platforms. I hope it works for you too. I'm attaching the union of all 15 patches for easy review, or you can look at the individual changes by inspecting each individual Git commits.