microsoft / microsoft/microsoft-ui-xaml
UniformGridLayout divide by zero when resized too narrow
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 8.4k
- Forks
- 942
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 105
Description
### Describe the bug
UniformGridLayout.GetMajorSize() divide by zero at https://github.com/microsoft/microsoft-ui-xaml/blob/268e06867114c04cc0f25201b57f64e326113ba0/src/controls/dev/Repeater/UniformGridLayout.cpp#L346
itemsPerLine is zero if the available width is smaller than the width of a single item.
The value of itemsPerLine comes from two places.
https://github.com/microsoft/microsoft-ui-xaml/blob/268e06867114c04cc0f25201b57f64e326113ba0/src/controls/dev/Repeater/UniformGridLayout.cpp#L208-L213
https://github.com/microsoft/microsoft-ui-xaml/blob/268e06867114c04cc0f25201b57f64e326113ba0/src/controls/dev/Repeater/UniformGridLayout.cpp#L331-L333
This is basically a copy-pasta. In both cases, if GetMinorItemSizeWithSpacing is greater than availableSizeMinor + MinItemSpacing(), then itemsPerLine is zero, which leads to the divide by zero.
itemsPerLine should probably be clamped so it cannot go below 1.
### Steps to reproduce the bug
1. Download, build, and run [the WinUINotes sample](https://github.com/MicrosoftDocs/windows-topic-specific-samples/tree/winui-3/tutorials/winui-notes).
2. Create two notes.
3. Go back to the AllNotesPage and resize the window to be as narrow as possible.
4. When you get it narrower than the width of a single note, the UniformGridLayout crashes with a divide by zero.
This issue was copied from https://github.com/MicrosoftDocs/windows-topic-specific-samples/issues/3
### Expected behavior
_No response_
### Screenshots
_No response_
### NuGet package version
None
### Windows version
_No response_
### Additional context
_No response_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/controls/dev/Repeater/UniformGridLayout.cpp at the referenced lines 208-213, 331-333, and 346. Reproduce the issue by resizing the WinUINotes sample narrower than one note, then trace how itemsPerLine is calculated. Done means a narrow layout no longer reaches a divide-by-zero condition and the sample remains usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100