Zion Boggan zionboggan.com ↗

Fix 32-bit usize overflow in MAX_CIPHERTEXT_BYTES (#4)

The literal 4 * 1024 * 1024 * 1024 overflows usize on 32-bit targets,
causing const-evaluation to fail at compile time and blocking 32-bit
Android (armv7, i686) and 32-bit iOS builds.

Gate the 4 GiB value to 64-bit targets only; on 32-bit fall back to
usize::MAX (which is just under 4 GiB anyway, so behavior is preserved
in practice - the cap stays larger than any realistic bundle).

Found while bringing up the Oversight mobile verifier app. With this
fix the protocol crates compile clean for all 4 Android ABIs.
ab45aca   Z committed on Apr 26, 2026 (1 month ago)
oversight-rust/oversight-container/src/lib.rs +6 -0
@@ -31,7 +31,13 @@ pub const SUITE_HYBRID_V1_ID: u8 = 2;
// Hard caps to prevent DoS via attacker-controlled length fields.
pub const MAX_MANIFEST_BYTES: usize = 4 * 1024 * 1024;
pub const MAX_WRAPPED_DEK_BYTES: usize = 1 * 1024 * 1024;
+// 4 GiB on 64-bit; usize::MAX on 32-bit (which is just under 4 GiB anyway).
+// The literal `4 * 1024 * 1024 * 1024` overflows on 32-bit targets, blocking
+// 32-bit Android / iOS builds at const-eval time.
+#[cfg(target_pointer_width = "64")]
pub const MAX_CIPHERTEXT_BYTES: usize = 4 * 1024 * 1024 * 1024;
+#[cfg(not(target_pointer_width = "64"))]
+pub const MAX_CIPHERTEXT_BYTES: usize = usize::MAX;
#[derive(Debug, Error)]
pub enum ContainerError {