From fc272f6c0d85779cff67c928c798ef68f532923e Mon Sep 17 00:00:00 2001 From: Steven Eck <77412505+StevenEck@users.noreply.github.com> Date: Tue, 8 Jul 2025 21:26:17 -0700 Subject: [PATCH] Fix integer overflow vulnerability in pkcs1_decode.c (#883) This commit fixes an integer overflow vulnerability in the pkcs1_decode function. Previously, the code was incrementing the position value returned by safe_search before checking if it was SIZE_T_MAX (error condition). This could lead to an overflow when adding 10 to SIZE_T_MAX, causing the subsequent error check to fail. The fix ensures we check for the error condition before performing the addition, preventing the potential overflow vulnerability. Fixes #883 --- src/pkcs1_decode.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pkcs1_decode.c b/src/pkcs1_decode.c index 5bf3a5ed..dd246d39 100644 --- a/src/pkcs1_decode.c +++ b/src/pkcs1_decode.c @@ -252,11 +252,12 @@ EXPORT_SYM int pkcs1_decode(const uint8_t *em, size_t len_em_output, * It can be len_em_output when the 0 is not present. * It can SIZE_T_MAX in case of other errors. */ - pos = safe_search(em + 10, 0, len_em_output - 10) + 10; + pos = safe_search(em + 10, 0, len_em_output - 10); if (pos == SIZE_T_MAX) { result = -1; goto end; } + pos += 10; /* * selector is 0 if: