Bug 138161

Summary: kslideshow.kss crashes quietly when "Random Position" is selected
Product: kscreensaver Reporter: Bryant Hansen <kde>
Component: screensaversAssignee: kscreensaver bugs tracking <kscreensaver-bugs-null>
Status: RESOLVED FIXED    
Severity: crash    
Priority: NOR    
Version: unspecified   
Target Milestone: ---   
Platform: Gentoo Packages   
OS: Linux   
Latest Commit: Version Fixed In:

Description Bryant Hansen 2006-11-30 15:05:31 UTC
Version:            (using KDE KDE 3.5.5)
Installed from:    Gentoo Packages
Compiler:          gcc 4.1.1 
OS:                Linux

The "Slide Show" screen saver in KDE Control Center only plays a handful of slides from a large collection and then dies.  The problem only occurs when I have the "Random Position" setting checked.

Today I determined the exact cause of the problem: it's in the calculation of the random position. When either the image width or the height matches the screen dimensions exactly, a divide-by-zero error results and the screen saver crashes.

The offending lines of code are lines 778 and 779 in screensaver.cpp (KDE 3.5.5):

          x = rand() % (ww - iw);
          y = rand() % (wh - ih); 

One possible fix, which I've tested successfully, is to change the boundary-checking condition above.

Line 759:
      if(iw > ww || ih > wh)

Should be changed to:
      if(iw >= ww || ih >= wh)
Comment 1 Oswald Buddenhagen 2007-05-18 22:57:14 UTC
SVN commit 666124 by ossi:

backport: fix div by 0
BUG: 138161


 M  +1 -1      slideshow.cpp  


--- branches/KDE/3.5/kdeartwork/kscreensaver/kdesavers/slideshow.cpp #666123:666124
@@ -756,7 +756,7 @@
     }
     else
     {
-      if(iw > ww || ih > wh)
+      if(iw >= ww || ih >= wh)
       {
         fx = (double)ww / iw;
 	fy = (double)wh / ih;