-
Notifications
You must be signed in to change notification settings - Fork 804
Description
Describe the bug
UniformGridLayout.GetMajorSize() divide by zero at
| const int fullLinesCount = itemsCount / itemsPerLine; |
itemsPerLine is zero if the available width is smaller than the width of a single item.
The value of itemsPerLine comes from two places.
microsoft-ui-xaml/src/controls/dev/Repeater/UniformGridLayout.cpp
Lines 208 to 213 in 268e068
| const unsigned int itemsPerLine = | |
| std::min( // note use of unsigned ints | |
| std::max(1u, std::isfinite(availableSizeMinor) | |
| ? static_cast<unsigned int>((availableSizeMinor + MinItemSpacing()) / GetMinorItemSizeWithSpacing(context)) | |
| : itemsCount), | |
| std::max(1u, m_maximumRowsOrColumns)); |
microsoft-ui-xaml/src/controls/dev/Repeater/UniformGridLayout.cpp
Lines 331 to 333 in 268e068
| return std::min( | |
| static_cast<unsigned int>((availableSizeMinor + MinItemSpacing()) / GetMinorItemSizeWithSpacing(context)), | |
| maximumRowsOrColumns); |
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
- Download, build, and run the WinUINotes sample.
- Create two notes.
- Go back to the AllNotesPage and resize the window to be as narrow as possible.
- 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 MicrosoftDocs/windows-topic-specific-samples#3
Expected behavior
No response
Screenshots
No response
NuGet package version
None
Windows version
No response
Additional context
No response