Skip to content

Blob created by openAsBlob changes contents after chdir #67282

Open

Description

@bakkot

Version

v28.0.0-pre

Platform

Darwin

Subsystem

fs

What steps will reproduce the bug?

fs.openAsBlob('x') in a directory containing a file named x, then process.chdir to a different directory containing such a file with the same same size and same nanoseconds part on its mtime (presumably this is always satisfied on filesystems without high-precision mtimes), then read.

Runnable repro (from Claude):

'use strict';
const fs = require('fs');
const os = require('os');
const path = require('path');

const root = fs.mkdtempSync(path.join(os.tmpdir(), 'blob-bug-'));
const a = path.join(root, 'a');
const b = path.join(root, 'b');
fs.mkdirSync(a);
fs.mkdirSync(b);
fs.writeFileSync(path.join(a, 'x'), 'from-a');
fs.writeFileSync(path.join(b, 'x'), 'from-b');  // Same size as a/x.
const t = 1_700_000_000;
fs.utimesSync(path.join(a, 'x'), t, t);
// Same size, mtime an hour later but tv_nsec still 0.
fs.utimesSync(path.join(b, 'x'), t + 3600, t + 3600);

(async () => {
  process.chdir(a);
  const blob = await fs.openAsBlob('x');
  console.log('before chdir:', await blob.text());  // from-a

  process.chdir(b);

  console.log('after chdir: ', await blob.text());  // from-b

  fs.rmSync(root, { recursive: true });
})();

How often does it reproduce? Is there a required condition?

Always.

What is the expected behavior? Why is that the expected behavior?

Once opened, the blob should not care if you later chdir.

What do you see instead?

It is affected by chdir.

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions