@@ -737,6 +737,19 @@ function resolve_ref_immediately(s::AbstractSerializer, @nospecialize(x))
737
737
nothing
738
738
end
739
739
740
+ function gettable (s:: AbstractSerializer , id:: Int )
741
+ get (s. table, id) do
742
+ errmsg = """ Inconsistent Serializer state when deserializing.
743
+ Attempt to access internal table with key $id failed.
744
+
745
+ This might occur if the Serializer contexts when serializing and deserializing are inconsistent.
746
+ In particular, if multiple serialize calls use the same Serializer object then
747
+ the corresponding deserialize calls should also use the same Serializer object.
748
+ """
749
+ error (errmsg)
750
+ end
751
+ end
752
+
740
753
# deserialize_ is an internal function to dispatch on the tag
741
754
# describing the serialized representation. the number of
742
755
# representations is fixed, so deserialize_ does not get extended.
@@ -750,10 +763,10 @@ function handle_deserialize(s::AbstractSerializer, b::Int32)
750
763
return deserialize_tuple (s, Int (read (s. io, UInt8):: UInt8 ))
751
764
elseif b == SHORTBACKREF_TAG
752
765
id = read (s. io, UInt16):: UInt16
753
- return s . table[ Int (id)]
766
+ return gettable (s, Int (id))
754
767
elseif b == BACKREF_TAG
755
768
id = read (s. io, Int32):: Int32
756
- return s . table[ Int (id)]
769
+ return gettable (s, Int (id))
757
770
elseif b == ARRAY_TAG
758
771
return deserialize_array (s)
759
772
elseif b == DATATYPE_TAG
@@ -800,7 +813,7 @@ function handle_deserialize(s::AbstractSerializer, b::Int32)
800
813
return deserialize_expr (s, Int (read (s. io, Int32):: Int32 ))
801
814
elseif b == LONGBACKREF_TAG
802
815
id = read (s. io, Int64):: Int64
803
- return s . table[ Int (id)]
816
+ return gettable (s, Int (id))
804
817
elseif b == LONGSYMBOL_TAG
805
818
return deserialize_symbol (s, Int (read (s. io, Int32):: Int32 ))
806
819
elseif b == HEADER_TAG
0 commit comments