~ubuntu-branches/ubuntu/gutsy/vnc4/gutsy

« back to all changes in this revision

Viewing changes to unix/xc/programs/Xserver/hw/xfree86/xaa/xaaBitmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2006-05-15 20:35:17 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060515203517-l4lre1ku942mn26k
Tags: 4.1.1+X4.3.0-10
* Correction of critical security issue. Thanks to Martin Kogler
  <e9925248@student.tuwien.ac.at> that informed me about the issue,
  and provided the patch.
  This flaw was originally found by Steve Wiseman of intelliadmin.com.
* Applied patch from Javier Kohen <jkohen@users.sourceforge.net> that
  inform the user that only 8 first characters of the password will
  actually be used when typing more than 8 characters, closes:
  #355619.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $XFree86: xc/programs/Xserver/hw/xfree86/xaa/xaaBitmap.c,v 1.10 2000/09/01 05:49:45 mvojkovi Exp $ */
 
2
 
 
3
 
 
4
#include "xaa.h"
 
5
#include "xaalocal.h"
 
6
#include "xaacexp.h"
 
7
#include "xf86.h"
 
8
#include "xf86_ansic.h"
 
9
 
 
10
 
 
11
 
 
12
/********** byte swapping ***************/
 
13
 
 
14
 
 
15
#ifdef FIXEDBASE
 
16
# define DEST(i)        *dest
 
17
# define RETURN(i)      return(dest)
 
18
#else
 
19
# define DEST(i)        dest[i]
 
20
# define RETURN(i)      return(dest + i)
 
21
#endif
 
22
 
 
23
#ifdef MSBFIRST
 
24
# define SOURCE(i)      SWAP_BITS_IN_BYTES(src[i])
 
25
#else
 
26
# define SOURCE(i)      src[i]
 
27
#endif
 
28
 
 
29
 
 
30
typedef CARD32 *(* BitmapScanlineProcPtr)(CARD32 *, CARD32 *, int, int);
 
31
 
 
32
#ifdef TRIPLE_BITS
 
33
static CARD32*
 
34
BitmapScanline(
 
35
   CARD32 *src, CARD32 *base,
 
36
   int count, int skipleft )
 
37
{
 
38
     CARD32 bits;
 
39
 
 
40
     while(count >= 3) {
 
41
        bits = *src;
 
42
        WRITE_BITS3(bits);
 
43
        src++;
 
44
        count -= 3;
 
45
     }
 
46
     if (count == 2) {
 
47
        bits = *src;
 
48
        WRITE_BITS2(bits);
 
49
     } else if (count == 1) {
 
50
        bits = *src;
 
51
        WRITE_BITS1(bits);
 
52
     }
 
53
     
 
54
     return base;
 
55
}
 
56
 
 
57
static CARD32*
 
58
BitmapScanline_Inverted(
 
59
   CARD32 *src, CARD32 *base,
 
60
   int count, int skipleft )
 
61
{
 
62
     CARD32 bits;
 
63
 
 
64
     while(count >= 3) {
 
65
        bits = ~(*src);
 
66
        WRITE_BITS3(bits);
 
67
        src++;
 
68
        count -= 3;
 
69
     }
 
70
     if (count == 2) {
 
71
        bits = ~(*src);
 
72
        WRITE_BITS2(bits);
 
73
     } else if (count == 1) {
 
74
        bits = ~(*src);
 
75
        WRITE_BITS1(bits);
 
76
     }
 
77
     
 
78
     return base;
 
79
}
 
80
 
 
81
 
 
82
static CARD32*
 
83
BitmapScanline_Shifted(
 
84
   CARD32 *src, CARD32 *base,
 
85
   int count, int skipleft )
 
86
{
 
87
     CARD32 bits;
 
88
 
 
89
     while(count >= 3) {
 
90
        bits = SHIFT_R(*src,skipleft) | SHIFT_L(*(src + 1),(32 - skipleft));
 
91
        WRITE_BITS3(bits);
 
92
        src++;
 
93
        count -= 3;
 
94
     }
 
95
     if (count == 2) {
 
96
        bits = SHIFT_R(*src,skipleft) | SHIFT_L(*(src + 1),(32 - skipleft));
 
97
        WRITE_BITS2(bits);
 
98
     } else if (count == 1) {
 
99
        bits = SHIFT_R(*src,skipleft) | SHIFT_L(*(src + 1),(32 - skipleft));
 
100
        WRITE_BITS1(bits);
 
101
     }
 
102
     
 
103
     return base;
 
104
}
 
