Skip to content

Commit

Permalink
java: Make SVWindow more robust (fix three CID issues)
Browse files Browse the repository at this point in the history
1386093 Division or modulo by zero
1386096 Division or modulo by float zero
1386101 Division or modulo by float zero

A division by zero would have occurred if both sizeX and canvasSizeX or
sizeY and canvasSizeY were 0.

Catch also negative sizes which don't raise a division by zero exception
but which are also invalid.

Signed-off-by: Stefan Weil <[email protected]>
  • Loading branch information
stweil committed Apr 26, 2018
1 parent 64e2eff commit 63d5709
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions java/com/google/scrollview/ui/SVWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,20 @@ public SVWindow(String name, int hash, int posX, int posY, int sizeX,
super(name);

// Provide defaults for sizes.
if (sizeX == 0) sizeX = canvasSizeX;
if (sizeY == 0) sizeY = canvasSizeY;
if (canvasSizeX == 0) canvasSizeX = sizeX;
if (canvasSizeY == 0) canvasSizeY = sizeY;
if (sizeX <= 0) sizeX = canvasSizeX;
if (sizeY <= 0) sizeY = canvasSizeY;
if (canvasSizeX <= 0) canvasSizeX = sizeX;
if (canvasSizeY <= 0) canvasSizeY = sizeY;

// Avoid later division by zero.
if (sizeX <= 0) {
sizeX = 1;
canvasSizeX = sizeX;
}
if (sizeY <= 0) {
sizeY = 1;
canvasSizeY = sizeY;
}

// Initialize variables
nrWindows++;
Expand Down

0 comments on commit 63d5709

Please sign in to comment.