1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Ensure that the table size for CACHE_MATCH fits with int

Currently, the keys for CACHE_MATCH are handled as an `int` type. So we
should make sure the table size are smaller than the range of `int`.
This commit is contained in:
Yusuke Endoh 2022-11-08 23:36:14 +09:00
parent 537286d0bb
commit 14845ab4ff

View file

@ -3842,7 +3842,7 @@ match_at(regex_t* reg, const UChar* str, const UChar* end,
size_t len = (end - str) + 1; size_t len = (end - str) + 1;
size_t match_cache_size8 = (size_t)msa->num_cache_opcode * len; size_t match_cache_size8 = (size_t)msa->num_cache_opcode * len;
/* overflow check */ /* overflow check */
if (match_cache_size8 / len != (size_t)msa->num_cache_opcode) { if (match_cache_size8 >= INT_MAX_LIMIT) {
return ONIGERR_MEMORY; return ONIGERR_MEMORY;
} }
size_t match_cache_size = (match_cache_size8 >> 3) + (match_cache_size8 & 7 ? 1 : 0); size_t match_cache_size = (match_cache_size8 >> 3) + (match_cache_size8 & 7 ? 1 : 0);