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

GenericIOBuffer assumes data is stored contiguously in memory #54636

Open
nhz2 opened this issue May 30, 2024 · 0 comments
Open

GenericIOBuffer assumes data is stored contiguously in memory #54636

nhz2 opened this issue May 30, 2024 · 0 comments
Labels
bug Indicates an unexpected problem or unintended behavior io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@nhz2
Copy link
Contributor

nhz2 commented May 30, 2024

julia/base/iobuffer.jl

Lines 184 to 194 in 4ecdc37

function unsafe_read(from::GenericIOBuffer, p::Ptr{UInt8}, nb::UInt)
from.readable || _throw_not_readable()
avail = bytesavailable(from)
adv = min(avail, nb)
GC.@preserve from unsafe_copyto!(p, pointer(from.data, from.ptr), adv)
from.ptr += adv
if nb > avail
throw(EOFError())
end
nothing
end

This can lead to the following strange behavior:

julia> a = @view(collect(0x00:0x0f)[begin:2:end])
8-element view(::Vector{UInt8}, 1:2:15) with eltype UInt8:
 0x00
 0x02
 0x04
 0x06
 0x08
 0x0a
 0x0c
 0x0e

julia> b = read(IOBuffer(a))
8-element Vector{UInt8}:
 0x00
 0x01
 0x02
 0x03
 0x04
 0x05
 0x06
 0x07

Tasks

No tasks being tracked yet.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant