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

Packing Dict{Symbol,Any} corrupts data #36

Closed
ararslan opened this issue Sep 25, 2019 · 1 comment · Fixed by #37
Closed

Packing Dict{Symbol,Any} corrupts data #36

ararslan opened this issue Sep 25, 2019 · 1 comment · Fixed by #37
Labels

Comments

@ararslan
Copy link
Member

Reproducer:

julia> bad = Dict{Symbol,Any}(:wake_after_sleep_onset => 0, :wake_after_sleep_onset_percentage => 1)
Dict{Symbol,Any} with 2 entries:
  :wake_after_sleep_onset            => 0
  :wake_after_sleep_onset_percentage => 1

julia> io = IOBuffer();

julia> pack(io, bad)

julia> seekstart(io);

julia> unpack(io, Dict{Symbol,Any})
Dict{Symbol,Any} with 2 entries:
  :wake_after_sleep_onset => 0x00
  :wake_after_sleep       => 0x5f

The keys are truncated and the values are wrong. Also note that the value assigned to the key :wake_after_sleep is the code point for an underscore, which would be the continuation of the key name were it completely consumed.

The problem seems to be specific to packing Symbols, as packing as String and unpacking as Symbol works fine:

julia> ok = Dict{String,Any}("wake_after_sleep_onset" => 0, "wake_after_sleep_onset_percentage" => 1)
Dict{String,Any} with 2 entries:
  "wake_after_sleep_onset"            => 0
  "wake_after_sleep_onset_percentage" => 1

julia> io = IOBuffer();

julia> pack(io, ok)

julia> seekstart(io);

julia> unpack(io, Dict{Symbol,Any})
Dict{Symbol,Any} with 2 entries:
  :wake_after_sleep_onset            => 0x00
  :wake_after_sleep_onset_percentage => 0x01
@ararslan ararslan added the bug label Sep 25, 2019
@ararslan
Copy link
Member Author

ararslan commented Sep 25, 2019

The issue seems to be with this use of sizeof: https://github.com/JuliaIO/MsgPack.jl/blob/master/src/pack.jl#L185. When x here is a PointerString, sizeof doesn't properly capture the length of the underlying data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant