Skip to content

utimes precision errors #13255

Closed
Closed
@jorangreef

Description

@jorangreef

Version: v7.10.0
Platform: Windows 10 64-bit
Subsystem: fs

I was working on a fuzz test to test the accuracy of timestamps set using fs.utimes() and found the following two precision bugs on Windows:

NEGATIVE MTIME:
expect mtime=2159345162531
actual mtime=-2135622133469

INACCURATE MTIME:
expect mtime=1713037251360
actual mtime=1713037251359

Here's the gist to reproduce (on a Windows fs with support for at least millisecond timestamps):

var fs = require('fs');
var path = 'test-utimes-precision';
fs.writeFileSync(path, '');

console.log('\r\nNEGATIVE MTIME:');
var mtime = 2159345162531;
fs.utimesSync(path, mtime / 1000, mtime / 1000);
var stats = fs.statSync(path);
console.log('expect mtime=' + mtime);                 // 2159345162531
console.log('actual mtime=' + stats.mtime.getTime()); // -2135622133469

console.log('\r\nINACCURATE MTIME:');
var mtime = 1713037251360;
fs.utimesSync(path, mtime / 1000, mtime / 1000);
var stats = fs.statSync(path);
console.log('expect mtime=' + mtime);                 // 1713037251360
console.log('actual mtime=' + stats.mtime.getTime()); // 1713037251359

On Mac, the negative mtime is also an issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    fsIssues and PRs related to the fs subsystem / file system.windowsIssues and PRs related to the Windows platform.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions