Skip to content

Commit def4bbb

Browse files
authored
fix(store-encryption): Remove an unwrap that snuck in (#4506)
1 parent 1dd2b2c commit def4bbb

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

crates/matrix-sdk-store-encryption/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ All notable changes to this project will be documented in this file.
66

77
## [Unreleased] - ReleaseDate
88

9+
### Bug Fixes
10+
11+
- Remove the usage of an unwrap in the `StoreCipher::import_with_key` method.
12+
This could have lead to panics if the second argument was an invalid
13+
`StoreCipher` export.
14+
([#4506](https://github.com/matrix-org/matrix-rust-sdk/pull/4506))
15+
916
## [0.9.0] - 2024-12-18
1017

1118
No notable changes in this release.

crates/matrix-sdk-store-encryption/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl StoreCipher {
334334
/// # anyhow::Ok(()) };
335335
/// ```
336336
pub fn import_with_key(key: &[u8; 32], encrypted: &[u8]) -> Result<Self, Error> {
337-
let encrypted: EncryptedStoreCipher = rmp_serde::from_slice(encrypted).unwrap();
337+
let encrypted: EncryptedStoreCipher = rmp_serde::from_slice(encrypted)?;
338338

339339
if let KdfInfo::Pbkdf2ToChaCha20Poly1305 { .. } = encrypted.kdf_info {
340340
return Err(Error::KdfMismatch);
@@ -903,6 +903,12 @@ mod tests {
903903
Ok(())
904904
}
905905

906+
#[test]
907+
fn test_importing_invalid_store_cipher_does_not_panic() {
908+
// This used to panic, we're testing that we're getting a real error.
909+
assert!(StoreCipher::import_with_key(&[0; 32], &[0; 64]).is_err())
910+
}
911+
906912
#[test]
907913
fn encrypting_values() -> Result<(), Error> {
908914
let event = json!({

0 commit comments

Comments
 (0)