Subject: bug#62290: closed (Re: bug#62290: Error when handling invalid unicode with suspendable ports)

From: [email-masked] (GNU bug Tracking System)
Date: Mon, 20 Mar 2023 22:28:02 +0000

Your bug report

#62290: Error when handling invalid unicode with suspendable ports

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

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

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

Subject: Re: bug#62290: Error when handling invalid unicode with suspendable ports
From: Ludovic Courtès <[email-masked]>
To: Christopher Baines <[email-masked]>
Cc: [email-masked]
Date: Mon, 20 Mar 2023 23:27:32 +0100
List-Id: <debbugs-submit.debbugs.gnu.org>

Hello,

Christopher Baines <[email-masked]> skribis:

> Based on the implementation in ports.c.  I don't understand what this
> code is really doing, but the suspendable ports implementation differs
> from the similar C code for a couple of inequalities.
>
> * module/ice-9/suspendable-ports.scm (decode-utf8, bad-utf8-len): Flip a
> couple of inequalities.
> * test-suite/tests/ports.test ("string ports"): Add additional invalid
> UTF-8 test case.

Pushed as cba2e7e3fec3c781230570f5d1ef070625eeeda8.

Thanks for documenting the problem and providing a perfect patch!

Ludo’.

Subject: Error when handling invalid unicode with suspendable ports
From: Christopher Baines <[email-masked]>
To: [email-masked]
Date: Mon, 20 Mar 2023 09:09:14 +0000
List-Id: <debbugs-submit.debbugs.gnu.org>

Here's a simple reproducer:

  (use-modules (ice-9 binary-ports)
               (ice-9 suspendable-ports)
               (rnrs bytevectors))

  (define (test)
    (let* ((sequence
             '(#xf4 #xa4 #xbd #xa4))
           (p (open-bytevector-input-port
               (u8-list->bytevector sequence))))
      (set-port-encoding! p "UTF-8")
      (set-port-conversion-strategy! p 'substitute)
      (peek (read-char p))))

  (test)

  (install-suspendable-ports!)

  (test)

If you run it, it outputs #\� as expected the first time, but then using
suspendable ports, it raises an exception. The behaviour should be the
same.

;;; (#\�)
Backtrace:
In ice-9/boot-9.scm:
  1752:10  8 (with-exception-handler _ _ #:unwind? _ # _)
In unknown file:
           7 (apply-smob/0 #<thunk 7f3f09cbe300>)
In ice-9/boot-9.scm:
    724:2  6 (call-with-prompt ("prompt") #<procedure 7f3f09ccb320 …> …)
In ice-9/eval.scm:
    619:8  5 (_ #(#(#<directory (guile-user) 7f3f09cc1c80>)))
In ice-9/boot-9.scm:
   2836:4  4 (save-module-excursion #<procedure 7f3f09cb2300 at ice-…>)
  4388:12  3 (_)
In /home/chris/Projects/Guile/guile/bad-unicode.scm:
    12:10  2 (test)
In ice-9/suspendable-ports.scm:
   591:33  1 (read-char _)
   499:12  0 (peek-char-and-next-cur/utf8 _ _ _ _)

ice-9/suspendable-ports.scm:499:12: In procedure peek-char-and-next-cur/utf8:
In procedure integer->char: Argument 1 out of range: 1199972