GNU bug report logs - #60779
‘SCM_F_BYTEVECTOR_IMMUTABLE’ is not honored by bytevector instructions

Previous Next

Package: guile;

Reported by: Ludovic Courtès <ludo <at> gnu.org>

Date: Fri, 13 Jan 2023 11:25:01 UTC

Severity: normal

To reply to this bug, email your comments to 60779 AT debbugs.gnu.org.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guile <at> gnu.org:
bug#60779; Package guile. (Fri, 13 Jan 2023 11:25:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Ludovic Courtès <ludo <at> gnu.org>:
New bug report received and forwarded. Copy sent to bug-guile <at> gnu.org. (Fri, 13 Jan 2023 11:25:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: bug-guile <at> gnu.org
Subject: ‘SCM_F_BYTEVECTOR_IMMUTABLE’ is
 not honored by bytevector instructions
Date: Fri, 13 Jan 2023 12:24:30 +0100
Bytevector literals are marked as ‘SCM_F_BYTEVECTOR_IMMUTABLE’, but VM
instructions that access bytevectors do not check that flag, which can
lead to segfaults:

--8<---------------cut here---------------start------------->8---
$ cat t.scm
(use-modules (rnrs bytevectors))

(define bv #vu8(1 2 3))
(bytevector-u8-set! bv 0 1)
$ guild compile -O2 t.scm
wrote `/home/ludo/.cache/guile/ccache/3.0-LE-8-4.6/data/src/guile-3.0/t.scm.go'
$ guile t.scm
Segmentation fault
--8<---------------cut here---------------end--------------->8---

Conversely, the subrs from bytevector.c do check the flag:

--8<---------------cut here---------------start------------->8---
$ guild compile -O0 t.scm
wrote `/home/ludo/.cache/guile/ccache/3.0-LE-8-4.6/data/src/guile-3.0/t.scm.go'
$ guile t.scm
Backtrace:
In ice-9/boot-9.scm:
  1752:10  6 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
           5 (apply-smob/0 #<thunk 7f2396b0e2e0>)
In ice-9/boot-9.scm:
    724:2  4 (call-with-prompt ("prompt") #<procedure 7f2396b20c60 …> …)
In ice-9/eval.scm:
    619:8  3 (_ #(#(#<directory (guile-user) 7f2396b14c80>)))
In ice-9/boot-9.scm:
   2836:4  2 (save-module-excursion #<procedure 7f2396b06300 at ice-…>)
  4388:12  1 (_)
In unknown file:
           0 (bytevector-u8-set! #vu8(1 2 3) 0 1)

ERROR: In procedure bytevector-u8-set!:
In procedure bytevector-u8-set!: Wrong type argument in position 1 (expecting mutable bytevector): #vu8(1 2 3)
$ guile --version
guile (GNU Guile) 3.0.8
Copyright (C) 2021 Free Software Foundation, Inc.

License LGPLv3+: GNU LGPL 3 or later <http://gnu.org/licenses/lgpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
--8<---------------cut here---------------end--------------->8---

I suppose the immutability test would have to be done not at the level
of individual VM instructions but at a higher-level in generated code,
such that the compiler could lift the test outside loops that access
bytevectors, similar to what it does with ‘heap-object?’.

Ludo’.




This bug report was last modified 1 year and 102 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.