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

Memory corruption in 0.9.3 #71

Closed
kbarros opened this issue Jan 23, 2024 · 3 comments
Closed

Memory corruption in 0.9.3 #71

kbarros opened this issue Jan 23, 2024 · 3 comments

Comments

@kbarros
Copy link

kbarros commented Jan 23, 2024

We have noticed intermittent crashes since upgrading from Spglib 0.9.2 to 0.9.3. Looks like the only real difference between these versions is the switch from enums to SumTypes: singularitti/Spglib.jl@819b7f6.

Perhaps there is memory corruption when reading an spglib_jll response into a sum type?

Frequently the result is a segfault, but here is one stacktrace we got that seems interpretable:

Failed to precompile Sunny [2b4a2ac8-8f8b-43e8-abf4-3cb0c45e8736] to "/home/runner/.julia/compiled/v1.9/Sunny/jl_GxA1Pq".
ERROR: LoadError: ArgumentError: cannot convert NULL to string
Stacktrace:
  [1] unsafe_string
    @ ./strings/string.jl:84 [inlined]
  [2] unsafe_string
    @ ./c.jl:193 [inlined]
  [3] get_error_message(code::Spglib.SpglibReturnCode)
    @ Spglib ~/.julia/packages/Spglib/rGUIW/src/error.jl:37
  [4] check_error
    @ ~/.julia/packages/Spglib/rGUIW/src/error.jl:50 [inlined]
  [5] get_spacegroup_type(hall_number::Int64)
    @ Spglib ~/.julia/packages/Spglib/rGUIW/src/symmetry.jl:291
  [...]

This appeared on our Github actions CI with Julia 1.9.4, Ubuntu, x86. Full trace here: https://github.com/SunnySuite/Sunny.jl/actions/runs/7629267203/job/20782289111?pr=217

I haven't seen the crashes yet on my Mac. On Linux/x86, reproducing might be as simple as ] add Sunny#spglib_crash and then using Sunny.

@MasonProtter
Copy link
Owner

This isn't a bug with SumTypes, it's just being used in a completely invalid way by that library. It's asserting to julia that it can interpret the return type from a ccall as a sum type, which encloses a union, so yeah that's almost guaranteed to cause memory corruption.

I would raise an issue in that library instead.

@MasonProtter MasonProtter closed this as not planned Won't fix, can't repro, duplicate, stale Jan 23, 2024
@kbarros
Copy link
Author

kbarros commented Jan 23, 2024

Thank you @MasonProtter. My mistake, I meant to file this issue in the Spglib repo, but your input is valuable, thanks.

@MasonProtter
Copy link
Owner

Not a problem, happy I could help diagnose.

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

No branches or pull requests

2 participants