Subject: bug#16286: closed (Re: 24.3.50; insert-file-contents may bring invisible garbage)

From: [email-masked] (GNU bug Tracking System)
Date: Sun, 26 Jan 2014 00:37:03 +0000

Your bug report

#16286: 24.3.50; insert-file-contents may bring invisible garbage

which was filed against the emacs package, has been closed.

The explanation is attached below, along with your original report.
If you require more details, please reply to [email-masked].

-- 
16286: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=16286
GNU Bug Tracking System
Contact [email-masked] with problems

Subject: Re: 24.3.50; insert-file-contents may bring invisible garbage
From: Paul Eggert <[email-masked]>
To: [email-masked]
Cc: Kenichi Handa <[email-masked]>
Date: Sat, 25 Jan 2014 16:36:29 -0800
List-Id: <debbugs-submit.debbugs.gnu.org>

I installed a patch as trunk bzr 116158, which (at least for me) fixes 
the reported bug, and am taking the liberty of marking this as done. 
There may well be a better fix, but at least Emacs shouldn't crash or 
report nonsense now.

Subject: 24.3.50; insert-file-contents may bring invisible garbage
From: Andrey Kotlarski <[email-masked]>
To: [email-masked]
Date: Sun, 29 Dec 2013 16:05:22 +0200
List-Id: <debbugs-submit.debbugs.gnu.org>

In trunk inserting few bytes from file may sometimes result in nothing
visible in the buffer while invisible artifacts are present and may
affect subsequent operations.  Moreover, there doesn't seem to be way to
recover from this.  Here's example session with emacs -Q:

(let ((file "test.txt"))
  (unless (file-exists-p file)
    (find-file file)
    (insert "абв")                      ;Cyrillic letters
    (save-buffer)
    (kill-buffer))

  (let ((buf (generate-new-buffer "test")))
    (switch-to-buffer buf)
    (insert-file-contents file nil 0 2) ;inserts а
    (goto-char (point-max))
    (insert-file-contents file nil 2 3) ;returns 0 bytes inserted, nothing visible in the buffer
                                        ;but actually there is
    (erase-buffer)                      ;and still is
    (insert-file-contents file nil 2 4) ;should insert б, instead let: Wrong type argument: inserted-chars, 1
    (message "%S" (buffer-string)) ;"бЀ" while buffer is visibly empty
    ))

Trying to insert multibyte characters now brings content length issues,
garbage inserted and at some point Emacs crashes.

In release 24.3 and earlier insert-file-contents seems to always insert
something, be it wrongly decoded or raw eight-bit characters.  But it is
visible and easy to deal with.  The above example works fine there.
This is useful for the vlf package (https://github.com/m00natic/vlfi) as
a way to detect insufficient amount of bytes requested and allows
further adjustment.

In GNU Emacs 24.3.50.1 (x86_64-pc-linux-gnu)
 of 2013-12-29 on andrexhe
Bzr revision: 115803 [email-masked]
Windowing system distributor `The X.Org Foundation', version 11.0.11405000
Configured using:
 `configure --build=x86_64-pc-linux-gnu --enable-link-time-optimization
 --with-x-toolkit=no --with-wide-int --without-toolkit-scroll-bars
 --without-xaw3d --without-gpm --without-gconf --without-gsettings
 build_alias=x86_64-pc-linux-gnu 'CFLAGS=-march=native -mtune=native -O2
 -pipe''

Important settings:
  value of $LC_COLLATE: C
  value of $LANG: bg_BG.UTF-8
  locale-coding-system: utf-8-unix

Major mode: Fundamental

Minor modes in effect:
  tooltip-mode: t
  electric-indent-mode: t
  mouse-wheel-mode: t
  tool-bar-mode: t
  menu-bar-mode: t
  file-name-shadow-mode: t
  global-font-lock-mode: t
  blink-cursor-mode: t
  auto-composition-mode: t
  auto-encryption-mode: t
  auto-compression-mode: t
  line-number-mode: t
  transient-mark-mode: t

Recent input:
M-x r e p o - e m - b u <tab> <return>

Recent messages:
For information about GNU Emacs and the GNU system, type C-h C-a.
let: Wrong type argument: inserted-chars, 1

Load-path shadows:
None found.

Features:
(shadow sort gnus-util mail-extr emacsbug message format-spec rfc822 mml
easymenu mml-sec mm-decode mm-bodies mm-encode mail-parse rfc2231
mailabbrev gmm-utils mailheader sendmail rfc2047 rfc2045 ietf-drums
mm-util help-fns mail-prsvr mail-utils time-date tooltip electric
uniquify ediff-hook vc-hooks lisp-float-type mwheel x-win x-dnd tool-bar
dnd fontset image regexp-opt fringe tabulated-list newcomment lisp-mode
prog-mode register page menu-bar rfn-eshadow timer select scroll-bar
mouse jit-lock font-lock syntax facemenu font-core frame cham georgian
utf-8-lang misc-lang vietnamese tibetan thai tai-viet lao korean
japanese hebrew greek romanian slovak czech european ethiopic indian
cyrillic chinese case-table epa-hook jka-cmpr-hook help simple abbrev
minibuffer nadvice loaddefs button faces cus-face macroexp files
text-properties overlay sha1 md5 base64 format env code-pages mule
custom widget hashtable-print-readable backquote make-network-process
dbusbind gfilenotify dynamic-setting font-render-setting x multi-tty
emacs)