Panic in trie operation logic – Assertion Failure in `nibbleslice.rs:120:9`
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia con il test di riproduzione nell’issue e ispeziona l’assertion in nibble/nibbleslice.rs:120:9, concentrandoti sull’operazione che fallisce con una chiave inesistente usando NoExtensionLayout. Segui l’operazione del trie che raggiunge questa assertion e aggiungi un test di regressione; il lavoro è completato quando lo scenario fornito termina senza panic.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
Performing specific operations on TrieDBMut with a custom trie layout that uses nibbles (NoExtensionLayout) causes a panic. The issue occurs when attempting to remove non-existent key, triggering an assertion failure in nibble/nibbleslice.rs:120:9.
Code to Reproduce
/// This module contains test to showcase issue with trie
#[cfg(test)]
mod tests {
use memory_db::{HashKey, MemoryDB};
use reference_trie::{RefHasher, ReferenceNodeCodecNoExt};
use trie_db::{TrieDBMutBuilder, TrieLayout, TrieMut};
/// Custom Trie layout that does not use extensions.
#[derive(Default)]
pub struct NoExtensionLayout;
impl TrieLayout for NoExtensionLayout {
const USE_EXTENSION: bool = false;
const ALLOW_EMPTY: bool = false;
const MAX_INLINE_VALUE: Option<u32> = None;
type Hash = RefHasher;
type Codec = ReferenceNodeCodecNoExt<RefHasher>;
}
/// Reproduces panic issue in trie
/// The panic occurs due to an assertion failure in `nibble/nibbleslice.rs:120:9`
///
/// #### Related Error Message:
/// ```
/// assertion failed: self.len() >= i
/// ```
#[test]
fn test_trie_panic() -> Result<(), Box<dyn std::error::Error>> {
let pairs = [
(hex::decode("ffff")?, hex::decode("0a")?),
(hex::decode("feffe9")?, hex::decode("0b")?),
(hex::decode("ffffff")?, hex::decode("0c")?),
(hex::decode("ff")?, hex::decode("")?), // Removal of non-existent key triggers panic
];
let mut memdb = MemoryDB::<_, HashKey<_>, _>::default();
let mut root = Default::default();
let mut trie = TrieDBMutBuilder::<NoExtensionLayout>::new(&mut memdb, &mut root).build();
for (key, value) in &pairs {
trie.insert(key, value)?;
}
Ok(())
}
}
Cargo.toml
[package]
name = "trie_panic"
version = "0.1.0"
edition = "2021"
[dependencies]
hex = "0.4.3"
memory-db = "0.32.0"
reference-trie = "0.29.1"
trie-db = "0.27.0" # Using this version to match the older trie-db version used by reference-trie.
Expected Behavior
The trie should handle this scenario gracefully without triggering a panic.
Actual Behavior
The test fails with a panic at /trie-db-0.27.1/src/nibble/nibbleslice.rs:120:9, resulting in the following assertion error:
`assertion failed: self.len() >= i`
Additional Information
This issue has also been tested with the latest trie-db version (0.29.1), and the behavior remains the same
- Lingua principale
- Rust
- Stelle
- 274
- Fork
- 72
- Merge medio
- 2g 4h
- PR unite (30g)
- 7
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di paritytech/trie
-
`NodeOwned::size_in_bytes` does not count the `ChildrenNodesOwned` heap allocation (since #216)Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
paritytech/trie#251 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
paritytech/trie#228 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
paritytech/trie#220 · 2 reazioni ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
paritytech/trie#207 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
paritytech/trie#182 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di paritytech/trie
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
antiguru/interrexx#213 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
bug CLI
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
HigherOrderCO/Bend#2120 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
KNXBench-Labs/KNXBench#47 ·