refill-bv-buffer setting wrong index

Bug #237976 reported by Derick Eddington
2
Affects Status Importance Assigned to Milestone
Ikarus Scheme
Fix Committed
High
Abdulaziz Ghuloum

Bug Description

Running the below program either raises an &i/o-decoding (but never &i/o-encoding it seems) or the read-back-in string is not equal to the original written-out string. What the program does is create a random-sized string filled with random characters, write it to a file, and read it back in and compare it. If creating such arbitrary random strings and writing them out works, shouldn't reading them work and shouldn't they always be equal for every possible random string? Playing with the value of max-string-size alters if it raises an exception or if the strings aren't equal and how long it will go before one of those happens. [This is similar to what I'm pumping through my forked-workers sockets test.]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(import (ikarus))

(define max-string-size #e1e5)

(define (make-test-string)
  (let ([s (make-string (+ 1 (random max-string-size)))])
    (do ([i 0 (+ 1 i)])
      [(fx=? i (string-length s))
       s]
      (let loop ()
        (let ([x (random #x110000)])
          (if (fx<=? #xd800 x #xdfff)
            (loop)
            (string-set! s i (integer->char x))))))))

(define transcoder
  (make-transcoder (utf-8-codec) (eol-style none) (error-handling-mode raise)))

(define tmp-file "/tmp/random-strings")

(let loop ()
  (let ([fop (open-file-output-port tmp-file
               (file-options no-fail) (buffer-mode block) transcoder)]
        [s (make-test-string)])
    (put-string fop s)
    (close-output-port fop)
    (let ([r (call-with-port (open-file-input-port tmp-file
                               (file-options) (buffer-mode block) transcoder)
               get-string-all)])
      (if (string=? r s)
        (display ".")
        (assertion-violation 'check "not equal" s r))))
  (loop))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Related branches

description: updated
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

It's a bug in reading from files (refilling the buffers in the middle of a multibyte character) I believe since it does not show up if you read the file as a bytevector and decode the bytevector as in:

      (let ([r (call-with-port
                 (transcoded-port
                   (open-bytevector-input-port
                     (call-with-port
                       (open-file-input-port tmp-file (file-options)
                         (buffer-mode block)
                         #f)
                       get-bytevector-all))
                   transcoder)
                 get-string-all)])

Changed in ikarus:
assignee: nobody → aghuloum
importance: Undecided → High
status: New → Confirmed
Revision history for this message
Abdulaziz Ghuloum (aghuloum) wrote :

Fixed 1504. Thank you!

Changed in ikarus:
status: Confirmed → Fix Committed
Changed in ikarus:
milestone: none → 0.0.4
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.