You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid crash in simplifyRanges by removing subsets up front (#6459)
## What's the problem this PR addresses?
Resolves#6373. The problem is that `simplifyRanges` doesn't correctly
reduce redundant OR ranges. For example, `~1.0.1 || ~1.0.2` should be
simplified to `~1.0.1`. As the algorithm runs, it will effectively
calculate every _combination_ of terms in such ranges. For example,
given two ranges like `~1.0.1 || ~1.0.2`, the `nextAlternatives` array
will end up with 2*2 = 4 entries; if you have 100 such ranges you'll end
up with 2^100 entries. Growing exponentially like this it's not hard to
crash the process.
Arguably packages should not specify peer deps with this sort of
redundant range, but sometimes they do (I'm working on cleaning up my
project now that I know what the problem is!) Regardless, yarn shouldn't
crash when it happens.
## How did you fix it?
At the beginning of `simplifyRanges`, I reduce any range of this sort by
splitting it apart and using `sember.subset` to check if one part of the
range is a subset of another, in which case it can be excluded from the
simplified range. I short circuit if the range only has one term, to
avoid any excess parsing.
I think this is the right fix, but I'm happy to take feedback or hand it
off if someone knows better. (Maybe @arcanis as author of this code?)
## Checklist
<!--- Don't worry if you miss something, chores are automatically
tested. -->
<!--- This checklist exists to help you remember doing the chores when
you submit a PR. -->
<!--- Put an `x` in all the boxes that apply. -->
- [x] I have read the [Contributing
Guide](https://yarnpkg.com/advanced/contributing).
<!-- See
https://yarnpkg.com/advanced/contributing#preparing-your-pr-to-be-released
for more details. -->
<!-- Check with `yarn version check` and fix with `yarn version check
-i` -->
- [x] I have set the packages that need to be released for my changes to
be effective.
<!-- The "Testing chores" workflow validates that your PR follows our
guidelines. -->
<!-- If it doesn't pass, click on it to see details as to what your PR
might be missing. -->
- [x] I will check that all automated PR checks pass before the PR gets
reviewed.
0 commit comments