Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element R: error message panicked at src/encryption.rs:118 #26610

Closed
andybalaam opened this issue Nov 20, 2023 · 6 comments
Closed

Element R: error message panicked at src/encryption.rs:118 #26610

andybalaam opened this issue Nov 20, 2023 · 6 comments
Assignees
Labels
A-Element-R Issues affecting the port of Element's crypto layer to Rust O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Impairs non-critical functionality or suitable workarounds exist Z-Element-R-Blocker A blocker for enabling Element R by default Z-Labs

Comments

@andybalaam
Copy link
Contributor

andybalaam commented Nov 20, 2023

Using Element R today I see this in the log:

panicked at src/encryption.rs:118:18:
internal error: entered unreachable code: Unknown variant

Stack:

1391/</module.exports.__wbg_new_abda76e883ba8a5f@https://develop.element.io/bundles/79181f06fa91b4cfd025/37.js:7169:17
@https://develop.element.io/bundles/79181f06fa91b4cfd025/37.js line 7924 > WebAssembly.instantiate:wasm-function[10344]:0x3b0c4a
@https://develop.element.io/bundles/79181f06fa91b4cfd025/37.js line 7924 > WebAssembly.instantiate:wasm-function[1849]:0x26338c
@https://develop.element.io/bundles/79181f06fa91b4cfd025/37.js line 7924 > WebAssembly.instantiate:wasm-function[5745]:0x32e2db
@https://develop.element.io/bundles/79181f06fa91b4cfd025/37.js line 7924 > WebAssembly.instantiate:wasm-function[4244]:0x2fc1be
@https://develop.element.io/bundles/79181f06fa91b4cfd025/37.js line 7924 > WebAssembly.instantiate:wasm-function[4085]:0x2f57eb
get algorithms@https://develop.element.io/bundles/79181f06fa91b4cfd025/37.js:1608:26
rustDeviceToJsDevice@https://develop.element.io/bundles/79181f06fa91b4cfd025/34.js:2147:26
1540/</getUserDevices/<@https://develop.element.io/bundles/79181f06fa91b4cfd025/34.js:573:166
getUserDevices@https://develop.element.io/bundles/79181f06fa91b4cfd025/34.js:573:36

and just before that:

Uncaught (in promise) Error: recursive use of an object detected which would lead to unsafe aliasing in rust
    __wbindgen_throw matrix_sdk_crypto_wasm.js:7830
    free matrix_sdk_crypto_wasm.js:1436
    getUserDevices rust-crypto.ts:515
    getUserDevices rust-crypto.ts:515
    getUserDeviceInfo rust-crypto.ts:471
    shieldStatusForRoom ShieldUtils.ts:59
    updateE2EStatus RoomView.tsx:1525
    RoomView_RoomView RoomView.tsx:1506
    emit events.js:158
    emit typed-event-emitter.ts:89
    forSource ReEmitter.ts:55
    emit events.js:153
    emit typed-event-emitter.ts:89
    onUserIdentityUpdated rust-crypto.ts:1391
    initRustCrypto index.ts:75
    __wbg_call_9495de66fdbe016b matrix_sdk_crypto_wasm.js:7611
    handleError matrix_sdk_crypto_wasm.js:328
    __wbg_call_9495de66fdbe016b matrix_sdk_crypto_wasm.js:7610
    __wbg_adapter_59 matrix_sdk_crypto_wasm.js:274
    real matrix_sdk_crypto_wasm.js:216
    promise callback*1391/</module.exports.__wbg_then_ec5db6d509eb475f matrix_sdk_crypto_wasm.js:7716
    __wbg_adapter_59 matrix_sdk_crypto_wasm.js:274
    real matrix_sdk_crypto_wasm.js:216
    promise callback*1391/</module.exports.__wbg_then_ec5db6d509eb475f matrix_sdk_crypto_wasm.js:7716
    __wbg_adapter_53 matrix_sdk_crypto_wasm.js:266
    real matrix_sdk_crypto_wasm.js:252
    __wbg_setonsuccess_925a7718d3f62bc1 matrix_sdk_crypto_wasm.js:7408
@andybalaam andybalaam added the A-Element-R Issues affecting the port of Element's crypto layer to Rust label Nov 20, 2023
@florianduros florianduros added S-Minor Impairs non-critical functionality or suitable workarounds exist O-Uncommon Most users are unlikely to come across this or unexpected workflow labels Nov 20, 2023
@andybalaam andybalaam changed the title Element R: error meesage panicked at src/encryption.rs:118 Element R: error message panicked at src/encryption.rs:118 Nov 23, 2023
@richvdh
Copy link
Member

richvdh commented Dec 13, 2023

The panic comes from this code:

impl From<matrix_sdk_crypto::types::EventEncryptionAlgorithm> for EncryptionAlgorithm {
    fn from(value: matrix_sdk_crypto::types::EventEncryptionAlgorithm) -> Self {
        use matrix_sdk_crypto::types::EventEncryptionAlgorithm::*;

        match value {
            OlmV1Curve25519AesSha2 => Self::OlmV1Curve25519AesSha2,
            MegolmV1AesSha2 => Self::MegolmV1AesSha2,
            _ => unreachable!("Unknown variant"),
        }
    }
}

... which rather suggests there is a device somewhere that claims to support an algorithm other than m.olm.v1.curve25519-aes-sha2 or m.megolm.v1.aes-sha2. That is of course legitimate and should not cause our application to panic.

The "recursive use of object" error is probably a separate problem

@uhoreg
Copy link
Member

uhoreg commented Jan 12, 2024

AFAICT, since TypeScript doesn't do enums the same way that Rust does, the only way to fix this is to pass around strings on the JS side instead of enums. Is that right?

(I suspect that this bug was triggered by someone trying the MLS POC on their account.)

@richvdh
Copy link
Member

richvdh commented Jan 12, 2024

AFAICT, since TypeScript doesn't do enums the same way that Rust does, the only way to fix this is to pass around strings on the JS side instead of enums. Is that right?

I'm not sure it is. We could add an entry in matrix-sdk-crypto-wasm::encryption::EncryptionAlgorithm for "unrecognised"?

@uhoreg
Copy link
Member

uhoreg commented Jan 13, 2024

I'm not sure it is. We could add an entry in matrix-sdk-crypto-wasm::encryption::EncryptionAlgorithm for "unrecognised"?

I suppose. I guess the JavaScript doesn't care whether devices support algorithms that it doesn't know about.

@richvdh richvdh added the Z-Element-R-Blocker A blocker for enabling Element R by default label Jan 17, 2024
@uhoreg uhoreg self-assigned this Jan 18, 2024
richvdh pushed a commit to matrix-org/matrix-rust-sdk-crypto-wasm that referenced this issue Jan 25, 2024
Related: element-hq/element-web#26610, which will be fixed by this once matrix-js-sdk is updated
@BillCarsonFr
Copy link
Member

Waiting for a new bindings version

@uhoreg
Copy link
Member

uhoreg commented Jan 30, 2024

js-sdk depends on the version of the bindings that has this fixed

@uhoreg uhoreg closed this as completed Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Element-R Issues affecting the port of Element's crypto layer to Rust O-Uncommon Most users are unlikely to come across this or unexpected workflow S-Minor Impairs non-critical functionality or suitable workarounds exist Z-Element-R-Blocker A blocker for enabling Element R by default Z-Labs
Projects
None yet
Development

No branches or pull requests

5 participants