Skip to content

Commit 9d69586

Browse files
authored
Avoid infinite loop in readbytes!(s, UInt8[], 1) (#194)
1 parent fc11ad7 commit 9d69586

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/stream.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ function Base.readbytes!(stream::TranscodingStream, b::DenseArray{UInt8}, nb=len
412412
resized = false
413413
while filled < nb && !eof(stream)
414414
if length(b) == filled
415-
resize!(b, min(length(b) * 2, nb))
415+
resize!(b, min(max(length(b) * 2, 8), nb))
416416
resized = true
417417
end
418418
filled += GC.@preserve b unsafe_read(stream, pointer(b, filled+1), min(length(b), nb)-filled)

test/codecnoop.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,14 @@
195195
@test readavailable(stream) == b"oobar"
196196
close(stream)
197197

198+
# issue #193
199+
stream = NoopStream(IOBuffer("foobar"))
200+
data = UInt8[]
201+
@test readbytes!(stream, data, 1) === 1
202+
@test data == b"f"
203+
@test position(stream) == 1
204+
close(stream)
205+
198206
data = b""
199207
@test transcode(Noop, data) == data
200208
@test transcode(Noop, data) !== data

0 commit comments

Comments
 (0)