Skip to content

fix: respect 'bigint' option for lstat(Sync) for asar wrapper#47505

Closed
panther7 wants to merge 1 commit intoelectron:mainfrom
panther7:fix-bigint-asar-wrapper
Closed

fix: respect 'bigint' option for lstat(Sync) for asar wrapper#47505
panther7 wants to merge 1 commit intoelectron:mainfrom
panther7:fix-bigint-asar-wrapper

Conversation

@panther7
Copy link
Copy Markdown
Contributor

@panther7 panther7 commented Jun 19, 2025

Description of Change

Fixed an issue where lstat option 'bigint' was ignored.

Issue discover via get-folder-size module. PR

Checklist

Release Notes

Notes: Fixed an issue where lstat option 'bigint' was ignored.

@electron-cation electron-cation Bot added the new-pr 🌱 PR opened recently label Jun 19, 2025
Copy link
Copy Markdown
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I'd like a test to verify this works as intended - you'll want to add one here and here.

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 16cfd65 to 913540e Compare June 19, 2025 16:07
@panther7
Copy link
Copy Markdown
Contributor Author

@codebytere done

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 913540e to d4e8640 Compare June 19, 2025 16:11
@panther7 panther7 changed the title fix: respect 'bigint' option for stat/lstat for asar wrapper fix: respect 'bigint' option for lstat(Sync) for asar wrapper Jun 19, 2025
@panther7
Copy link
Copy Markdown
Contributor Author

panther7 commented Jun 20, 2025

Btw, why asar file returns always size "0"?

Because, if i call native fs.lstat, will be returned correct size, ino, etc.

fs.lstat('app.asar', console.log)
> null Stats {
  dev: 0,
  mode: 33206,
  nlink: 1,
  uid: 0,
  gid: 0,
  rdev: 0,
  blksize: 4096,
  ino: 7881299348490233,
  size: 132247133,
  blocks: 258296,
  atimeMs: 1750337668594.9424,
  mtimeMs: 1750337664266.7073,
  ctimeMs: 1750337664266.7073,
  birthtimeMs: 1750337663840.4016
}

#47505 (comment)

https://www.electronjs.org/docs/latest/tutorial/asar-archives#fake-stat-information-of-fsstat

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch 2 times, most recently from 136e21b to 572b7ec Compare June 20, 2025 06:57
Comment thread lib/node/asar-fs-wrapper.ts Outdated
}

return asarStatsToFsStats(stats);
return asarStatsToFsStats(stats, options);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question is, why it not used native lstat for compute values, like:

Suggested change
return asarStatsToFsStats(stats, options);
return lstat(pathArgument, options, callback);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarshallOfSound i think you probably have the most context here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, hotfix:

    if (stats.size === 0) {
      stats.size = lstatSync(filePath, options).size;
    }

Comment thread lib/node/asar-fs-wrapper.ts
@panther7
Copy link
Copy Markdown
Contributor Author

Any progress with this?

@codebytere
Copy link
Copy Markdown
Member

@panther7 we're down a few maintainers due to illness at the moment. Please be patient. This PR will be reviewed as bandwidth permits.

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 16fd533 to 910fef9 Compare June 24, 2025 12:05
@electron-cation electron-cation Bot removed the new-pr 🌱 PR opened recently label Jun 26, 2025
@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 910fef9 to 7616764 Compare July 7, 2025 19:21
@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 7616764 to f698bae Compare July 17, 2025 12:21
@panther7
Copy link
Copy Markdown
Contributor Author

Another month has out, can I help with it some progress?

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch 2 times, most recently from 94a0dba to 84effcd Compare July 30, 2025 13:11
@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 84effcd to 0813071 Compare August 16, 2025 07:36
@panther7
Copy link
Copy Markdown
Contributor Author

Next month out.

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 0813071 to 400748b Compare August 27, 2025 06:24
@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch 2 times, most recently from 478b3d8 to c8ad46c Compare September 17, 2025 18:59
@panther7
Copy link
Copy Markdown
Contributor Author

panther7 commented Sep 25, 2025

Three months of being ignoring. What can i do for move this PR to merge?

@codebytere

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from c8ad46c to 5ea083d Compare September 25, 2025 08:34
@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch 2 times, most recently from 7f8dd6a to b5a6478 Compare October 17, 2025 19:39
@panther7
Copy link
Copy Markdown
Contributor Author

