Closed
Description
The utimensat function of NODERAWFS sets wrong atime and mtime. The issue looks like an overflow problem to me.
Update 1 It's a factor 1000 issue.
Update 2 The utimensat
handler is also missing a check for times == NULL
. Value 0
indicates that the OS should set mtime and atime to current time (NOW).
Version of emscripten/emsdk:
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.7 (48a16209b1a0de5efd8112ce6430415730008d18)
clang version 15.0.0 (https://github.com/llvm/llvm-project fbce4a78035c32792b0a13cf1f169048b822c06b)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /emsdk/upstream/bin
Reproducer
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define PATH "utime.test"
#define TS 1646823705
int main(void) {
int fd = open(PATH, O_RDWR | O_CREAT, 0644);
close(fd);
struct timespec times[2];
times[0].tv_sec = TS;
times[0].tv_nsec = 0;
times[1].tv_sec = times[0].tv_sec;
times[1].tv_nsec = times[0].tv_nsec;
utimensat(AT_FDCWD, PATH, times, 0);
struct stat st;
stat(PATH, &st);
fprintf(stdout, "mtime: %li, atime: %li\n", st.st_mtime, st.st_atime);
return 0;
}
$ gcc -outime utime.c && ./utime && stat utime.test
mtime: 1646823705, atime: 1646823705
File: utime.test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 8942735 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2022-03-09 11:01:45.000000000 +0000
Modify: 2022-03-09 11:01:45.000000000 +0000
Change: 2022-03-09 11:17:03.726773876 +0000
Birth: -
$ emcc -s NODERAWFS -o utime.js utime.c && node utime.js && stat utime.test
mtime: 2147483647, atime: 2147483647
File: utime.test
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd03h/64771d Inode: 8942735 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2446-05-10 22:38:55.000000000 +0000
Modify: 2446-05-10 22:38:55.000000000 +0000
Change: 2022-03-09 11:17:35.650125660 +0000
Birth: -
Please note the difference between stat()
call and stat command output. The stat command returns year 2446. The timestamp 2147483647
is the beginning of the epochalypse. It appears that Emscripten NODERAWFS is not 2038-safe yet, but that is a different issue.
Metadata
Metadata
Assignees
Labels
No labels