Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid infinite loop in readbytes!(s, UInt8[], 1) #194

Merged
merged 2 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading