diff --git a/include/haproxy/xprt_quic.h b/include/haproxy/xprt_quic.h index 5e66b5480..48568e9a6 100644 --- a/include/haproxy/xprt_quic.h +++ b/include/haproxy/xprt_quic.h @@ -331,7 +331,8 @@ static inline uint64_t quic_max_int(size_t sz) * buffer with as size for a data field of bytes prefixed by its QUIC * variable-length (may be 0). * Also put in <*len_sz> the size of this QUIC variable-length. - * So after returning from this function we have : <*len_sz> + = . + * So after returning from this function we have : <*len_sz> + <= + * (<*len_sz> = { max(i), i + ret <= }) . */ static inline size_t max_available_room(size_t sz, size_t *len_sz) { @@ -346,8 +347,22 @@ static inline size_t max_available_room(size_t sz, size_t *len_sz) *len_sz = quic_int_getsize(ret); /* Difference between the two sizes. Note that >= <*len_sz>. */ diff = sz_sz - *len_sz; - if (unlikely(diff > 0)) - ret += diff; + if (unlikely(diff > 0)) { + /* Let's try to take into an account remaining bytes. + * + * <----------------> + * <--------------><--------> +----> + * | + * +---------------------------+-----------.... + * <--------------------------------> + */ + size_t max_int = quic_max_int_by_size(*len_sz); + + if (max_int + *len_sz <= sz) + ret = max_int; + else + ret = sz - diff; + } return ret; }