Bound flatCols to MaxColumns when flattening worksheet columns - #2370
Merged
Conversation
The min and max attributes of a col element are read from the worksheet XML without validation, and flatCols materializes one xlsxCol per column in that range. A worksheet cannot hold more than MaxColumns columns, so a file declaring a wider range makes the function allocate for columns that cannot exist. Clamping both loops to MinColumns..MaxColumns keeps the flattening result the same for any range a worksheet can actually contain, and bounds the work for ranges it cannot. Adds a regression test asserting the flattened set stays within MaxColumns and that a real column is still flattened and readable afterwards. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
xuri
requested changes
Aug 7, 2026
xuri
approved these changes
Aug 7, 2026
xuri
left a comment
Member
There was a problem hiding this comment.
Thanks for your contribution. I've made some changes based on your branch.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2370 +/- ##
=======================================
Coverage 99.62% 99.62%
=======================================
Files 32 32
Lines 26994 26994
=======================================
Hits 26892 26892
Misses 53 53
Partials 49 49
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
flatColsmaterializes onexlsxColper column in the range a<col>element declares. Thoseminandmaxattributes come straight from the worksheet XML and are not validated anywhere on the way in, so the size of that loop is whatever the file says it is.A worksheet cannot hold more than
MaxColumnscolumns, so flattening past that bound cannot produce anything usable. This clamps both loops toMinColumns..MaxColumns.For any range a worksheet can genuinely contain the result is unchanged, since the clamp only takes effect outside the representable range. The four column mutators that call
flatCols(setColVisible,setColOutlineLevel,setColStyle,setColWidth) keep their signatures, so nothing changes for callers.I went with clamping rather than returning
ErrColumnNumberto keep this toflatCols. Returning an error would mean threading it through those four helpers and their nine call sites acrosscol.goandstream.go. Happy to redo it that way if you would rather reject such a file outright, and equally happy to move the check to parse time instead.Verified:
go build ./...clean,gofmtcleango test ./...passes (71s)TestFlatColsBounded, which sets a<col>range of1..2147483647on a sheet, callsSetColWidth, and asserts the flattened set stays withinMaxColumnswhile a real column is still flattened and readableFiled at your request from the report on the advisory.