From c1fe2af601e5e0c34ad67d05844760950956d1bc Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Thu, 9 Apr 2026 23:16:48 +0200 Subject: [PATCH] Reject impossible lengths in crypto_box --- src/libsodium/crypto_box/crypto_box_seal.c | 3 +++ .../box_seal_curve25519xchacha20poly1305.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/libsodium/crypto_box/crypto_box_seal.c b/src/libsodium/crypto_box/crypto_box_seal.c index 9a677d00..f53ac369 100644 --- a/src/libsodium/crypto_box/crypto_box_seal.c +++ b/src/libsodium/crypto_box/crypto_box_seal.c @@ -29,6 +29,9 @@ crypto_box_seal(unsigned char *c, const unsigned char *m, unsigned char esk[crypto_box_SECRETKEYBYTES]; int ret; + if (mlen > crypto_box_MESSAGEBYTES_MAX) { + sodium_misuse(); /* LCOV_EXCL_LINE */ + } if (crypto_box_keypair(epk, esk) != 0) { return -1; /* LCOV_EXCL_LINE */ } diff --git a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c index 0b63431b..0e2593d7 100644 --- a/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c +++ b/src/libsodium/crypto_box/curve25519xchacha20poly1305/box_seal_curve25519xchacha20poly1305.c @@ -35,6 +35,9 @@ crypto_box_curve25519xchacha20poly1305_seal(unsigned char *c, const unsigned cha unsigned char esk[crypto_box_curve25519xchacha20poly1305_SECRETKEYBYTES]; int ret; + if (mlen > crypto_box_curve25519xchacha20poly1305_MESSAGEBYTES_MAX) { + sodium_misuse(); /* LCOV_EXCL_LINE */ + } if (crypto_box_curve25519xchacha20poly1305_keypair(epk, esk) != 0) { return -1; /* LCOV_EXCL_LINE */ }