diff --git a/source/nwm_misc/ikcp.c b/source/nwm_misc/ikcp.c index 363238c..432d70a 100644 --- a/source/nwm_misc/ikcp.c +++ b/source/nwm_misc/ikcp.c @@ -605,6 +605,10 @@ int ikcp_input(ikcpcb *kcp, char *data, int size) IUINT16 nack_start = (val >> count_nbits) & ((1 << PID_NBITS) - 1); IUINT16 nack_count_0 = size == 1 ? (1 << (PID_NBITS - 2)) - 1 : val & ((1 << count_nbits) - 1); + if (kcp->n_nacks >= sizeof(kcp->nacks) / sizeof(*kcp->nacks)) { + return -4; + } + kcp->nacks[kcp->n_nacks][0] = nack_start; kcp->nacks[kcp->n_nacks][1] = nack_count_0; ++kcp->n_nacks; diff --git a/source/nwm_misc/ikcp.h b/source/nwm_misc/ikcp.h index 829bbf0..2405b14 100644 --- a/source/nwm_misc/ikcp.h +++ b/source/nwm_misc/ikcp.h @@ -358,8 +358,8 @@ struct IKCPCB #ifdef CHECK_PID struct BitSet4096Mem pid_bs; #endif - // Worst case every other packet is nack - u16 nacks[DIV_ROUND_UP(ARQ_PREFERRED_COUNT_MAX, 2)][2]; + // Worst case between every other packet is nack + u16 nacks[ARQ_PREFERRED_COUNT_MAX][2]; u16 n_nacks; };