Skip to content

Commit

Permalink
chore: add thread sanitizer and add ub notes
Browse files Browse the repository at this point in the history
  • Loading branch information
liuq19 committed Feb 11, 2025
1 parent 0dca8a0 commit 1f26ece
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
strategy:
fail-fast: false
matrix:
san: [address, leak]
san: ["address,leak", thread]
feature: ["", "arbitrary_precision", "sort_keys", "use_raw", "utf8_lossy"]
name: Sanitize ${{matrix.san}} feature ${{matrix.feature}}
runs-on: [self-hosted, Linux, amd64]
Expand Down
15 changes: 13 additions & 2 deletions src/value/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,19 @@ use crate::{
///
/// # Notes
///
/// Actually the lookup in `Value` is O(n), not O(1). If you want to use `Value` as a map, recommend
/// to use `serde_json::Value`.
/// Not use any unsafe invalid_reference_casting for `Value`, it will cause UB.
///
/// ```rust,no_run
/// use sonic_rs::{from_str, Value};
/// let json = r#"["a", "b", "c"]"#;
/// let root: Value = from_str(json).unwrap();
/// let immref = &root["b"];
///
/// // This is dangerous, will coredump when using sanitizer
/// #[allow(invalid_reference_casting)]
/// let ub_cast = unsafe { &mut *(immref as *const _ as *mut Value) };
/// let _ub = std::mem::take(ub_cast);
/// ```
#[repr(C)]
pub struct Value {
pub(crate) meta: Meta,
Expand Down

0 comments on commit 1f26ece

Please sign in to comment.