mirror of
https://github.com/ruby/ruby.git
synced 2026-08-03 11:18:06 +08:00
Prevent overflow of length bits for embedded structs
Embedded structs only use 7 bits for the length, so it will overflow if the GC can allocate large slots. We need to add the cap to struct_alloc.
This commit is contained in:
parent
f132ecd1d9
commit
916d8c1050
Notes:
git
2026-07-11 06:21:28 +00:00
4
struct.c
4
struct.c
@ -829,7 +829,9 @@ struct_alloc(VALUE klass)
|
||||
|
||||
VALUE flags = T_STRUCT;
|
||||
|
||||
if (n > 0 && rb_gc_size_allocatable_p(embedded_size)) {
|
||||
const long embed_len_max = RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT;
|
||||
|
||||
if (n > 0 && n <= embed_len_max && rb_gc_size_allocatable_p(embedded_size)) {
|
||||
flags |= n << RSTRUCT_EMBED_LEN_SHIFT;
|
||||
if (RCLASS_MAX_IV_COUNT(klass) == 0) {
|
||||
// We set the flag before calling `NEWOBJ_OF` in case a NEWOBJ tracepoint does
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user