freemyipod r649 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r648‎ | r649 | r650 >
Date:03:35, 4 March 2011
Author:theseven
Status:new
Tags:
Comment:
libpng: Fix some IDAT compression handling bugs
Modified paths:
  • /libs/png/png.c (modified) (history)
  • /libs/png/tinflate.c (modified) (history)

Diff [purge]

Index: libs/png/png.c
@@ -166,9 +166,9 @@
167167 if (!idat)
168168 {
169169 info.idat = in - 8;
170 - info.idatlen += length + 12;
171170 idat = 1;
172171 }
 172+ info.idatlen += length + 12;
173173 in += length;
174174 break;
175175 case PNG_CHUNK_IEND:
Index: libs/png/tinflate.c
@@ -60,10 +60,10 @@
6161 */
6262
6363
64 -//#define DEBUG_CONSOLES 2
65 -//#define DEBUG_PRINT_SOURCE_LINE
66 -
 64+//#define DEBUG_CONSOLES 2
 65+//#define DEBUG_PRINT_SOURCE_LINE
6766
 67+
6868 #include "emcorelib.h"
6969 #include "tinf.h"
7070
@@ -227,27 +227,29 @@
228228 // d->bytecount, d->bitcount, d->source);
229229
230230 /* check if tag is empty */
231 - if (!--d->bitcount)
 231+ if (!d->bitcount)
232232 {
233 - while (!--d->bytecount)
 233+ while (!d->bytecount)
234234 {
235235 DEBUGF("tinf_getbit: refilling bytes");
236 - DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
237 - d->bytecount, d->bitcount, d->source);
 236+ DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
 237+ d->bytecount, d->bitcount, d->source);
238238 d->bytecount = (d->source[4] << 24) | (d->source[5] << 16)
239239 | (d->source[6] << 8) | d->source[7];
240240 d->source += 12;
241 - DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
242 - d->bytecount, d->bitcount, d->source);
 241+ DEBUGF("tinf_getbit: bytecount=%d, bitcount=%d, source=0x%08X",
 242+ d->bytecount, d->bitcount, d->source);
243243 }
244244 /* load next tag */
245245 d->tag = *d->source++;
246246 d->bitcount = 8;
 247+ d->bytecount--;
247248 }
248249
249250 /* shift bit out of tag */
250251 bit = d->tag & 1;
251252 d->tag >>= 1;
 253+ d->bitcount--;
252254
253255 // DEBUGF("tinf_getbit: returning bit %d", bit);
254256 return bit;
@@ -479,9 +481,9 @@
480482 int bfinal;
481483
482484 d.source = (const unsigned char *)(source + 10);
483 - d.bitcount = 1;
 485+ d.bitcount = 0;
484486 d.bytecount = ((d.source[-10] << 24) | (d.source[-9] << 16)
485 - | (d.source[-8] << 8) | d.source[-7]) + 1;
 487+ | (d.source[-8] << 8) | d.source[-7]) - 2;
486488
487489 d.dest = (unsigned char *)dest;
488490 d.destLen = destLen;
@@ -524,8 +526,20 @@
525527 if (res) return res;
526528
527529 if (d.source > (unsigned char *)source + sourceLen)
 530+ {
 531+ DEBUGF("tinf_uncompress: Hit end of buffer! (source=0x%08X, len=%d, current=0x%08X)",
 532+ source, sourceLen, d.source);
528533 return -7;
 534+ }
529535 } while (!bfinal);
530536
 537+ d.bytecount -= 4;
 538+
 539+ if (d.bytecount)
 540+ {
 541+ DEBUGF("tinf_uncompress: %d leftover bytes, %d bits!", d.bytecount, d.bitcount);
 542+ return -8;
 543+ }
 544+
531545 return 0;
532546 }