Prevent read-bytevector from corrupting data

Previously it was possible for an extra by to be introduced between multiple reads
This commit is contained in:
Justin Ethier 2020-03-06 12:33:05 -05:00
parent f2bf308746
commit b5a9bd24e1
2 changed files with 12 additions and 12 deletions

View file

@ -14,8 +14,7 @@ Features
Bug Fixes Bug Fixes
- WIP - bug fixes to `read-bytevector` (return EOF, issue with sha2 sums) - Fixed a bug in `read-bytevector` where an extra byte could be introduced when reading multiple chunks of data.
- Fixed a bug where variables defined within `define-syntax` and `let-syntax` are reported as unbound by the compiler. - Fixed a bug where variables defined within `define-syntax` and `let-syntax` are reported as unbound by the compiler.
## 0.15 - February 26, 2020 ## 0.15 - February 26, 2020

View file

@ -715,16 +715,17 @@
(car _port))) (car _port)))
(bv (make-bytevector k)) (bv (make-bytevector k))
(loop (lambda (n) (loop (lambda (n)
(let ((b (read-u8 port))) (if (>= n k)
(cond bv
((eof-object? b) (let ((b (read-u8 port)))
(if (zero? n) (cond
b ;; EOF ((eof-object? b)
(bytevector-copy bv 0 n))) (if (zero? n)
((< n k) b ;; EOF
(bytevector-u8-set! bv n b) (bytevector-copy bv 0 n)))
(loop (+ n 1))) (else
(else bv)))))) (bytevector-u8-set! bv n b)
(loop (+ n 1)))))))))
(loop 0))) (loop 0)))
(define (read-bytevector! vec . o) (define (read-bytevector! vec . o)
(let* ((in (if (pair? o) (car o) (current-input-port))) (let* ((in (if (pair? o) (car o) (current-input-port)))