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

Add heuristics to stats.ino comparison when bigint is not available #694

Merged

Conversation

mbargiel
Copy link
Contributor

@mbargiel mbargiel commented Jun 1, 2019

The resolution of #657 relies on Node >= 10.5, but actually leaves the issue not fixed on previous versions of Node (in particular, for the OP, who reported the issue on Node 8.11.3). The issue particularly problematic and frequent in automated setups, such as running tests that create files in sequence, where it is likely to happen.

This PR minimizes the frequency of this issue by comparing additional fs.Stats values when Bigint support is not available. Note that the check is still heuristic: different stats prove they are different files*, but while same stats do not prove they are the same, we must err on the side of caution and still treat them as the same file.

(*) Race condition: comparing file stats before performing a copy or other operation implicitly introduces a race condition. However the existing implementation already suffered from this, so we presume that this PR does not make the condition much worse (with the exception that unlike ino and vol, a malicious user could in theory manipulate some of the other stats). In practice, this race condition seems extremely hard to abuse, since it requires using a vulnerable system, and a means to change the file stats between the two stats calls made by getStats and getStatsSync.

@coveralls
Copy link

coveralls commented Jun 1, 2019

Coverage Status

Coverage decreased (-0.08%) to 83.45% when pulling 391fb73 on mbargiel:feature/stats-heuristics-without-bigint into ca58cbc on jprichardson:master.

@mbargiel mbargiel force-pushed the feature/stats-heuristics-without-bigint branch from 10b96d3 to bea4a39 Compare June 1, 2019 13:29
@mbargiel
Copy link
Contributor Author

mbargiel commented Jun 1, 2019

Sorry about the last commit (10b96d3), I pushed too fast - it's unnecessary. I removed it.

@mbargiel
Copy link
Contributor Author

mbargiel commented Jun 2, 2019

Checked the coverage loss - it's due to the fact that the code branch where I added the heuristic checks was not covered by tests (of course, since BigInt is supported in the test runs used by the coverage check).

lib/util/stat.js Outdated
throw new Error(errMsg(src, dest, funcName))
}
return checkParentPathsSync(src, srcStat, destParent, funcName)
}

function areApparentlyIdentical (srcStat, destStat) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is good but the function name is a bit confusing. Will you please rename it to something simpler like just areIdentical?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 7e4c852

Copy link
Collaborator

@manidlou manidlou left a comment

Choose a reason for hiding this comment

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

LGTM! however this needs to be squashed before merging.

@mbargiel mbargiel force-pushed the feature/stats-heuristics-without-bigint branch from 7e4c852 to 391fb73 Compare July 27, 2019 17:32
@mbargiel
Copy link
Contributor Author

@manidlou Commits squashed into 391fb73

Copy link
Collaborator

@RyanZim RyanZim left a comment

Choose a reason for hiding this comment

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

LGTM

@manidlou
Copy link
Collaborator

@RyanZim do we wanna merge this directly into master? we have #633 and #698 that are apparently gonna be ready soon as well!

@RyanZim
Copy link
Collaborator

RyanZim commented Jul 30, 2019

I'm good with merging.

@manidlou manidlou merged commit e3d1ab8 into jprichardson:master Jul 30, 2019
@mbargiel mbargiel deleted the feature/stats-heuristics-without-bigint branch July 30, 2019 21:12
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 this pull request may close these issues.

None yet

4 participants