Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

panic with empty buffer as argument: NonNull::new_unchecked requires that the pointer is non-null #2085

Closed
mischnic opened this issue May 5, 2024 · 2 comments · Fixed by #2094

Comments

@mischnic
Copy link
Contributor

mischnic commented May 5, 2024

In this example, passing a zero-size buffer causes a panic (non-empty buffers work fine).
I suspect this is a regression between 2.12.6 and 2.16.4 when upgrading napi-rs in Parcel.

Reproduction (not sure if actually minimal, maybe serde isn't necessary): https://github.com/mischnic/napi-issue-buffer-crash
This is with Node 20

   0: rust_begin_unwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/std/src/panicking.rs:645:5
   1: core::panicking::panic_nounwind_fmt::runtime
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:110:18
   2: core::panicking::panic_nounwind_fmt
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:123:9
   3: core::panicking::panic_nounwind
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/panicking.rs:156:5
   4: core::ptr::non_null::NonNull<T>::new_unchecked::precondition_check
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/intrinsics.rs:2799:21
   5: core::ptr::non_null::NonNull<T>::new_unchecked
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ptr/non_null.rs:220:13
   6: core::ptr::unique::Unique<T>::new_unchecked
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/ptr/unique.rs:89:36
   7: alloc::raw_vec::RawVec<T,A>::from_raw_parts_in
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/raw_vec.rs:250:30
   8: alloc::vec::Vec<T,A>::from_raw_parts_in
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/vec/mod.rs:820:29
   9: alloc::vec::Vec<T>::from_raw_parts
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/alloc/src/vec/mod.rs:604:18
  10: napi::js_values::buffer::JsBufferValue::from_raw
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/napi-2.16.4/src/js_values/buffer.rs:74:45
  11: <&mut napi::js_values::de::De as serde::de::Deserializer>::deserialize_byte_buf
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/napi-2.16.4/src/js_values/de.rs:89:26
  12: <serde_bytes::bytebuf::ByteBuf as serde::de::Deserialize>::deserialize
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_bytes-0.11.14/src/bytebuf.rs:251:9
  13: <serde_bytes::bytebuf::ByteBuf as serde_bytes::de::Deserialize>::deserialize
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_bytes-0.11.14/src/de.rs:113:9
  14: <alloc::vec::Vec<u8> as serde_bytes::de::Deserialize>::deserialize
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_bytes-0.11.14/src/de.rs:52:9
  15: serde_bytes::deserialize
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde_bytes-0.11.14/src/lib.rs:121:5
  16: <<napi_buffer_crash::_::<impl serde::de::Deserialize for napi_buffer_crash::Config>::deserialize::__Visitor as serde::de::Visitor>::visit_map::__DeserializeWith as serde::de::Deserialize>::deserialize
             at ./src/lib.rs:6:28
  17: <core::marker::PhantomData<T> as serde::de::DeserializeSeed>::deserialize
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.200/src/de/mod.rs:794:9
  18: <napi::js_values::de::JsObjectAccess as serde::de::MapAccess>::next_value_seed
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/napi-2.16.4/src/js_values/de.rs:365:15
  19: serde::de::MapAccess::next_value
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.200/src/de/mod.rs:1867:9
  20: <&mut A as serde::de::MapAccess>::next_value
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.200/src/de/mod.rs:1948:9
  21: <napi_buffer_crash::_::<impl serde::de::Deserialize for napi_buffer_crash::Config>::deserialize::__Visitor as serde::de::Visitor>::visit_map
             at ./src/lib.rs:6:28
  22: <&mut napi::js_values::de::De as serde::de::Deserializer>::deserialize_any
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/napi-2.16.4/src/js_values/de.rs:53:11
  23: <&mut napi::js_values::de::De as serde::de::Deserializer>::deserialize_struct
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/serde-1.0.200/src/macros.rs:133:13
  24: napi_buffer_crash::_::<impl serde::de::Deserialize for napi_buffer_crash::Config>::deserialize
             at ./src/lib.rs:6:28
  25: napi::env::Env::from_js_value
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/napi-2.16.4/src/env.rs:1336:5
  26: napi_buffer_crash::transform
             at ./src/lib.rs:15:26
  27: napi_buffer_crash::__napi__transform::{{closure}}::{{closure}}
             at ./src/lib.rs:13:1
  28: napi::bindgen_prelude::within_runtime_if_available
             at /Users/niklas/.cargo/registry/src/index.crates.io-6f17d22bba15001f/napi-2.16.4/src/lib.rs:162:5
  29: napi_buffer_crash::__napi__transform::{{closure}}
             at ./src/lib.rs:13:1
  30: core::result::Result<T,E>::and_then
             at /rustc/9b00956e56009bab2aa15d7bff10916599e3d6d6/library/core/src/result.rs:1321:22
  31: napi_buffer_crash::__napi__transform
             at ./src/lib.rs:13:1
@mischnic
Copy link
Contributor Author

mischnic commented May 5, 2024

Looks like this will be fixed by #2083

@mischnic mischnic closed this as completed May 6, 2024
@mischnic mischnic reopened this May 6, 2024
@mischnic
Copy link
Contributor Author

mischnic commented May 6, 2024

This is actually still broken, panicing on this line

data: mem::ManuallyDrop::new(unsafe { Vec::from_raw_parts(data as *mut _, len, len) }),

And I suspect there might be even more places

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant