Skip to content

create_triedb_key and create_range_key silently degrade to ([], 0) on truncation #2204

@ogechno

Description

@ogechno

create_triedb_key and create_range_key both silently return (vec![], 0) when key_nibbles.len() exceeds the bounds of the key and gets truncated into num_nibbles.

let num_nibbles: u8 = match key_nibbles.len().try_into() {
	Ok(len) => len,
	Err(_) => {
		warn!("Key too big, returning an empty key");
		return (vec![], 0); <-- returns an empty key
	}
};

This is informational only since the nibble lengths currently stay within those bounds, but it could become a problem in the future. Failing explicitly rather than silently degrading would make this easier to catch early. One possible mitigation is to explicitly return an Error instead of the empty key.

key.rs#L148-L202
triedb_env.rs#L1075-L1103

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions