[iOS] Stop computing illegal TabGridPage values.
The GetPageFromScrollView() utility function in TabGridViewController computes a TabGridPage value (an enum in the range 0..2) by dividing the scroll view offset by its page width and then lround()ing. This can, it turns out, produce values outside of the 0..2 range, which is not caught at runtime. This causes problems because the currentPageViewController property getter uses a switch() based on a TabGridPage value. Because the switch is over an enum, there's no default case. But because this enum is just a typedef for an int, there's no guarantees that all enum values are valid. When a TabGridPage value of, say, 3 (or MAXINT, or whatever) is set for _currentPage, none of the switch cases in currentPageViewController are hit, so it doesn't set a return value. This means that at runtime the return value is random memory, which means crashes of various kinds. This CL is the quick fix: it clamps the value of the page computation to the defined range of the TabGridPage typedef. This is suitable for merging into release. The better fix, which is to change TabGridPage to an enum class and stop inferring discrete values using just arithmetic, will be in a follow-up CL, which will probably touch too much code for convenient merging, but which can land on trunk for future releases. Bug: 979683 Change-Id: If817d6c6ca0e657d5a49efbc2169601e44b29bdb Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1728882Reviewed-by:edchin <edchin@chromium.org> Commit-Queue: Mark Cogan <marq@chromium.org> Cr-Commit-Position: refs/heads/master@{#682753}
Showing
Please register or sign in to comment