From 8e1ad64eb7e4cd914dbd6f477c217987209c1950 Mon Sep 17 00:00:00 2001 From: Tim Besard Date: Wed, 15 Jan 2020 16:49:31 +0100 Subject: [PATCH] Don't read trailing datatype layout bytes when first_ptr==-1. --- src/dump.c | 12 +++++++++--- src/staticdata.c | 4 +++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/dump.c b/src/dump.c index a0ddd5de89786..ee15e193910d3 100644 --- a/src/dump.c +++ b/src/dump.c @@ -403,7 +403,10 @@ static void jl_serialize_datatype(jl_serializer_state *s, jl_datatype_t *dt) JL_ uint32_t np = dt->layout->npointers; size_t fieldsize = jl_fielddesc_size(dt->layout->fielddesc_type); ios_write(s->s, (const char*)dt->layout, sizeof(*dt->layout)); - ios_write(s->s, (const char*)(dt->layout + 1), nf * fieldsize + (np << dt->layout->fielddesc_type)); + size_t fldsize = nf * fieldsize; + if (dt->layout->first_ptr != -1) + fldsize += np << dt->layout->fielddesc_type; + ios_write(s->s, (const char*)(dt->layout + 1), fldsize); } } @@ -1484,11 +1487,14 @@ static jl_value_t *jl_deserialize_datatype(jl_serializer_state *s, int pos, jl_v uint32_t np = buffer.npointers; uint8_t fielddesc_type = buffer.fielddesc_type; size_t fielddesc_size = nf > 0 ? jl_fielddesc_size(fielddesc_type) : 0; + size_t fldsize = nf * fielddesc_size; + if (buffer.first_ptr != -1) + fldsize += np << fielddesc_type; jl_datatype_layout_t *layout = (jl_datatype_layout_t*)jl_gc_perm_alloc( - sizeof(jl_datatype_layout_t) + nf * fielddesc_size + (np << fielddesc_type), + sizeof(jl_datatype_layout_t) + fldsize, 0, 4, 0); *layout = buffer; - ios_read(s->s, (char*)(layout + 1), nf * fielddesc_size + (np << fielddesc_type)); + ios_read(s->s, (char*)(layout + 1), fldsize); dt->layout = layout; } } diff --git a/src/staticdata.c b/src/staticdata.c index a59168c63716d..e789713d4f39b 100644 --- a/src/staticdata.c +++ b/src/staticdata.c @@ -871,7 +871,9 @@ static void jl_write_values(jl_serializer_state *s) size_t np = dt->layout->npointers; size_t fieldsize = jl_fielddesc_size(dt->layout->fielddesc_type); char *flddesc = (char*)dt->layout; - size_t fldsize = sizeof(jl_datatype_layout_t) + nf * fieldsize + (np << dt->layout->fielddesc_type); + size_t fldsize = sizeof(jl_datatype_layout_t) + nf * fieldsize; + if (dt->layout->first_ptr != -1) + fldsize += np << dt->layout->fielddesc_type; uintptr_t layout = LLT_ALIGN(ios_pos(s->const_data), sizeof(void*)); write_padding(s->const_data, layout - ios_pos(s->const_data)); // realign stream newdt->layout = NULL; // relocation offset