Fix divide-by-zero crash for zero-sized cropped images
AcceptedPublic

Authored by twitt on May 24 2020, 12:57 AM.

Details

Reviewers
anthonyfieroni
Group Reviewers
Gwenview
Summary

Gwenview crashes when built as debug version if the cropped tool is executed after an image was cropped to a zero sized image (width or height set to zero). It results in the following assert error:

ASSERT: "!qFuzzyIsNull(c)" in file /usr/include/qt/QtCore/qsize.h, line 202

The origin of this crash is the initialization of the image's ratio in the ratio combobox (to keep a ratio during the crop operation). If width and height are set to zero, the division operation in QRect will crash.

This patch tests if the divisor is zero and will return a ratio of {0, 0} in this case. Those values are valid as a further crop operation is not working anyway, but they prevent the application from crashing.

Test Plan
  1. build Gwenview in debug mode and execute it
  2. open an image
  3. start the crop tool, set width or height to 0, apply the cropping
  4. start the cropping tool again (the application should crash now, without this patch)

Diff Detail

Repository
R260 Gwenview
Lint
Lint Skipped
Unit
Unit Tests Skipped
twitt requested review of this revision.May 24 2020, 12:57 AM
twitt created this revision.
twitt added a comment.Sat, Jun 6, 3:03 PM

Hi, is there anybody who can help review?

Also a more general question. Is it better for you to have a big commit or smaller commits for adding features that require several code changes?

anthonyfieroni added inline comments.
lib/crop/cropwidget.cpp
62

Use qFuzzyIsNull(divisor)

twitt added inline comments.Sat, Jun 6, 6:10 PM
lib/crop/cropwidget.cpp
62

qFuzzyIsNull is only necessary for float or double variables. It is save to test the integer for zero in this case.

anthonyfieroni accepted this revision.Sat, Jun 6, 6:49 PM
This revision is now accepted and ready to land.Sat, Jun 6, 6:49 PM
twitt added a comment.Sat, Jun 6, 6:50 PM

thanks for reviewing!

Thanks! Can you provide an email address so we can land this with correct git authorship information?

twitt added a comment.Wed, Jun 17, 3:46 PM

I hope it's okay to just add it here as a comment:
Tobias Witt <kde@amtare.eu>

Next time I might try out gitlab :)