Skip to content

Commit eb5da26

Browse files
committed
Merge pull request #11330 from yuyichao/field-overflow
Throw OverflowError when the field offset / size overflows.
2 parents c777d31 + 49a3f3a commit eb5da26

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/alloc.c

+4
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ void jl_compute_field_offsets(jl_datatype_t *st)
534534
size_t fsz, al;
535535
if (jl_isbits(ty) && jl_is_leaf_type(ty)) {
536536
fsz = jl_datatype_size(ty);
537+
if (__unlikely(fsz > JL_FIELD_MAX_SIZE))
538+
jl_throw(jl_overflow_exception);
537539
al = ((jl_datatype_t*)ty)->alignment;
538540
st->fields[i].isptr = 0;
539541
}
@@ -550,6 +552,8 @@ void jl_compute_field_offsets(jl_datatype_t *st)
550552
if (al > alignm)
551553
alignm = al;
552554
}
555+
if (__unlikely(sz > JL_FIELD_MAX_OFFSET))
556+
jl_throw(jl_overflow_exception);
553557
st->fields[i].offset = sz;
554558
st->fields[i].size = fsz;
555559
sz += fsz;

src/julia.h

+3
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ typedef struct {
265265
uint16_t isptr:1;
266266
} jl_fielddesc_t;
267267

268+
#define JL_FIELD_MAX_OFFSET ((1ul << 16) - 1ul)
269+
#define JL_FIELD_MAX_SIZE ((1ul << 15) - 1ul)
270+
268271
typedef struct _jl_datatype_t {
269272
JL_DATA_TYPE
270273
jl_typename_t *name;

0 commit comments

Comments
 (0)