DIB fix

François Gouget fgouget at codeweavers.com
Tue Oct 30 14:54:27 CST 2001


   When left!=0 we don't copy a full line so Convert_any_asis cannot not
use dstlinebytes as the length of a line in bytes. We really have to use
width and multiply it by the number of bytes per pixel.
   This 
bug could cause a buffer overflow.

Changelog:

   François Gouget <fgouget at codeweavers.com>

 * graphics/x11drv/dib.c
   Fix line length calculation in X11DRV_DIB_Convert_any_asis

-- 
François Gouget
fgouget at codeweavers.com
-------------- next part --------------
Index: graphics/x11drv/dib.c
===================================================================
RCS file: /home/wine/wine/graphics/x11drv/dib.c,v
retrieving revision 1.81
diff -u -r1.81 dib.c
--- graphics/x11drv/dib.c	2001/10/17 19:41:54	1.81
+++ graphics/x11drv/dib.c	2001/10/30 19:09:14
@@ -330,12 +330,13 @@
  *   high bits, the green, and the source color in the low bits.
  */
 static void X11DRV_DIB_Convert_any_asis(int width, int height,
+                                    int bytes_per_pixel,
                                     const void* srcbits, int srclinebytes,
                                     void* dstbits, int dstlinebytes)
 {
     int y;
 
-    width=abs(dstlinebytes);
+    width*=bytes_per_pixel;
     for (y=0; y<height; y++) {
         memcpy(dstbits, srcbits, width);
         srcbits += srclinebytes;
@@ -2938,7 +2939,7 @@
                     /* ==== rgb 555 dib -> rgb 555 bmp ==== */
                     /* ==== bgr 555 dib -> bgr 555 bmp ==== */
                     X11DRV_DIB_Convert_any_asis
-                        (dstwidth,lines,
+                        (dstwidth,lines,2,
                          srcbits,linebytes,
                          dstbits,-bmpImage->bytes_per_line);
                 } else {
@@ -2981,7 +2982,7 @@
                     /* ==== rgb 565 dib -> rgb 565 bmp ==== */
                     /* ==== bgr 565 dib -> bgr 565 bmp ==== */
                     X11DRV_DIB_Convert_any_asis
-                        (dstwidth,lines,
+                        (dstwidth,lines,2,
                          srcbits,linebytes,
                          dstbits,-bmpImage->bytes_per_line);
                 } else {
@@ -3199,7 +3200,7 @@
                     /* ==== rgb 555 bmp -> rgb 555 dib ==== */
                     /* ==== bgr 555 bmp -> bgr 555 dib ==== */
                     X11DRV_DIB_Convert_any_asis
-                        (dstwidth,lines,
+                        (dstwidth,lines,2,
                          srcbits,-bmpImage->bytes_per_line,
                          dstbits,linebytes);
                 } else {
@@ -3241,7 +3242,7 @@
                     /* ==== rgb 565 bmp -> rgb 565 dib ==== */
                     /* ==== bgr 565 bmp -> bgr 565 dib ==== */
                     X11DRV_DIB_Convert_any_asis
-                        (dstwidth,lines,
+                        (dstwidth,lines,2,
                          srcbits,-bmpImage->bytes_per_line,
                          dstbits,linebytes);
                 } else {
@@ -3522,7 +3523,7 @@
                 /* ==== rgb 888 dib -> rgb 888 bmp ==== */
                 /* ==== bgr 888 dib -> bgr 888 bmp ==== */
                 X11DRV_DIB_Convert_any_asis
-                    (dstwidth,lines,
+                    (dstwidth,lines,3,
                      srcbits,linebytes,
                      dstbits,-bmpImage->bytes_per_line);
             } else {
@@ -3677,7 +3678,7 @@
                 /* ==== rgb 888 bmp -> rgb 888 dib ==== */
                 /* ==== bgr 888 bmp -> bgr 888 dib ==== */
                 X11DRV_DIB_Convert_any_asis
-                    (dstwidth,lines,
+                    (dstwidth,lines,3,
                      srcbits,-bmpImage->bytes_per_line,
                      dstbits,linebytes);
             } else {
@@ -3923,7 +3924,7 @@
                     /* ==== rgb 0888 dib -> rgb 0888 bmp ==== */
                     /* ==== bgr 0888 dib -> bgr 0888 bmp ==== */
                     X11DRV_DIB_Convert_any_asis
-                        (dstwidth,lines,
+                        (dstwidth,lines,4,
                          srcbits,linebytes,
                          dstbits,-bmpImage->bytes_per_line);
                 } else if (rSrc==bmpImage->blue_mask && bSrc==bmpImage->red_mask) {
@@ -4159,7 +4160,7 @@
                     /* ==== rgb 0888 bmp -> rgb 0888 dib ==== */
                     /* ==== bgr 0888 bmp -> bgr 0888 dib ==== */
                     X11DRV_DIB_Convert_any_asis
-                        (dstwidth,lines,
+                        (dstwidth,lines,4,
                          srcbits,-bmpImage->bytes_per_line,
                          dstbits,linebytes);
                 } else if (rDst==bmpImage->blue_mask && bDst==bmpImage->red_mask) {


More information about the wine-patches mailing list