Skip to content

[Bug] debug_assert!(false) in error handling paths contradicts Result return types #1998

Closed

Description

@silmil97

Description

OpenMLS contains several debug_assert!(false, ...) calls inside .map_err() closures and error-handling branches. These cause panics in debug builds even though the surrounding code correctly converts errors to proper Result return types.

The most impactful instances for downstream consumers:

1. src/framing/private_message_in.rs:129 — AEAD decryption failure

.map_err(|_| {
    log::error!("  Ciphertext decryption error");
    debug_assert!(false, "Ciphertext decryption failed");
    MessageDecryptionError::AeadError
})?;

2. group/mls_group/creation.rs:429 — Welcome confirmation tag mismatch

debug_assert!(false, "Confirmation tag mismatch");
// ...
return Err(WelcomeError::ConfirmationTagMismatch);

Both correctly return errors in release mode but panic in debug mode, causing test-mode divergence for any consumer that tests error handling with corrupted/tampered MLS messages.

Impact

  • Downstream crates must gate decrypt-failure tests with #[cfg(not(debug_assertions))], splitting test suites between debug and release modes
  • The panics contradict the functions' Result<..., Error> return signatures
  • OpenMLS's own test_valsem006 expects AeadError (not panic), suggesting these assertions are unintentional artifacts

Reproduction

Both panics can be triggered in a debug build (cargo test, not --release):

Decrypt panic (private_message_in.rs:129):

  1. Create group with two members (alice, bob)
  2. alice encrypts an application message
  3. XOR last byte of ciphertext
  4. bob calls process_message() → panics instead of Err

Welcome panic (creation.rs:429):

  1. alice creates a group and generates a Welcome for bob
  2. Modify any byte in the Welcome's encrypted group secrets region
  3. bob calls MlsGroup::new_from_welcome() → panics instead of Err

Suggested Fix (three options)

  1. Remove the debug_assert! calls — The error handling is already correct. The log::error!() calls provide sufficient diagnostic visibility.

  2. Replace with log::warn! — If the intent was diagnostic logging rather than hard assertion, downgrade to a warning log that doesn't affect control flow.

  3. Gate behind a feature flag — Add a strict-debug-asserts feature (default off) for consumers who want panics during development:

#[cfg(feature = "strict-debug-asserts")]
debug_assert!(false, "Ciphertext decryption failed");

Environment

  • Verified in both openmls 0.6.0 and 0.8.1 (main branch at time of writing)
  • Rust: 1.94.1
  • 6 instances of debug_assert!(false) found in the codebase; 2 are in error-handling paths reachable by external input (listed above), 4 are internal invariant checks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions