Rust codegen: Empty interned strings cause a null pointer dereference in valdi_rust_value_ref_get_string

Open Beginner friendly
#236 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
84/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
cpp, rust

Research direction

Start in valdi_core/src/valdi_core/cpp/Marshalling/RustValdi.cpp at valdi_rust_value_ref_get_string and inspect the isInternedString() branch. Reproduce the null pointer path with an empty interned string, then add the null check and empty-slice fallback described in the issue. Done when empty strings no longer crash and the existing Rust string conversion behavior remains intact.

Written by the indexing model from the issue text.

Description

Found while reviewing https://github.com/Snapchat/Valdi/pull/211 (native Rust code generation). Not blocking that PR.

Empty interned strings cause a null pointer dereference in valdi_rust_value_ref_get_string

File: valdi_core/src/valdi_core/cpp/Marshalling/RustValdi.cpp

Reading an empty interned string from Rust (such as "" passed from TypeScript or constructed via Value::from_string("")) crashes the process with a null pointer dereference. The crash starts in valdi_rust_value_ref_get_string inside the isInternedString() branch when string->toStringView() is called.

Because StringCache::makeString represents an empty string as a default StringBox with no InternedStringImpl allocation, Value stores _isShared = false and a null pointer while still setting ValueType::InternedString. Calling getTypedRef<Valdi::InternedStringImpl>() returns nullptr, so dereferencing string on the next line segfaults.

Check string != nullptr before calling string->toStringView(), falling back to Valdi::makeRustSlice("").

Dominant language
C++
Stars
16.4k
Forks
539
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Snapchat/Valdi

All issues in Snapchat/Valdi

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.