105
 
 
106
static CARD32*
 
107
BitmapScanline_Shifted_Inverted(
 
108
   CARD32 *src, CARD32 *base,
 
109
   int count, int skipleft )
 
110
{
 
111
     CARD32 bits;
 
112
 
 
113
     while(count >= 3) {
 
114
        bits = ~(SHIFT_R(*src,skipleft) | SHIFT_L(*(src + 1),(32 - skipleft)));
 
115
        WRITE_BITS3(bits);
 
116
        src++;
 
117
        count -= 3;
 
118
     }
 
119
     if (count == 2) {
 
120
        bits = ~(SHIFT_R(*src,skipleft) | SHIFT_L(*(src + 1),(32 - skipleft)));
 
121
        WRITE_BITS2(bits);
 
122
     } else if (count == 1) {
 
123
        bits = ~(SHIFT_R(*src,skipleft) | SHIFT_L(*(src + 1),(32 - skipleft)));
 
124
        WRITE_BITS1(bits);
 
125
     }
 
126
     
 
127
     return base;
 
128
}
 
129
 
 
130
#define BitmapScanline_Shifted_Careful BitmapScanline_Shifted
 
131
#define BitmapScanline_Shifted_Inverted_Careful BitmapScanline_Shifted_Inverted
 
132
 
 
133
#else
 
134
static CARD32*
 
135
BitmapScanline(
 
136
   CARD32 *src, CARD32 *dest,
 
137
   int count, int skipleft )
 
138
{
 
139
   while(count >= 4) {
 
140
        DEST(0) = SOURCE(0);
 
141
        DEST(1) = SOURCE(1);
 
142
        DEST(2) = SOURCE(2);
 
143
        DEST(3) = SOURCE(3);
 
144
        count -= 4;
 
145
        src += 4;
 
146
#ifndef FIXEDBASE
 
147
        dest += 4;
 
148
#endif
 
149
   }
 
150
   
 
151
   if(!count) return dest;
 
152
   DEST(0) = SOURCE(0);
 
153
   if(count == 1) RETURN(1);
 
154
   DEST(1) = SOURCE(1);
 
155
   if(count == 2) RETURN(2);
 
156
   DEST(2) = SOURCE(2);
 
157
   RETURN(3);
 
158
}
 
159
 
 
160
static CARD32*
 
161
BitmapScanline_Inverted(
 
162
   CARD32 *src, CARD32 *dest,
 
163
   int count, int skipleft )
 
164
{
 
165
   while(count >= 4) {
 
166
        DEST(0) = ~SOURCE(0);
 
167
        DEST(1) = ~SOURCE(1);
 
168
        DEST(2) = ~SOURCE(2);
 
169
        DEST(3) = ~SOURCE(3);
 
170
        count -= 4;
 
171
        src += 4;
 
172
#ifndef FIXEDBASE
 
173
        dest += 4;
 
174
#endif
 
175
   }
 
176
   
 
177
   if(!count) return dest;
 
178
   DEST(0) = ~SOURCE(0);
 
179
   if(count == 1) RETURN(1);
 
180
   DEST(1) = ~SOURCE(1);
 
181
   if(count == 2) RETURN(2);
 
182
   DEST(2) = ~SOURCE(2);
 
183
   RETURN(3);
 
184
}
 
185
 
 
186
 
 
187
static CARD32*
 
188
BitmapScanline_Shifted(
 
189
   CARD32 *bits, CARD32 *base,
 
190
   int count, int skipleft )
 
191
{
 
192
     while(count--) {
 
193
        register CARD32 tmp = SHIFT_R(*bits,skipleft) | 
 
194
                              SHIFT_L(*(bits + 1),(32 - skipleft));
 
195
        WRITE_BITS(tmp);
 
196
        bits++;
 
197
     }
 
198
     return base;
 
199
}
 
