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

take! after pushfirst! reads garbage values #54097

Closed
nhz2 opened this issue Apr 16, 2024 · 2 comments · Fixed by #54129
Closed

take! after pushfirst! reads garbage values #54097

nhz2 opened this issue Apr 16, 2024 · 2 comments · Fixed by #54129
Milestone

Comments

@nhz2
Copy link
Contributor

nhz2 commented Apr 16, 2024

Here is a MWE:

julia> b = pushfirst!([0x02], 0x01)
2-element Vector{UInt8}:
 0x01
 0x02

julia> take!(IOBuffer(b))
5-element Vector{UInt8}:
 0x01
 0x02
 0x69
 0x73
 0x69
julia> versioninfo()
Julia Version 1.12.0-DEV.347
Commit c0611e8c49c (2024-04-15 17:22 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 16 × AMD Ryzen 7 7800X3D 8-Core Processor
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, znver4)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)

I think the issue is

data = copyto!(StringVector(io.size), 1, io.data, io.offset + 1, nbytes)

using StringVector(io.size) instead of StringVector(nbytes).

The pushfirst! causes the IOBuffer to have a nonzero offset field (added in #53192) which makes nbytes and io.size different.

@andrewjradcliffe
Copy link
Contributor

Technically, it's not reading garbage values, but rather, nothing is written to the trailing io.size - nbytes values allocated by StringVector.

@KristofferC
Copy link
Sponsor Member

KristofferC commented Apr 18, 2024

I made a PR to get the ball rolling (#54129).

oscardssmith pushed a commit that referenced this issue Apr 20, 2024
KristofferC added a commit that referenced this issue Apr 25, 2024
PR from #54097.

Fixes #54097

Co-authored-by: Nathan Zimmerberg
(cherry picked from commit fda02ac)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants