Skip to content

Commit

Permalink
fix #39895, crash from deserialized closure using the shared method t…
Browse files Browse the repository at this point in the history
…able (#39916)

(cherry picked from commit cc66025)
  • Loading branch information
JeffBezanson authored and staticfloat committed Dec 22, 2022
1 parent 0afe40e commit f54127e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,8 @@ function deserialize_typename(s::AbstractSerializer, number)
tn.mt.kwsorter = kws
end
end
elseif makenew
tn.mt = Symbol.name.mt
end
return tn::Core.TypeName
end
Expand Down
15 changes: 15 additions & 0 deletions stdlib/Serialization/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,18 @@ let s = join(rand('a':'z', 1024)), io = IOBuffer()
s2 = deserialize(io)
@test Base.summarysize(s2) < 2*sizeof(s)
end

# issue #39895
@eval Main begin
using Test, Serialization
let g = gensym(:g)
closure = eval(:(f -> $g(x) = f(x)))
inc(x) = x + 1
b = IOBuffer()
serialize(b, closure(inc))
seekstart(b)
f = deserialize(b)
# this should not crash
@test_broken f(1) == 2
end
end

0 comments on commit f54127e

Please sign in to comment.