Fix precedent cells incorrectly accepting file references #2162
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Today I came across a bug that caused a stack overflow and crashed my app. One of my test spreadsheets had a cell
'10.Livestock'!X122
with a formula of=-'[1]10.Livestock'!X122
and with the latest code of ClosedXML from Git, this caused my crash.I know that ClosedXML doesn't currently support file references, and has previously rejected them with a
NotImplementedException
. With latest HEAD though, the newPrecedentCells
code was ignoring the file reference prefix entirely, resulting in the cell'10.Livestock'!X122
basically looking like it had formula of=-'10.Livestock'!X122
, at least for the code that works out the precedent cells. With a certain setup where the value is out of date, this can cause the precedent cell code to get into an infinite recursion loop, overflowing the stack and crashing the app.This PR updates the precedent cell code to use a different method of getting the worksheet which checks for file references and throws an exception if detected, which matches up with what the calculation code does. It also adds a new test to make sure that file references are always rejected.