Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix for issue 7: backtracking gone wrong for CODE refs

When trying to stringify an unknown data structure, the encoder had a
bug in the backtracking that would cause output corruption for
refcounts > 1. Solution: Avoid tracking refs that we don't want to refer
to using REFP/ALIAS.
  • Loading branch information...
commit 48d5cdc3dc07fd29ac7be05678a0b614244fec4f 1 parent 1aa23fd
@tsee tsee authored
Showing with 11 additions and 2 deletions.
  1. +11 −2 Perl/Encoder/srl_encoder.c
View
13 Perl/Encoder/srl_encoder.c
@@ -987,8 +987,13 @@ srl_dump_sv(pTHX_ srl_encoder_t *enc, SV *src)
warn("Found type %u %s(0x%p), but it is not representable " \
"by the Sereal encoding format; will encode as an " \
"undefined value", (svt), sv_reftype((src),0),(src)); \
- if (ref_rewrite_pos) \
+ if (ref_rewrite_pos) { \
+ /* make sure we don't keep a reference to the thing that we do not \
+ * want to serialize around for REFP and ALIAS output */ \
+ PTABLE_t *ref_seenhash= SRL_GET_REF_SEENHASH(enc); \
+ PTABLE_delete(ref_seenhash, src); \
enc->pos= enc->buf_start + ref_rewrite_pos; \
+ } \
srl_buf_cat_char((enc), SRL_HDR_UNDEF); \
} \
else if ( SRL_ENC_HAVE_OPTION((enc), SRL_F_STRINGIFY_UNKNOWN) ) { \
@@ -1010,7 +1015,11 @@ srl_dump_sv(pTHX_ srl_encoder_t *enc, SV *src)
"stringified form", (svt), sv_reftype((src),0),(src)); \
} \
} \
- if (refsv) { \
+ if (ref_rewrite_pos) { \
+ /* make sure we don't keep a reference to the thing that we do not \
+ * want to serialize around for REFP and ALIAS output */ \
+ PTABLE_t *ref_seenhash= SRL_GET_REF_SEENHASH(enc); \
+ PTABLE_delete(ref_seenhash, src); \
enc->pos= enc->buf_start + ref_rewrite_pos; \
str = SvPV((refsv), len); \
} else \
Please sign in to comment.
Something went wrong with that request. Please try again.