Skip to content

Commit

Permalink
Avoid infinite loop in readbytes!(s, UInt8[], 1) (#194)
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 authored Mar 28, 2024
1 parent fc11ad7 commit 9d69586
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/stream.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ function Base.readbytes!(stream::TranscodingStream, b::DenseArray{UInt8}, nb=len
resized = false
while filled < nb && !eof(stream)
if length(b) == filled
resize!(b, min(length(b) * 2, nb))
resize!(b, min(max(length(b) * 2, 8), nb))
resized = true
end
filled += GC.@preserve b unsafe_read(stream, pointer(b, filled+1), min(length(b), nb)-filled)
Expand Down
8 changes: 8 additions & 0 deletions test/codecnoop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@
@test readavailable(stream) == b"oobar"
close(stream)

# issue #193
stream = NoopStream(IOBuffer("foobar"))
data = UInt8[]
@test readbytes!(stream, data, 1) === 1
@test data == b"f"
@test position(stream) == 1
close(stream)

data = b""
@test transcode(Noop, data) == data
@test transcode(Noop, data) !== data
Expand Down

0 comments on commit 9d69586

Please sign in to comment.