~ubuntu-branches/ubuntu/intrepid/libgd2/intrepid-updates

« back to all changes in this revision

Viewing changes to gd_gif_in.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2007-02-06 21:15:32 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20070206211532-p00rbx2wak0ls19y
Tags: 2.0.34~rc1-2ubuntu1
* Merge from debian unstable, remaining changes:
  - debian/control: Drop unnecessary build dependency 'gnulib'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
#define LOCALCOLORMAP  0x80
43
43
#define BitSet(byte, bit)      (((byte) & (bit)) == (bit))
44
44
 
45
 
#define        ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) != 0)
 
45
#define        ReadOK(file,buffer,len) (gdGetBuf(buffer, len, file) > 0)
46
46
 
47
47
#define LM_to_uint(a,b)                        (((b)<<8)|(a))
48
48
 
141
141
       Background      = buf[5];
142
142
       AspectRatio     = buf[6];
143
143
#endif
 
144
           imw = LM_to_uint(buf[0],buf[1]);
 
145
           imh = LM_to_uint(buf[2],buf[3]);
144
146
 
145
147
       if (BitSet(buf[4], LOCALCOLORMAP)) {    /* Global Colormap */
146
148
               if (ReadColorMap(fd, BitPixel, ColorMap)) {
177
179
 
178
180
               bitPixel = 1<<((buf[8]&0x07)+1);
179
181
 
180
 
               imw = LM_to_uint(buf[4],buf[5]);
181
 
               imh = LM_to_uint(buf[6],buf[7]);
182
 
               if (!(im = gdImageCreate(imw, imh))) {
183
 
                         return 0;
184
 
               }
185
 
               im->interlace = BitSet(buf[8], INTERLACE);
 
182
 
 
183
                           if (!useGlobalColormap) {
 
184
                                   if (ReadColorMap(fd, bitPixel, localColorMap)) {
 
185
                                           return 0;
 
186
                                   }
 
187
                           }
 
188
 
 
189
                           if (!(im = gdImageCreate(imw, imh))) {
 
190
                                   return 0;
 
191
                           }
 
192
                           im->interlace = BitSet(buf[8], INTERLACE);
186
193
               if (! useGlobalColormap) {
187
194
                       if (ReadColorMap(fd, bitPixel, localColorMap)) { 
188
195
                                 return 0;
205
212
       if (!im) {
206
213
                return 0;
207
214
       }
 
215
           if (!im->colorsTotal) {
 
216
                   gdImageDestroy(im);
 
217
                   return 0;
 
218
           }
208
219
       /* Check for open colors at the end, so
209
220
          we can reduce colorsTotal and ultimately
210
221
          BitsPerPixel */
254
265
               if ((buf[0] & 0x1) != 0)
255
266
                       *Transparent = buf[3];
256
267
 
257
 
               while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) != 0)
 
268
               while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0)
258
269
                       ;
259
270
               return FALSE;
260
271
       default:
261
272
               break;
262
273
       }
263
 
       while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) != 0)
 
274
       while (GetDataBlock(fd, (unsigned char*) buf, ZeroDataBlockP) > 0)
264
275
               ;
265
276
 
266
277
       return FALSE;
327
338
               buf[0] = buf[last_byte-2];
328
339
               buf[1] = buf[last_byte-1];
329
340
 
330
 
               if ((count = GetDataBlock(fd, &buf[2], ZeroDataBlockP)) == 0)
 
341
               if ((count = GetDataBlock(fd, &buf[2], ZeroDataBlockP)) <= 0)
331
342
                       done = TRUE;
332
343
 
333
344
               last_byte = 2 + count;
492
503
       int             v;
493
504
       int             xpos = 0, ypos = 0, pass = 0;
494
505
       int i;
 
506
 
 
507
       /*
 
508
       **  Initialize the Compression routines
 
509
       */
 
510
       if (! ReadOK(fd,&c,1)) {
 
511
               return; 
 
512
       }
 
513
 
 
514
                if (c > MAX_LWZ_BITS) {
 
515
                        return; 
 
516
                }
 
517
 
495
518
       /* Stash the color map into the image */
496
519
       for (i=0; (i<gdMaxColors); i++) {
497
520
               im->red[i] = cmap[CM_RED][i];    
501
524
       }
502
525
       /* Many (perhaps most) of these colors will remain marked open. */
503
526
       im->colorsTotal = gdMaxColors;
504
 
       /*
505
 
       **  Initialize the Compression routines
506
 
       */
507
 
       if (! ReadOK(fd,&c,1)) {
508
 
               return; 
509
 
       }
510
527
       if (LWZReadByte(fd, TRUE, c, ZeroDataBlockP) < 0) {
511
528
               return;
512
529
       }