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

2-argument deserialize should be internal #14090

Open
eschnett opened this issue Nov 21, 2015 · 4 comments
Open

2-argument deserialize should be internal #14090

eschnett opened this issue Nov 21, 2015 · 4 comments
Assignees
Labels
deprecation This change introduces or involves a deprecation stdlib Julia's standard library

Comments

@eschnett
Copy link
Contributor

When implementing serialization for a type I defined, I accidentally called deserialize with two arguments, passing the expected type as second argument. Since the respective field was declared as AbstractString, this is the type I passed. As a result, I received a very strange error message:

ERROR: you must implement endof(AbstractString)

It seems as if deserialize created an object of type AbstractString that (of course) later cannot be handled.

This reproduces the error:

io=IOBuffer()
serialize(io, "hello")
s=SerializationState(IOBuffer(io.data))
deserialize(s, AbstractString)
@JeffBezanson JeffBezanson self-assigned this Dec 1, 2015
@JeffBezanson
Copy link
Sponsor Member

Yes, in hindsight it's clear to me that the 2-argument deserialize should be private (i.e. renamed).

@mbauman
Copy link
Sponsor Member

mbauman commented Apr 9, 2021

Well we no longer create abstract types... we just segfault:

julia> using Serialization

julia> s = Serializer(IOBuffer())
Serializer{IOBuffer}(IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1), 0, IdDict{Any, Any}(), Int64[], ^[[BDict{UInt64, Any}(), 15)

julia> serialize(s, "hello")

julia> seekstart(s.io)
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=7, maxsize=Inf, ptr=1, mark=-1)

julia> v = deserialize(s, AbstractString);

signal (11): Segmentation fault: 11
in expression starting at none:0
jl_field_offset at /Users/mbauman/Julia/master/src/./julia.h:1098 [inlined]
set_nth_field at /Users/mbauman/Julia/master/src/datatype.c:1099
jl_f_tuple at /Users/mbauman/Julia/master/src/builtins.c:787
indexed_iterate at ./pair.jl:50 [inlined]
indexed_iterate at ./pair.jl:50
jfptr_indexed_iterate_31423 at /Users/mbauman/Julia/master/usr/lib/julia/sys.dylib (unknown line)
jl_apply_generic at /Users/mbauman/Julia/master/src/gf.c:0

@vtjnash vtjnash added the stdlib Julia's standard library label Apr 9, 2021
@StefanKarpinski StefanKarpinski added the bug Indicates an unexpected problem or unintended behavior label Aug 17, 2021
@LilithHafner
Copy link
Member

This throws a reasonable error in 1.9.0

julia> using Serialization

julia> s = Serializer(IOBuffer())
Serializer{IOBuffer}(IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=0, maxsize=Inf, ptr=1, mark=-1), 0, IdDict{Any, Any}(), Int64[], Dict{UInt64, Any}(), 20)

julia> serialize(s, "hello")

julia> seekstart(s.io)
IOBuffer(data=UInt8[...], readable=true, writable=true, seekable=true, append=false, size=7, maxsize=Inf, ptr=1, mark=-1)

julia> v = deserialize(s, AbstractString);
ERROR: TypeError: in new, expected DataType, got Type{AbstractString}
Stacktrace:
 [1] deserialize(s::Serializer{IOBuffer}, t::DataType)
   @ Serialization ~/.julia/juliaup/julia-1.9.0+0.aarch64.apple.darwin14/share/julia/stdlib/v1.9/Serialization/src/Serialization.jl:1492
 [2] top-level scope
   @ REPL[5]:1

@KristofferC
Copy link
Sponsor Member

#14090 (comment) seems like it stands.

@LilithHafner LilithHafner added deprecation This change introduces or involves a deprecation and removed bug Indicates an unexpected problem or unintended behavior labels Jun 5, 2023
@LilithHafner LilithHafner changed the title deserialize can create objects with abstract types 2-argument deserialize should be internal Jun 5, 2023
@LilithHafner LilithHafner reopened this Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deprecation This change introduces or involves a deprecation stdlib Julia's standard library
Projects
None yet
Development

No branches or pull requests

7 participants