summaryrefslogtreecommitdiffstats
path: root/src/kernel/qimage.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/kernel/qimage.cpp')
-rw-r--r--src/kernel/qimage.cpp95
1 files changed, 60 insertions, 35 deletions
diff --git a/src/kernel/qimage.cpp b/src/kernel/qimage.cpp
index 8dd71be..69b5350 100644
--- a/src/kernel/qimage.cpp
+++ b/src/kernel/qimage.cpp
@@ -1392,7 +1392,7 @@ struct QRgbMap {
static bool convert_32_to_8( const QImage *src, QImage *dst, int conversion_flags, QRgb* palette=0, int palette_count=0 )
{
- register QRgb *p;
+ QRgb *p;
uchar *b;
bool do_quant = FALSE;
int y, x;
@@ -1702,7 +1702,7 @@ static bool convert_8_to_32( const QImage *src, QImage *dst )
return FALSE; // create failed
dst->setAlphaBuffer( src->hasAlphaBuffer() );
for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
- register uint *p = (uint *)dst->scanLine(y);
+ uint *p = (uint *)dst->scanLine(y);
uchar *b = src->scanLine(y);
uint *end = p + dst->width();
while ( p < end )
@@ -1718,7 +1718,7 @@ static bool convert_1_to_32( const QImage *src, QImage *dst )
return FALSE; // could not create
dst->setAlphaBuffer( src->hasAlphaBuffer() );
for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
- register uint *p = (uint *)dst->scanLine(y);
+ uint *p = (uint *)dst->scanLine(y);
uchar *b = src->scanLine(y);
int x;
if ( src->bitOrder() == QImage::BigEndian ) {
@@ -1756,7 +1756,7 @@ static bool convert_1_to_8( const QImage *src, QImage *dst )
dst->setColor( 1, 0xff000000 );
}
for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
- register uchar *p = dst->scanLine(y);
+ uchar *p = dst->scanLine(y);
uchar *b = src->scanLine(y);
int x;
if ( src->bitOrder() == QImage::BigEndian ) {
@@ -1833,7 +1833,7 @@ static bool dither_to_1( const QImage *src, QImage *dst,
int bmwidth = (w+7)/8;
if ( !(line1 && line2) )
return FALSE;
- register uchar *p;
+ uchar *p;
uchar *end;
int *b1, *b2;
int wbytes = w * (d/8);
@@ -2083,7 +2083,7 @@ static bool convert_16_to_32( const QImage *src, QImage *dst )
return FALSE; // create failed
dst->setAlphaBuffer( src->hasAlphaBuffer() );
for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
- register uint *p = (uint *)dst->scanLine(y);
+ uint *p = (uint *)dst->scanLine(y);
ushort *s = (ushort*)src->scanLine(y);
uint *end = p + dst->width();
while ( p < end )
@@ -2099,7 +2099,7 @@ static bool convert_32_to_16( const QImage *src, QImage *dst )
return FALSE; // create failed
dst->setAlphaBuffer( src->hasAlphaBuffer() );
for ( int y=0; y<dst->height(); y++ ) { // for each scan line...
- register ushort *p = (ushort *)dst->scanLine(y);
+ ushort *p = (ushort *)dst->scanLine(y);
uint *s = (uint*)src->scanLine(y);
ushort *end = p + dst->width();
while ( p < end )
@@ -2363,7 +2363,7 @@ QImage QImage::convertBitOrder( Endian bitOrder ) const
int bpl = (width() + 7) / 8;
for ( int y = 0; y < data->h; y++ ) {
- register uchar *p = jumpTable()[y];
+ uchar *p = jumpTable()[y];
uchar *end = p + bpl;
uchar *b = image.jumpTable()[y];
while ( p < end )
@@ -2454,14 +2454,14 @@ void pnmscale(const QImage& src, QImage& dst)
{
QRgb* xelrow = 0;
QRgb* tempxelrow = 0;
- register QRgb* xP;
- register QRgb* nxP;
+ QRgb* xP;
+ QRgb* nxP;
int rows, cols, rowsread, newrows, newcols;
- register int row, col, needtoreadrow;
+ int row, col, needtoreadrow;
const uchar maxval = 255;
double xscale, yscale;
long sxscale, syscale;
- register long fracrowtofill, fracrowleft;
+ long fracrowtofill, fracrowleft;
long* as;
long* rs;
long* gs;
@@ -2551,11 +2551,11 @@ void pnmscale(const QImage& src, QImage& dst)
xelrow = (QRgb*)src.scanLine(rowsread++);
needtoreadrow = 0;
}
- register long a=0;
+ long a=0;
for ( col = 0, xP = xelrow, nxP = tempxelrow;
col < cols; ++col, ++xP, ++nxP )
{
- register long r, g, b;
+ long r, g, b;
if ( as ) {
r = rs[col] + fracrowtofill * qRed( *xP ) * qAlpha( *xP ) / 255;
@@ -2601,9 +2601,9 @@ void pnmscale(const QImage& src, QImage& dst)
/* shortcut X scaling if possible */
memcpy(dst.scanLine(rowswritten++), tempxelrow, newcols*4);
} else {
- register long a, r, g, b;
- register long fraccoltofill, fraccolleft = 0;
- register int needcol;
+ long a, r, g, b;
+ long fraccoltofill, fraccolleft = 0;
+ int needcol;
nxP = (QRgb*)dst.scanLine(rowswritten++);
fraccoltofill = SCALE;
@@ -3692,7 +3692,7 @@ static void swapPixel01( QImage *image ) // 1-bpp: swap 0 and 1 pixels
{
int i;
if ( image->depth() == 1 && image->numColors() == 2 ) {
- register uint *p = (uint *)image->bits();
+ uint *p = (uint *)image->bits();
int nbytes = image->numBytes();
for ( i=0; i<nbytes/4; i++ ) {
*p = ~*p;
@@ -3942,7 +3942,7 @@ static QImageHandler *get_image_handler( const char *format )
{ // get pointer to handler
qt_init_image_handlers();
qt_init_image_plugins();
- register QImageHandler *p = imageHandlers->first();
+ QImageHandler *p = imageHandlers->first();
while ( p ) { // traverse list
if ( p->format == format )
return p;
@@ -4776,7 +4776,7 @@ bool read_dib( QDataStream& s, int offset, int startpos, QImage& image )
Q_CHECK_PTR( buf );
if ( comp == BMP_RLE4 ) { // run length compression
int x=0, y=0, b, c, i;
- register uchar *p = line[h-1];
+ uchar *p = line[h-1];
uchar *endp = line[h-1]+w;
while ( y < h ) {
if ( (b=d->getch()) == EOF )
@@ -4841,7 +4841,7 @@ bool read_dib( QDataStream& s, int offset, int startpos, QImage& image )
while ( --h >= 0 ) {
if ( d->readBlock((char*)buf,buflen) != buflen )
break;
- register uchar *p = line[h];
+ uchar *p = line[h];
uchar *b = buf;
for ( int i=0; i<w/2; i++ ) { // convert nibbles to bytes
*p++ = *b >> 4;
@@ -4857,7 +4857,7 @@ bool read_dib( QDataStream& s, int offset, int startpos, QImage& image )
else if ( nbits == 8 ) { // 8 bit BMP image
if ( comp == BMP_RLE8 ) { // run length compression
int x=0, y=0, b;
- register uchar *p = line[h-1];
+ uchar *p = line[h-1];
const uchar *endp = line[h-1]+w;
while ( y < h ) {
if ( (b=d->getch()) == EOF )
@@ -4920,7 +4920,7 @@ bool read_dib( QDataStream& s, int offset, int startpos, QImage& image )
}
else if ( nbits == 16 || nbits == 24 || nbits == 32 ) { // 16,24,32 bit BMP image
- register QRgb *p;
+ QRgb *p;
QRgb *end;
uchar *buf24 = new uchar[bpl];
int bpl24 = ((w*nbits+31)/32)*4;
@@ -5051,7 +5051,7 @@ bool qt_write_dib( QDataStream& s, QImage image )
uchar *buf = new uchar[bpl_bmp];
uchar *b, *end;
- register uchar *p;
+ uchar *p;
memset( buf, 0, bpl_bmp );
for ( y=image.height()-1; y>=0; y-- ) { // write the image bits
@@ -5196,7 +5196,7 @@ static void read_pbm_image( QImageIO *iio ) // read PBM image data
mcc = 1; // ignore max color component
else
mcc = read_pbm_int( d ); // get max color component
- if ( w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0 )
+ if ( w <= 0 || w > 32767 || h <= 0 || h > 32767 || mcc <= 0 || mcc > 0xffff )
return; // weird P.M image
int maxc = mcc;
@@ -5237,7 +5237,7 @@ static void read_pbm_image( QImageIO *iio ) // read PBM image data
}
}
} else { // read ascii data
- register uchar *p;
+ uchar *p;
int n;
for ( y=0; y<h; y++ ) {
p = image.scanLine( y );
@@ -5503,7 +5503,7 @@ static void read_async_image( QImageIO *iio )
X bitmap image read/write functions
*****************************************************************************/
-static inline int hex2byte( register char *p )
+static inline int hex2byte( char *p )
{
return ( (isdigit((uchar) *p) ? *p - '0' : toupper((uchar) *p) - 'A' + 10) << 4 ) |
( isdigit((uchar) *(p+1)) ? *(p+1) - '0' : toupper((uchar) *(p+1)) - 'A' + 10 );
@@ -5512,18 +5512,32 @@ static inline int hex2byte( register char *p )
static void read_xbm_image( QImageIO *iio )
{
const int buflen = 300;
+ const int maxlen = 4096;
char buf[buflen];
QRegExp r1, r2;
QIODevice *d = iio->ioDevice();
int w=-1, h=-1;
QImage image;
+ Q_INT64 readBytes = 0;
+ Q_INT64 totalReadBytes = 0;
r1 = QString::fromLatin1("^#define[ \t]+[a-zA-Z0-9._]+[ \t]+");
r2 = QString::fromLatin1("[0-9]+");
- d->readLine( buf, buflen ); // "#define .._width <num>"
- while (!d->atEnd() && buf[0] != '#') //skip leading comment, if any
- d->readLine( buf, buflen );
+ buf[0] = '\0';
+ while (buf[0] != '#') { //skip leading comment, if any
+ readBytes = d->readLine(buf, buflen);
+
+ // if readBytes >= buflen, it's very probably not a C file
+ if ((readBytes <= 0) || (readBytes >= (buflen-1)))
+ return;
+
+ // limit xbm headers to the first 4k in the file to prevent
+ // excessive reads on non-xbm files
+ totalReadBytes += readBytes;
+ if (totalReadBytes >= maxlen)
+ return;
+ }
QString sbuf;
sbuf = QString::fromLatin1(buf);
@@ -5532,7 +5546,10 @@ static void read_xbm_image( QImageIO *iio )
r2.search(sbuf, r1.matchedLength()) == r1.matchedLength() )
w = atoi( &buf[r1.matchedLength()] );
- d->readLine( buf, buflen ); // "#define .._height <num>"
+ readBytes = d->readLine(buf, buflen ); // "#define .._height <num>"
+ if (readBytes <= 0) {
+ return;
+ }
sbuf = QString::fromLatin1(buf);
if ( r1.search(sbuf) == 0 &&
@@ -5543,8 +5560,11 @@ static void read_xbm_image( QImageIO *iio )
return; // format error
for ( ;; ) { // scan for data
- if ( d->readLine(buf, buflen) <= 0 ) // end of file
+ readBytes = d->readLine(buf, buflen);
+ if (readBytes <= 0) { // end of file
return;
+ }
+ buf[readBytes] = '\0';
if ( strstr(buf,"0x") != 0 ) // does line contain data?
break;
}
@@ -5562,7 +5582,10 @@ static void read_xbm_image( QImageIO *iio )
w = (w+7)/8; // byte width
while ( y < h ) { // for all encoded bytes...
- if ( p ) { // p = "0x.."
+ if (p && (p < (buf + readBytes - 3))) { // p = "0x.."
+ if (!isxdigit(p[2]) || !isxdigit(p[3])) {
+ return;
+ }
*b++ = hex2byte(p+2);
p += 2;
if ( ++x == w && ++y < h ) {
@@ -5571,8 +5594,10 @@ static void read_xbm_image( QImageIO *iio )
}
p = strstr( p, "0x" );
} else { // read another line
- if ( d->readLine(buf,buflen) <= 0 ) // EOF ==> truncated image
+ readBytes = d->readLine(buf, buflen);
+ if (readBytes <= 0) // EOF ==> truncated image
break;
+ buf[readBytes] = '\0';
p = strstr( buf, "0x" );
}
}
@@ -5621,7 +5646,7 @@ static void write_xbm_image( QImageIO *iio )
}
}
int bcnt = 0;
- register char *p = buf;
+ char *p = buf;
int bpl = (w+7)/8;
for (int y = 0; y < h; ++y) {
uchar *b = image.scanLine(y);