200
 
 
201
static CARD32*
 
202
BitmapScanline_Shifted_Inverted(
 
203
   CARD32 *bits, CARD32 *base,
 
204
   int count, int skipleft )
 
205
{
 
206
     while(count--) {
 
207
        register CARD32 tmp = ~(SHIFT_R(*bits,skipleft) | 
 
208
                                SHIFT_L(*(bits + 1),(32 - skipleft)));
 
209
        WRITE_BITS(tmp);
 
210
        bits++;
 
211
     }
 
212
     return base;
 
213
}
 
214
 
 
215
static CARD32*
 
216
BitmapScanline_Shifted_Careful(
 
217
   CARD32 *bits, CARD32 *base,
 
218
   int count, int skipleft )
 
219
{
 
220
     register CARD32 tmp;
 
221
     while(--count) {
 
222
        tmp = SHIFT_R(*bits,skipleft) | SHIFT_L(*(bits + 1),(32 - skipleft));
 
223
        WRITE_BITS(tmp);
 
224
        bits++;
 
225
     }
 
226
     tmp = SHIFT_R(*bits,skipleft);
 
227
     WRITE_BITS(tmp);
 
228
 
 
229
     return base;
 
230
}
 
231
 
 
232
static CARD32*
 
233
BitmapScanline_Shifted_Inverted_Careful(
 
234
   CARD32 *bits, CARD32 *base,
 
235
   int count, int skipleft )
 
236
{
 
237
     register CARD32 tmp;
 
238
     while(--count) {
 
239
        tmp = ~(SHIFT_R(*bits,skipleft) | SHIFT_L(*(bits + 1),(32 - skipleft)));
 
240
        WRITE_BITS(tmp);
 
241
        bits++;
 
242
     }
 
243
     tmp = ~(SHIFT_R(*bits,skipleft));
 
244
     WRITE_BITS(tmp);
 
245
     return base;
 
246
}
 
247
 
 
248
#endif
 
249
 
 
250
/*  
 
251
    When the accelerator is TRANSPARENCY_ONLY, WriteBitmap can do
 
252
    the fill in two passes, inverting the source on the second pass.  
 
253
    For GXcopy we can fill the backing rectangle as a solid rect and
 
254
    avoid the invert.
 
255
*/ 
 
256
 
 
257
void
 
258
#ifdef TRIPLE_BITS
 