Ok, this can't works, becase return object must be a type BigIntStats (if bigint is sets to true).
BigIntStats hasn't constructor.
This "asar" hack is bad solution.

@jkleinsc
Copy link
Copy Markdown
Member

Ok, this can't works, becase return object must be a type BigIntStats (if bigint is sets to true).
BigIntStats hasn't constructor.
This "asar" hack is bad solution.

@panther7 can you clarify what you mean here? Are you saying your currently proposed change won't work?

@panther7
Copy link
Copy Markdown
Contributor Author

panther7 commented Oct 23, 2025

@jkleinsc

Yes, it won't work because the fs.stat method with the parameter bigint = true must return a BigIntStats object, which is not possible because Electron uses "fake" Stats which returns artificial values ​​for the asar file.

Since BigIntStats doesn't have a constructor like Stats, it can't be solved.

The only option is to "cancel" fake Stats (which is deprecated by the way), but someone would have to comment on that, who did it and why.

ckerr
ckerr previously requested changes Oct 27, 2025
Copy link
Copy Markdown
Member

@ckerr ckerr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking as 'request changes' to prevent accidental merging, since #47505 (comment) says that the current version of this PR won't work.

@panther7
Copy link
Copy Markdown
Contributor Author

I know, how fix it but I don't know, why maintaner use fake Stats for asar file. Maybe some @MarshallOfSound?

@ckerr @jkleinsc

@ckerr
Copy link
Copy Markdown
Member

ckerr commented Oct 31, 2025

@panther7 what does 'fake stats' mean here? i.e. what part of the code are you referring to?

@panther7
Copy link
Copy Markdown
Contributor Author

panther7 commented Nov 1, 2025

@ckerr
I mean this:

const statsObject = new Stats(

Using deprecated Stats construtor which is deprecated and will be probably remove in Nodejs 24 or 26.

For resolve this issue is need BigIntStats object as result if bigint: true option sets. But BigIntStats hasn't construtor.

Right solution is use native fs.stat method which return right object. But i don't know, why is used this fake Stats.

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch 2 times, most recently from 68e7eb8 to 0626af3 Compare November 2, 2025 13:36
@panther7
Copy link
Copy Markdown
Contributor Author

panther7 commented Nov 2, 2025

This is probably fix 0626af3 with using native lstat...

@ckerr
Copy link
Copy Markdown
Member

ckerr commented Mar 5, 2026

@panther7 just to make sure I'm understanding the PR correctly -- the other properties returned by lstatSync, e.g. size, will already be a BigInt and that's why we don't need size in the new Object.entries({}) call, correct?

@ckerr ckerr added semver/patch backwards-compatible bug fixes no-backport labels Mar 5, 2026
@panther7
Copy link
Copy Markdown
Contributor Author

panther7 commented Mar 5, 2026

Actually, fs.lstat with the bigint option is broken in Electron. The expected result is a BigIntStats object with bigint values.

The question is: why are Electron developers creating a fake Stats object with zero size and other fake attributes?

My suggested solution is to use native fs.lstat, which returns the correct object type (Stats or BigIntStats).

If a fake Stats object is not necessary, native fs.lstat should be used by default.

Used Stats contructor is deprecated from NodeJS 20.

@ckerr

@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from 0626af3 to fb068de Compare March 5, 2026 19:05
@panther7 panther7 force-pushed the fix-bigint-asar-wrapper branch from fb068de to 7faa99b Compare March 5, 2026 19:07
@panther7 panther7 requested review from ckerr and codebytere March 5, 2026 20:42
@ckerr
Copy link
Copy Markdown
Member

ckerr commented Mar 9, 2026

The question is: why are Electron developers creating a fake Stats object with zero size and other fake attributes?

Looks like that new Stats code was added in #24495. There was some code review discussing the fake attributes:

stats.atime and friends are never actually set, so this always returns fakeTime

Trying to avoid changing implementation during ts stuff, also why I had to type a few things as any. Turns our there's a lot of inaccuracies in this file. They can all be addressed individually once this has landed.

@panther7
Copy link
Copy Markdown
Contributor Author

Maybe @MarshallOfSound could tell about it.

Copy link
Copy Markdown
Member

@codebytere codebytere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fundamentally not feasible unfortunately. It's not possible to get native stats on asar files because the file doesn't exist to make the stat syscall on. That's why it's faked.

@codebytere codebytere closed this Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

no-backport semver/patch backwards-compatible bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants