mirror of
https://git.in.rschanz.org/ryan77627/guix.git
synced 2025-01-25 20:19:18 -05:00
zlib: Protect against non-empty port internal buffers.
* guix/zlib.scm (make-gzip-input-port)[gzfile]: Error out if (drain-input port) returns a non-empty string. * guix/zlib.scm (make-gzip-output-port)[gzfile]: Call 'force-output'.
This commit is contained in:
parent
d00240c36e
commit
688ec13c45
1 changed files with 15 additions and 4 deletions
|
@ -168,9 +168,18 @@ (define* (make-gzip-input-port port #:key (buffer-size %default-buffer-size))
|
||||||
"Return an input port that decompresses data read from PORT, a file port.
|
"Return an input port that decompresses data read from PORT, a file port.
|
||||||
PORT is automatically closed when the resulting port is closed. BUFFER-SIZE
|
PORT is automatically closed when the resulting port is closed. BUFFER-SIZE
|
||||||
is the size in bytes of the internal buffer, 8 KiB by default; using a larger
|
is the size in bytes of the internal buffer, 8 KiB by default; using a larger
|
||||||
buffer increases decompression speed."
|
buffer increases decompression speed. An error is thrown if PORT contains
|
||||||
|
buffered input, which would be lost (and is lost anyway)."
|
||||||
(define gzfile
|
(define gzfile
|
||||||
|
(match (drain-input port)
|
||||||
|
("" ;PORT's buffer is empty
|
||||||
(gzdopen (fileno port) "r"))
|
(gzdopen (fileno port) "r"))
|
||||||
|
(_
|
||||||
|
;; This is unrecoverable but it's better than having the buffered input
|
||||||
|
;; be lost, leading to unclear end-of-file or corrupt-data errors down
|
||||||
|
;; the path.
|
||||||
|
(throw 'zlib-error 'make-gzip-input-port
|
||||||
|
"port contains buffered input" port))))
|
||||||
|
|
||||||
(define (read! bv start count)
|
(define (read! bv start count)
|
||||||
(gzread! gzfile bv start count))
|
(gzread! gzfile bv start count))
|
||||||
|
@ -189,8 +198,10 @@ (define* (make-gzip-output-port port
|
||||||
a file port, as its sink. PORT is automatically closed when the resulting
|
a file port, as its sink. PORT is automatically closed when the resulting
|
||||||
port is closed."
|
port is closed."
|
||||||
(define gzfile
|
(define gzfile
|
||||||
|
(begin
|
||||||
|
(force-output port) ;empty PORT's buffer
|
||||||
(gzdopen (fileno port)
|
(gzdopen (fileno port)
|
||||||
(string-append "w" (number->string level))))
|
(string-append "w" (number->string level)))))
|
||||||
|
|
||||||
(define (write! bv start count)
|
(define (write! bv start count)
|
||||||
(gzwrite gzfile bv start count))
|
(gzwrite gzfile bv start count))
|
||||||
|
|
Loading…
Reference in a new issue