From 6d84a6c050486d90f915d3f953cacf2620f502aa Mon Sep 17 00:00:00 2001 From: Benalleng Date: Tue, 25 Aug 2026 13:55:41 -0400 Subject: [PATCH] Ensure receiver properly handles junk responses to mailbox Before this check any response that fell outside the size range could cause an overflow and crash the receiver's program. This is limited to anyone who knew the receiver's pk for a sesssion. --- payjoin/src/core/hpke.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/payjoin/src/core/hpke.rs b/payjoin/src/core/hpke.rs index a66f73140..abf28053d 100644 --- a/payjoin/src/core/hpke.rs +++ b/payjoin/src/core/hpke.rs @@ -200,9 +200,9 @@ pub fn decrypt_message_a( cursor.read_to_end(&mut ciphertext).map_err(|_| HpkeError::PayloadTooShort)?; let plaintext = decryption_ctx.open(&ciphertext, &[])?; - let reply_pk = pubkey_from_compressed_bytes(&plaintext[..PUBLIC_KEY_SIZE])?; - - let body = &plaintext[PUBLIC_KEY_SIZE..]; + let (reply_pk_bytes, body) = + plaintext.split_at_checked(PUBLIC_KEY_SIZE).ok_or(HpkeError::PayloadTooShort)?; + let reply_pk = pubkey_from_compressed_bytes(reply_pk_bytes)?; Ok((body.to_vec(), reply_pk)) }