From eeea2488c34968a0316c7cd97e1b79c5f72ec953 Mon Sep 17 00:00:00 2001 From: Colton Willey Date: Tue, 30 Jun 2026 12:58:10 -0700 Subject: [PATCH] wp_aes_stream: bound CTS input length to prevent int overflow The CTS encrypt/decrypt helpers cast the block count to int, so an inLen above 0x7FFFFFFF overflows blocks*AES_BLOCK_SIZE and smashes the stack copy. Not reachable via EVP_CipherUpdate (its inl is int); guard added as defense in depth for a caller driving OSSL_FUNC_cipher_update directly. --- src/wp_aes_stream.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/wp_aes_stream.c b/src/wp_aes_stream.c index 873bc125..38c9f29a 100644 --- a/src/wp_aes_stream.c +++ b/src/wp_aes_stream.c @@ -590,6 +590,13 @@ static int wp_aes_stream_doit(wp_AesStreamCtx *ctx, unsigned char *out, if (inLen < AES_BLOCK_SIZE) { ok = 0; } + /* The CTS helpers cast the block count to int, so an inLen past + * 0x7FFFFFFF overflows blocks*AES_BLOCK_SIZE. Not reachable via + * EVP_CipherUpdate (its inl is int) - defense in depth for a caller + * driving OSSL_FUNC_cipher_update directly. */ + if (inLen > 0x7FFFFFFFU) { + ok = 0; + } if (ok) { if (ctx->enc) { ok = wp_aes_cts_encrypt(ctx, out, in, inLen);