Skip to content

RA Crashes with aes-gcm crate. #13506

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

Closed
dtzxporter opened this issue Oct 28, 2022 · 2 comments
Closed

RA Crashes with aes-gcm crate. #13506

dtzxporter opened this issue Oct 28, 2022 · 2 comments
Labels
A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately S-unactionable Issue requires feedback, design decisions or is blocked on other work

Comments

@dtzxporter
Copy link

rust-analyzer version: (eg. output of "rust-analyzer: Show RA Version" command, accessible in VSCode via Ctrl/⌘+Shift+P)

0.3.1258-standalone (43fb956 2022-10-23)

rustc version: (eg. output of rustc -V)

rustc 1.64.0 (a55dd71d5 2022-09-19)

relevant settings: (eg. client settings, or environment variables like CARGO, RUSTUP_HOME or CARGO_HOME)

Hi All, I had reported a similar crash with tonic (#7817). Which seemed to be infinite recursion.

It looks like this can be triggered with the aes-gcm crate as well.

It's enough to trigger using:

use aes_gcm::aead::Aead;
use aes_gcm::Aes256Gcm;
use aes_gcm::KeyInit;
use aes_gcm::Nonce;

use bincode::config::Config;
use bincode::enc;
use bincode::error::EncodeError;
use bincode::Decode;
use bincode::Encode;

use rand::rngs::OsRng;
use rand::RngCore;

/// Encrypt and encode the given value into a `Vec<u8>` with the key and given `Config`.
pub fn encode_to_vec<E: enc::Encode, C: Config>(
    val: E,
    key: &[u8],
    config: C,
) -> Result<Vec<u8>, EncodeError> {
    let cipher = Aes256Gcm::new_from_slice(key).unwrap();
    let nonce_bytes = generate_nonce();
    let nonce = Nonce::from_slice(&nonce_bytes);

    let bincode_data = bincode::encode_to_vec(val, config)?;
    let ciphertext = cipher.encrypt(nonce, bincode_data.as_ref()).unwrap();

    Ok(bincode::encode_to_vec(
        EncryptedData(nonce_bytes, ciphertext),
        config,
    )?)
}

Callstack (Seems same issue as before, infinite recursion):

   0: std::panicking::begin_panic
   1: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
   2: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
   3: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
   4: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
   5: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
   6: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
   7: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
   8: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
   9: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  10: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  11: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  12: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  13: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  14: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  15: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  16: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  17: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  18: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  19: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  20: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  21: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  22: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  23: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  24: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  25: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  26: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  27: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  28: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  29: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  30: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  31: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  32: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  33: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  34: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  35: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  36: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  37: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  38: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  39: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  40: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  41: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  42: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  43: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  44: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  45: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  46: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  47: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  48: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  49: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  50: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  51: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  52: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  53: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  54: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  55: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  56: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  57: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  58: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  59: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  60: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  61: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  62: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  63: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  64: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  65: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  66: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  67: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  68: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  69: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  70: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  71: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  72: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  73: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  74: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  75: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  76: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  77: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  78: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  79: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  80: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  81: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  82: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  83: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  84: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  85: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  86: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
  87: chalk_recursive::fulfill::Fulfill<I,Solver>::prove
  88: chalk_recursive::fulfill::Fulfill<I,Solver>::solve
  89: chalk_recursive::solve::SolveIterationHelpers::solve_from_clauses
  90: chalk_recursive::recursive::<impl chalk_recursive::fixed_point::SolverStuff<chalk_ir::UCanonical<chalk_ir::InEnvironment<chalk_ir::Goal<I>>>,core::result::Result<chalk_solve::solve::Solution<I>,chalk_ir::NoSolution>> for &dyn chalk_solve::RustIrDatabase<I>>::solve_iteration
  91: chalk_recursive::fixed_point::RecursiveContext<K,V>::solve_goal
@lnicola
Copy link
Member

lnicola commented Oct 31, 2022

Probably a dupe of #13006

@lnicola lnicola added A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately labels Oct 31, 2022
@lnicola
Copy link
Member

lnicola commented Oct 31, 2022

@dtzxporter can you please update your code example with a proper reproduction? I tried the following:

[package]
name = "hello"
version = "0.1.0"
edition = "2021"

[dependencies]
aes-gcm = "0.10.1"
bincode = "2.0.0-rc.2"
rand = "0.8.5"
use aes_gcm::aead::Aead;
use aes_gcm::Aes256Gcm;
use aes_gcm::KeyInit;
use aes_gcm::Nonce;

use bincode::config::Config;
use bincode::enc;
use bincode::error::EncodeError;
use bincode::Decode;
use bincode::Encode;

use rand::rngs::OsRng;
use rand::RngCore;

struct EncryptedData(([u8; 32], Vec<u8>));

/// Encrypt and encode the given value into a `Vec<u8>` with the key and given `Config`.
pub fn encode_to_vec<E: enc::Encode, C: Config>(
    val: E,
    key: &[u8],
    config: C,
) -> Result<Vec<u8>, EncodeError> {
    let cipher = Aes256Gcm::new_from_slice(key).unwrap();
    let nonce_bytes = [0; 32];
    let nonce = Nonce::from_slice(&nonce_bytes);

    let bincode_data = bincode::encode_to_vec(val, config)?;
    let ciphertext = cipher.encrypt(nonce, bincode_data.as_ref()).unwrap();

    Ok(bincode::encode_to_vec(
        EncryptedData((nonce_bytes, ciphertext)),
        config,
    )?)
}

impl Encode for EncryptedData {
    fn encode<E: enc::Encoder>(&self, encoder: &mut E) -> Result<(), EncodeError> {
        todo!()
    }
}

fn main() {}

I don't get a crash in Code, nor in rust-analyzer analysis-stats ..

@lnicola lnicola added the S-unactionable Issue requires feedback, design decisions or is blocked on other work label Oct 31, 2022
@Veykril Veykril closed this as completed Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-ty type system / type inference / traits / method resolution Broken Window Bugs / technical debt to be addressed immediately S-unactionable Issue requires feedback, design decisions or is blocked on other work
Projects
None yet
Development

No branches or pull requests

3 participants