Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/image/qxbmhandler.cpp

    r651 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 201 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation ([email protected])
     
    6767{
    6868    const int buflen = 300;
     69
    6970    char buf[buflen + 1];
    7071    QRegExp r1(QLatin1String("^#define[ \t]+[a-zA-Z0-9._]+[ \t]+"));
     
    7273
    7374    qint64 readBytes = 0;
    74 
    75     // "#define .._width <num>"
    76     readBytes = device->readLine(buf, buflen);
    77     if (readBytes <= 0)
    78         return false;
    79     buf[readBytes - 1] = '\0';
     75    qint64 totalReadBytes = 0;
     76
     77    buf[0] = '\0';
    8078
    8179    // skip initial comment, if any
    82     while (buf[0] != '#' && (readBytes = device->readLine( buf, buflen )) > 0) {}
    83 
    84     if (readBytes <= 0)
    85         return false;
     80    while (buf[0] != '#') {
     81        readBytes = device->readLine(buf, buflen);
     82
     83        // if readBytes >= buflen, it's very probably not a C file
     84        if (readBytes <= 0 || readBytes >= buflen -1)
     85            return false;
     86
     87        // limit xbm headers to the first 4k in the file to prevent
     88        // excessive reads on non-xbm files
     89        totalReadBytes += readBytes;
     90        if (totalReadBytes >= maxlen)
     91            return false;
     92    }
     93
    8694    buf[readBytes - 1] = '\0';
    8795    QString sbuf;
    8896    sbuf = QString::fromLatin1(buf);
    8997
     98
    9099    if (r1.indexIn(sbuf) == 0 &&
    91100         r2.indexIn(sbuf, r1.matchedLength()) == r1.matchedLength())
     
    262271bool QXbmHandler::canRead() const
    263272{
    264     if (state == Ready) {
    265         if (!canRead(device()))
    266             return false;
     273    if (state == Ready && !canRead(device()))
     274        return false;
     275
     276    if (state != Error) {
    267277        setFormat("xbm");
    268278        return true;
    269279    }
    270     return state != Error;
     280
     281    return false;
    271282}
    272283
Note: See TracChangeset for help on using the changeset viewer.