Join GitHub today
sys::unix::fs::canonicalize can lead to undefined-ish behavior on Android #58862
Its code is:
The problem comes from the pair of calls
Now, funky things are funky. Say you have a binary that makes
Yes, there is
https://bugzilla.mozilla.org/show_bug.cgi?id=1531887 is a real issue that results from this, although it doesn't involve
For this particular case, it's possible to pass an appropriately-sized buffer to realpath instead of
FWIW, I pulled libc.so from my android phone, and its
As far as I understand this issue is not about
Or are you saying that using the
I suppose this raises the question: does the C code in Firefox carefully avoid doing things like this?
I don't know if it can be considered a bug in jemalloc, since there may simply be nothing it can do. Nor in bionic, since I don't think anything in the C standard (or probably other standards) would imply it's possible to replace the allocator this way.
Someone more familar with jemalloc and linker wizardry might have a better idea, but perhaps the conclusion is just that it's wrong to use an alternate
Searching for "jemalloc Android", apparently since Android 7, jemalloc is actually used by default.
One thing that comes to mind: wouldn't it in principle be possible to use an allocator like jemalloc for allocation in Rust without overriding
Right. But only in some configurations. Firefox has an even weirder configuration than the cases where it might happen without all the Firefox weirdness.
And it is, to some extent, but there's also no escape hatch provided by rust.
It's possible, but that wouldn't solve the problem, because the it's not a problem with rust allocations. It's a problem with rust libstd deallocation of a buffer that was allocated by libc. At least it's using libc::free, and not rust's allocator, which would be another layer of problems.
One part of the problem is that all this is statically linked, and linkers don't allow to redirect symbols differently depending on where they're used from. And even if I were to locally modify the libc crate so that its free does something else, that wouldn't change what libstd uses.