Skip to content

[Rust] Return None from Project::query_metadata for a missing key - #8737

Open
jrozner wants to merge 1 commit into
Vector35:devfrom
jrozner:rust-project-query-metadata-option
Open

jrozner wants to merge 1 commit into
Vector35:devfrom
jrozner:rust-project-query-metadata-option

Conversation

@jrozner

@jrozner jrozner commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Problem

Project::query_metadata passes the result of BNProjectQueryMetadata straight to Metadata::ref_from_raw. The core returns null when nothing is stored under the key, so the caller gets a Ref<Metadata> with a null handle. That trips the debug_assert in debug builds, and in release builds any use of the value dereferences null. The Rust bindings give no way to ask whether a key exists, so reading a key that may not be set can't be done safely. The Python binding handles this case: query_metadata raises KeyError and get_metadata returns its default.

Change

Project::query_metadata now returns Option<Ref<Metadata>>, and None when the core returns null. That matches BinaryView, Function, TypeLibrary and TypeArchive, whose query_metadata already return Option. This changes the method's signature, so callers need to handle the Option. Nothing else in this repository calls it except rust/tests/project.rs, which is updated.

Testing

rust/tests/project.rs now unwraps the result where the key is set. It also checks that query_metadata returns None right after remove_metadata, which would have crashed before. cargo test --test project passes (3 tests), and cargo fmt is clean on the changed files.

BNProjectQueryMetadata returns null when nothing is stored under the
key, and wrapping that in a Ref made any later use of the metadata
dereference null. Return an Option, as BinaryView, Function, TypeLibrary
and TypeArchive already do.
@emesare emesare added the Ready for Review PR is ready for internal review/merging label Nov 30, 2026
@emesare emesare self-assigned this Nov 30, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for Review PR is ready for internal review/merging

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants