miri icon indicating copy to clipboard operation
miri copied to clipboard

32-bit Linux (glibc): setting file times past 2038 fails because the `__futimens64` shim is missing

Open programskillforverification opened this issue 2 months ago • 4 comments

On 32-bit linux-gnu targets, std looks up the weak symbol __futimens64 (glibc 2.34+) so that File::set_times can use a 64-bit time_t. Miri does not provide that symbol, so std falls back to plain futimens with a 32-bit time_t, and any timestamp after January 2038 is rejected before the shim is even called.

use std::fs::{File, FileTimes};
use std::time::{Duration, SystemTime};

fn main() {
    let path = std::env::temp_dir().join("miri_t2038.txt");
    let file = File::create(&path).unwrap();
    // 3_000_000_000 s after the epoch is in 2065, past the 32-bit `time_t` limit.
    let t = SystemTime::UNIX_EPOCH + Duration::from_secs(3_000_000_000);
    file.set_times(FileTimes::new().set_modified(t)).unwrap();
}

With -Zmiri-disable-isolation --target i686-unknown-linux-gnu this panics with

Error { kind: InvalidInput, message: "timestamp is too large to set as a file time" }

while it passes on x86_64-unknown-linux-gnu. Run natively on i686-unknown-linux-gnu (rustc 1.99.0, glibc 2.41, in a linux/386 container) it also passes, and the modification time reads back as 3000000000.

A fix would be a __futimens64 shim that reads __timespec64 instead of timespec, registered as a weak symbol on Linux. The same applies to __utimensat64, which std uses for fs::set_times / fs::set_times_nofollow, once utimensat is supported (#5181).

Miri has so far largely ignored the 64bit time_t mess on 32bit. I agree it'd be good to support this. I don't know how annoying it will be; I hope a lot of the code can be shared with the existing codepaths.

RalfJung avatar Oct 05 '26 07:10 RalfJung

Related: the SYS_futex_time64 system call isn't handled right now, and when it is, it will need the same "timespec64 instead of timespec" treatment. But since std doesn't currently use SYS_futex_time64 on targets with a 32-bit timespec, this is not especially pressing.

(Originally noted in the discussion of https://github.com/rust-lang/rust/pull/164748)

TechnoPorg avatar Oct 22 '26 17:10 TechnoPorg

@rustbot claim

Kaileshwar16 avatar Oct 31 '26 07:10 Kaileshwar16

@rustbot unclaim

Kaileshwar16 avatar Nov 02 '26 03:11 Kaileshwar16