-
-
Notifications
You must be signed in to change notification settings - Fork 119
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
RawVersion::to_string with CStr, enable WIndows version check #1341
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this pull request, @MartinKavik! It's great to see some attention on Windows support.
Linux and Windows seem to handle strings differently when both expect C-like nul-terminated strings but raw Rust strings are provided.
I don't understand that. What did expect a nul-terminated string before? As far as I can tell, the current code on main
both produces and expects raw Rust strings.
While testing this, I ran into segmentation faults, both on main
and your branch. Here's what I did:
- Install the latest
fj-app
release:cargo install
fj-app` - Go to the repository root.
- Run the test model:
cargo run
Here's what happens on the main branch:
2022-11-13T18:31:49.110410Z WARN fj_host::model: Host version (0.23.0 (unreleased)) and model version (0.23.0 (35a02544a, unreleased)) do not match
at /home/hanno/.cargo/registry/src/github.aaakk.us.kg-1ecc6299db9ec823/fj-host-0.23.0/src/model.rs:139
Segmentation fault (core dumped)
And this happens, if I do the same with your branch:
memory allocation of 140097384091217 bytes failed
Aborted (core dumped)
This is happening on my laptop, and this is the first time since any version checking code was added that I did any testing of this kind there. The version checking code was originally developed on my office PC, and maybe something works differently there. (cargo run
works on my laptop like normal, on both branches.)
I'd like to look into this tomorrow. I'll hold off on making any decisions about this pull request, until we better understand what's going on.
e05972f
to
77df0cc
Compare
I've created another version you can try to run: main...MartinKavik:Fornjot:C-compatible-RawVersion-v2 (tested on Windows 10 & Kubuntu)
I don't really know - I just guess there is a problem when we try to pass the Rust version string through C-compatible API even though it's from Rust to Rust in practice. There is a chance Windows is trying to encode literals in UTF-16 or the old code is counting bytes instead of chars or there is missing FFI patterns for passing/accepting Strings: https://rust-unofficial.github.io/patterns/idioms/ffi/intro.html
Perhaps you already know but for sure:
I've seen it once on my Kubuntu while the Fornjot was starting. It feels a bit random. There is a chance it isn't directly related to Fornjot code, see for instance rust-lang/rust-clippy#8558.
It's a quite popular topic among the MacOS users - see vectordotdev/vector#4196 (comment) |
Thank you! I'll take a look later.
Hmm, I don't know. None of that rings true to me.
Then again, it's obviously not working, so all my reasoning might be wrong. And I certainly appreciate the discussion, so keep the theories coming, if you have more. I do suspect though that the string handling is not the reason for the problem, and that whether it's done using the raw representation of a Rust string, or
Thanks, I'll look into it later! At a first glance, I'm not sure how relevant it is though. It talks about FFI between Rust and C(-compatible) APIs, while here we're only dealing with quasi-FFI between two Rust sides. As I expressed above, there really should be no C-style strings there, at all, unless we explicitly introduce them.
Interesting! I already kinda knew this, but it certainly wasn't at the top of my mind. I'll re-test with
I'm pretty confident it's related to this issue, for the following reasons:
Interesting. I saw the segmentation fault on Linux though (all my machines run Linux), and haven't heard any reports about segmentation faults on macOS. |
Ok, let me know how it went, that version should be the safest one I hope. If it doesn't work, please write me what Linux distribution + version + architecture you use so I can reproduce the problem. |
Will do 👍 Note: "later" had been delayed by a bit. I'm having trouble with the weekly release (due to some updates to the release automation) and will likely not get to anything else today. I should have time tomorrow. |
I wasn't able to reproduce the segmentation faults I was seeing yesterday, but I got this (on my office PC running Arch Linux): This isn't an error message that got mangled into the output somehow. It's the actual contents of the version string. I suspect that the About the Regardless of this finding, I have decided not to merge this pull request without strong justification. Using While doing my testing and research, I came across a potential soundness hole which I've fixed in #1358. That may have been the problem we've been seeing on Windows, but I don't know. The pull request is also reducing the number of moving parts overall, so if you have some time, I'd appreciate if you could try it. Closing, as I don't believe this is the right approach, for the aforementioned reasons. But still, thanks a lot for looking into this, @MartinKavik! At the very least, you provided the motivation for me to look into this again. I doubt I would have seen this soundness hole, if I your code hadn't made me think about this in new ways. |
Fixes #1307
Linux and Windows seem to handle strings differently when both expect C-like nul-terminated strings but raw Rust strings are provided.
The code in the PR tested with
cargo run
on Windows 10 and Kubuntu 22.04.I was trying to do as few changes as possible but there are some potential improvements like:
or to create
C_VERSION_PKG
lazily fromVERSION_PKG
.