Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Number overflow #21

Closed
wholegroup opened this issue Feb 17, 2022 · 2 comments · Fixed by #23
Closed

Number overflow #21

wholegroup opened this issue Feb 17, 2022 · 2 comments · Fixed by #23

Comments

@wholegroup
Copy link

Hi,

get-folder-size/index.js

Lines 59 to 61 in f5c7a3f

const stats = returnType.strict ? await fs.lstat(itemPath) : await fs.lstat(itemPath).catch(error => errors.push(error));
if(typeof stats !== 'object') return;
fileSizes.set(stats.ino, stats.size);

We've got an issue with folder size calculation. We found out that stats.ino can be a BigInt when fs.lstat has additional options parameter.
I have 2 different files, one has ino = 57420895249767887n, the other has ino = 57420895249767888n
But after we cast BigInt to Number we could have the same result for 2 different values.
Number(57420895249767887n) is equal to 57420895249767890
and
Number(57420895249767888n) is equal to 57420895249767890 as well

Well, we have wrong size (results can be various because of Promise.all) if we call fs.lstat without {bigint: true} option.

Our current workaround:

  const patchedFs = {...fs};
  patchedFs.lstat = async function (itemPath) {
    const stats = await fs.lstat(itemPath, { bigint: true });
    stats.ino = stats.ino.toString();
    stats.size = Number(stats.size);
    return stats;
  };

  const { size, errors } = await getFolderSize(folder, {
    ignore: /node_modules/,
    fs: patchedFs
  });
@atjn
Copy link
Collaborator

atjn commented Feb 17, 2022

Huh, I wasn't aware there was an issue with the conversion of ino IDs.

@atjn
Copy link
Collaborator

atjn commented Jul 27, 2022

Thank you for documenting this properly and bringing it to our attention!

We should be releasing a fix for it soon :)

@atjn atjn closed this as completed in #23 Jul 27, 2022
atjn added a commit that referenced this issue Jul 27, 2022
* Use bigInts for ino IDs, fixes #21

* Support folder size output as BigInt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants