Skip to content

Commit

Permalink
Merge branch 'master' into nz/fix-position2
Browse files Browse the repository at this point in the history
  • Loading branch information
nhz2 authored Mar 30, 2024
2 parents 6e0a7e7 + e81cd34 commit 767f406
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions fuzz/fuzz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ function wrap_stream(codecs_kws, io::IO)::IO
end
end

# read data using various means
# these function read data from io,
# if the stream is eof they should return an empty vector.
# Read data using various means.
# These function read a vector of bytes from io,
# if io is eof they should return an empty vector.
read_methods = Data.SampledFrom([
function read_byte(io)
eof(io) && return UInt8[]
Expand Down Expand Up @@ -92,7 +92,6 @@ read_methods = Data.SampledFrom([
])



@check function read_byte_data(
kws=read_codecs_kws,
data=datas,
Expand Down
16 changes: 16 additions & 0 deletions test/codecdoubleframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,22 @@ DoubleFrameDecoderStream(stream::IO; kwargs...) = TranscodingStream(DoubleFrameD
@test eof(s2)
end

@testset "reading zero bytes from invalid stream" begin
# This behavior is required to avoid breaking JLD2.jl
# `s` must go into read mode, but not actually call `eof`
for readnone in (io -> read!(io, UInt8[]), io -> read(io, 0))
for invalid_data in (b"", b"asdf")
s = DoubleFrameDecoderStream(IOBuffer(invalid_data;read=true,write=true))
@test iswritable(s)
@test isreadable(s)
readnone(s)
@test !iswritable(s)
@test isreadable(s)
@test_throws ErrorException eof(s)
end
end
end

test_roundtrip_read(DoubleFrameEncoderStream, DoubleFrameDecoderStream)
test_roundtrip_write(DoubleFrameEncoderStream, DoubleFrameDecoderStream)
test_roundtrip_lines(DoubleFrameEncoderStream, DoubleFrameDecoderStream)
Expand Down

0 comments on commit 767f406

Please sign in to comment.