From 8720df9baa25faf1df03c230185e3f4eac99b8bc Mon Sep 17 00:00:00 2001 From: "trop[bot]" <37223003+trop[bot]@users.noreply.github.com> Date: Fri, 10 Apr 2026 12:15:26 +0200 Subject: [PATCH] fix: return numeric blksize and blocks from asar fs.stat (#50876) fix: return numeric `blksize` and `blocks` from asar `fs.stat` Previously, `fs.stat` on files inside `.asar` archives returned `undefined` for `blksize` and `blocks`, violating the Node.js API contract where these fields must be `number | bigint`. Use `4096` for `blksize` (matching the convention used by `memfs` and the proposed `node:vfs` module in nodejs/node#61478) and compute `blocks` as `ceil(size / 512)` (standard 512-byte block units). Fixes #42686 Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: clavin --- lib/node/asar-fs-wrapper.ts | 4 ++-- spec/asar-spec.ts | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/node/asar-fs-wrapper.ts b/lib/node/asar-fs-wrapper.ts index 4e3602df4e..bf0d3e705d 100644 --- a/lib/node/asar-fs-wrapper.ts +++ b/lib/node/asar-fs-wrapper.ts @@ -135,10 +135,10 @@ const asarStatsToFsStats = function (stats: NodeJS.AsarFileStat) { uid, gid, 0, // rdev - undefined, // blksize + 4096, // blksize ++nextInode, // ino stats.size, - undefined, // blocks, + Math.ceil(stats.size / 512), // blocks (512-byte units) fakeTime.getTime(), // atim_msec fakeTime.getTime(), // mtim_msec fakeTime.getTime(), // ctim_msec diff --git a/spec/asar-spec.ts b/spec/asar-spec.ts index e8e4e1b05d..0243b38d05 100644 --- a/spec/asar-spec.ts +++ b/spec/asar-spec.ts @@ -458,6 +458,14 @@ describe('asar package', function () { expect(stats.size).to.equal(0); }); + itremote('returns stat properties with types matching a real file', function () { + const asarStats = fs.lstatSync(path.join(asarDir, 'a.asar', 'file1')); + const realStats = fs.lstatSync(path.join(fixtures, 'test.asar', 'a.asar')); + for (const key of Object.keys(realStats) as (keyof typeof realStats)[]) { + expect(typeof asarStats[key]).to.equal(typeof realStats[key], `typeof stats.${key}`); + } + }); + itremote('returns information of root with stats as bigint', function () { const p = path.join(asarDir, 'a.asar'); const stats = fs.lstatSync(p, { bigint: false });