259
EXPNAME(XAAWriteBitmapColorExpand3)(
 
260
#else
 
261
EXPNAME(XAAWriteBitmapColorExpand)(
 
262
#endif
 
263
    ScrnInfoPtr pScrn,
 
264
    int x, int y, int w, int H,
 
265
    unsigned char *src,
 
266
    int srcwidth,
 
267
    int skipleft,
 
268
    int fg, int bg,
 
269
    int rop,
 
270
    unsigned int planemask 
 
271
)
 
272
{
 
273
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
 
274
    CARD32* base;
 
275
    unsigned char *srcp = src;
 
276
    int SecondPassColor = -1;
 
277
    int shift = 0, dwords;
 
278
    BitmapScanlineProcPtr firstFunc;
 
279
    BitmapScanlineProcPtr secondFunc;
 
280
    int flag;
 
281
    int h = H;
 
282
 
 
283
#ifdef TRIPLE_BITS
 
284
    if((bg != -1) && 
 
285
        ((infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) ||
 
286
        ((infoRec->CPUToScreenColorExpandFillFlags & RGB_EQUAL) && 
 
287
        (!CHECK_RGB_EQUAL(bg))))) {
 
288
#else
 
289
    if((bg != -1) && 
 
290
        (infoRec->CPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)) {
 
291
#endif
 
292
        if((rop == GXcopy) && infoRec->SetupForSolidFill) {
 
293
            (*infoRec->SetupForSolidFill)(pScrn, bg, rop, planemask);
 
294
            (*infoRec->SubsequentSolidFillRect)(pScrn, x, y, w, h);
 
295
        } else SecondPassColor = bg;
 
296
        bg = -1;
 
297
    }
 
298
 
 
299
#ifdef TRIPLE_BITS
 
300
    if(skipleft) {
 
301
#else
 
302
    if(skipleft && 
 
303
        (!(infoRec->CPUToScreenColorExpandFillFlags & LEFT_EDGE_CLIPPING) || 
 
304
        (!(infoRec->CPUToScreenColorExpandFillFlags & LEFT_EDGE_CLIPPING_NEGATIVE_X) && 
 
305
                (skipleft > x)))) {
 
306
#endif
 
307
        if((skipleft + ((w + 31) & ~31)) > ((skipleft + w + 31) & ~31)) {
 
308
            /* don't read past the end */
 
309
            firstFunc = BitmapScanline_Shifted_Careful;
 
310
            secondFunc = BitmapScanline_Shifted_Inverted_Careful;
 
311
        } else {
 
312
            firstFunc = BitmapScanline_Shifted;
 
313
            secondFunc = BitmapScanline_Shifted_Inverted;
 
314
        }
 
315
        shift = skipleft;
 
316
        skipleft = 0;
 
317
    } else {
 
318
        firstFunc = BitmapScanline;
 
319
        secondFunc = BitmapScanline_Inverted;
 
320
        w += skipleft;
 
321
        x -= skipleft;
 
322
    }
 
323
 
 
324
#ifdef TRIPLE_BITS
 
325
    dwords = (3 * w + 31) >> 5;
 
326
#else
 
327
    dwords = (w + 31) >> 5;
 
328
#endif
 
329
 
 
330
SECOND_PASS:
 
331
 
 
332
    flag = (infoRec->CPUToScreenColorExpandFillFlags 
 
333
             & CPU_TRANSFER_PAD_QWORD) && ((dwords * h) & 0x01);
 
334
    (*infoRec->SetupForCPUToScreenColorExpandFill)(
 
335
                                        pScrn, fg, bg, rop, planemask);
 
336
    (*infoRec->SubsequentCPUToScreenColorExpandFill)(
 
337
                                        pScrn, x, y, w, h, skipleft);
 
338
 
 
339
    base = (CARD32*)infoRec->ColorExpandBase;
 
340
 
 
341
#ifndef FIXEDBASE
 
342
    if((dwords * h) <= infoRec->ColorExpandRange)
 
343
        while(h--) {
 
344
            base = (*firstFunc)((CARD32*)srcp, base, dwords, shift);
 
345
            srcp += srcwidth;
 
346
        }
 
347
    else
 
348
#endif
 
349
        while(h--) {
 
350
            (*firstFunc)((CARD32*)srcp, base, dwords, shift);
 
351
            srcp += srcwidth;
 
352
        }
 
353
 
 
354
    if(flag){
 
355
        base = (CARD32*)infoRec->ColorExpandBase;
 
356
        base[0] = 0x00000000;
 
357
    }
 
358
 
 
359
    if(SecondPassColor != -1) {
 
360
        h = H; /* Reset height */
 
361
        fg = SecondPassColor;
 
362
        SecondPassColor = -1;
 
363
        firstFunc = secondFunc;
 
364
        srcp = src;
 
365
        goto SECOND_PASS;
 
366
    }
 
367
 
 
368
    if(infoRec->CPUToScreenColorExpandFillFlags & SYNC_AFTER_COLOR_EXPAND) 
 
369
        (*infoRec->Sync)(pScrn);
 
370
    else SET_SYNC_FLAG(infoRec);
 
371
}
 
372
 
 
373
#ifndef FIXEDBASE
 
374
 
 
375
void
 
376
#ifdef TRIPLE_BITS
 
377
EXPNAME(XAAWriteBitmapScanlineColorExpand3)(
 
378
#else
 
379
EXPNAME(XAAWriteBitmapScanlineColorExpand)(
 
380
#endif
 
381
    ScrnInfoPtr pScrn,
 
382
    int x, int y, int w, int h,
 
383
    unsigned char *src,
 
384
    int srcwidth,
 
385
    int skipleft,
 
386
    int fg, int bg,
 
387
    int rop,
 
388
    unsigned int planemask 
 
389
)
 
390
{
 
391
    XAAInfoRecPtr infoRec = GET_XAAINFORECPTR_FROM_SCRNINFOPTR(pScrn);
 
392
    CARD32* base;
 
393
    unsigned char *srcp = src;
 
394
    int SecondPassColor = -1;
 
395
    int shift = 0, dwords, bufferNo;
 
396
    BitmapScanlineProcPtr firstFunc;
 
397
    BitmapScanlineProcPtr secondFunc;
 
398
 
 
399
#ifdef TRIPLE_BITS
 
400
    if((bg != -1) &&
 
401
        ((infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY) 
 
402
        || ((infoRec->ScanlineCPUToScreenColorExpandFillFlags & RGB_EQUAL) && 
 
403
        (!CHECK_RGB_EQUAL(bg))))) {
 
404
#else
 
405
    if((bg != -1) && 
 
406
        (infoRec->ScanlineCPUToScreenColorExpandFillFlags & TRANSPARENCY_ONLY)){
 
407
#endif
 
408
        if((rop == GXcopy) && infoRec->SetupForSolidFill) {
 
409
            (*infoRec->SetupForSolidFill)(pScrn, bg, rop, planemask);
 
410
            (*infoRec->SubsequentSolidFillRect)(pScrn, x, y, w, h);
 
411
        } else SecondPassColor = bg;
 
412
        bg = -1;
 
413
    }
 
414
 
 
415
#ifdef TRIPLE_BITS
 
416
    if(skipleft) {
 
417
#else
 
418
    if(skipleft && 
 
419
        (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags & 
 
420
                LEFT_EDGE_CLIPPING) || 
 
421
        (!(infoRec->ScanlineCPUToScreenColorExpandFillFlags &
 
422
                 LEFT_EDGE_CLIPPING_NEGATIVE_X) && (skipleft > x)))) {
 
423
#endif
 
424
        if((skipleft + ((w + 31) & ~31)) > ((skipleft + w + 31) & ~31)) {
 
425
            /* don't read past the end */
 
426
            firstFunc = BitmapScanline_Shifted_Careful;
 
427
            secondFunc = BitmapScanline_Shifted_Inverted_Careful;
 
428
        } else {
 
429
            firstFunc = BitmapScanline_Shifted;
 
430
            secondFunc = BitmapScanline_Shifted_Inverted;
 
431
        }
 
432
        shift = skipleft;
 
433
        skipleft = 0;
 
434
    } else {
 
435
        firstFunc = BitmapScanline;
 
436
        secondFunc = BitmapScanline_Inverted;
 
437
        w += skipleft;
 
438
        x -= skipleft;
 
439
    }
 
440
 
 
441
#ifdef TRIPLE_BITS
 
442
    dwords = (3 * w + 31) >> 5;
 
443
#else
 
444
    dwords = (w + 31) >> 5;
 
445
#endif
 
446
 
 
447
SECOND_PASS:
 
448
 
 
449
    (*infoRec->SetupForScanlineCPUToScreenColorExpandFill)(pScrn, fg, bg, rop, planemask);
 
450
    (*infoRec->SubsequentScanlineCPUToScreenColorExpandFill)(
 
451
                                        pScrn, x, y, w, h, skipleft);
 
452
 
 
453
    bufferNo = 0;
 
454
 
 
455
    while(h--) {
 
456
        base = (CARD32*)infoRec->ScanlineColorExpandBuffers[bufferNo];
 
457
        (*firstFunc)((CARD32*)srcp, base, dwords, shift);
 
458
        (*infoRec->SubsequentColorExpandScanline)(pScrn, bufferNo++);
 
459
        srcp += srcwidth;
 
460
        if(bufferNo >= infoRec->NumScanlineColorExpandBuffers)
 
461
            bufferNo = 0;
 
462
    }
 
463
 
 
464
    if(SecondPassColor != -1) {
 
465
        fg = SecondPassColor;
 
466
        SecondPassColor = -1;
 
467
        firstFunc = secondFunc;
 
468
        srcp = src;
 
469
        goto SECOND_PASS;
 
470
    }
 
471
 
 
472
    SET_SYNC_FLAG(infoRec);
 
473
}
 
474
 
 
475
#endif