bug664.patch

Andreas Huggel, 28 Dec 2009 18:43

Download (8.98 KB)

View differences:

trunk-bug664/src/pngchunk.cpp 2009-12-29 10:17:19.000000000 +0800
103 103
        std::cout << "Exiv2::PngChunk::decodeTXTChunk: TXT chunk data: "
104 104
                  << std::string((const char*)arr.pData_, 32) << "\n";
105 105
#endif
106
        parseChunkContent(pImage, key.pData_, arr);
106
        parseChunkContent(pImage, key.pData_, key.size_, arr);
107 107

  
108 108
    } // PngChunk::decodeTXTChunk
109 109

  
......
111 111
    {
112 112
        // From a tEXt, zTXt, or iTXt chunk,
113 113
        // we get the key, it's a null terminated string at the chunk start
114

  
114
        if (data.size_ <= (stripHeader ? 8 : 0)) throw Error(14);
115 115
        const byte *key = data.pData_ + (stripHeader ? 8 : 0);
116 116

  
117 117
        // Find null string at end of key.
......
162 162
            const byte* text = data.pData_ + keysize + 1;
163 163
            long textsize    = data.size_  - keysize - 1;
164 164

  
165
            arr.alloc(textsize);
166 165
            arr = DataBuf(text, textsize);
167 166
        }
168 167
        else if(type == iTXt_Chunk)
......
228 227

  
229 228
    } // PngChunk::parsePngChunk
230 229

  
231
    void PngChunk::parseChunkContent(Image* pImage, const byte *key, const DataBuf arr)
230
    void PngChunk::parseChunkContent(      Image*  pImage,
231
                                     const byte*   key,
232
                                           long    keySize,
233
                                     const DataBuf arr)
232 234
    {
233 235
        // We look if an ImageMagick EXIF raw profile exist.
234 236

  
235
        if ( (memcmp("Raw profile type exif", key, 21) == 0 ||
236
              memcmp("Raw profile type APP1", key, 21) == 0) &&
237
             pImage->exifData().empty())
237
        if (   keySize >= 21 
238
            && (   memcmp("Raw profile type exif", key, 21) == 0
239
                || memcmp("Raw profile type APP1", key, 21) == 0)
240
            && pImage->exifData().empty())
238 241
        {
239 242
            DataBuf exifData = readRawProfile(arr);
240 243
            long length      = exifData.size_;
......
282 285

  
283 286
        // We look if an ImageMagick IPTC raw profile exist.
284 287

  
285
        if (   memcmp("Raw profile type iptc", key, 21) == 0
288
        if (   keySize >= 21
289
            && memcmp("Raw profile type iptc", key, 21) == 0
286 290
            && pImage->iptcData().empty()) {
287 291
            DataBuf psData = readRawProfile(arr);
288 292
            if (psData.size_ > 0) {
......
332 336

  
333 337
        // We look if an ImageMagick XMP raw profile exist.
334 338

  
335
        if ( memcmp("Raw profile type xmp", key, 20) == 0 &&
336
             pImage->xmpData().empty())
339
        if (   keySize >= 20
340
            && memcmp("Raw profile type xmp", key, 20) == 0
341
            && pImage->xmpData().empty()) 
337 342
        {
338 343
            DataBuf xmpBuf = readRawProfile(arr);
339 344
            long length    = xmpBuf.size_;
......
362 367

  
363 368
        // We look if an Adobe XMP string exist.
364 369

  
365
        if ( memcmp("XML:com.adobe.xmp", key, 17) == 0 &&
366
             pImage->xmpData().empty())
370
        if (   keySize >= 17
371
            && memcmp("XML:com.adobe.xmp", key, 17) == 0
372
            && pImage->xmpData().empty())
367 373
        {
368 374
            if (arr.size_ > 0)
369 375
            {
......
390 396
        // We look if a comments string exist. Note than we use only 'Description' keyword which
391 397
        // is dedicaced to store long comments. 'Comment' keyword is ignored.
392 398

  
393
        if ( memcmp("Description", key, 11) == 0 &&
394
             pImage->comment().empty())
399
        if (   keySize >= 11
400
            && memcmp("Description", key, 11) == 0
401
            && pImage->comment().empty())
395 402
        {
396 403
            pImage->comment().assign(reinterpret_cast<char*>(arr.pData_), arr.size_);
397 404
        }
trunk-bug664/src/pngchunk_int.hpp 2009-12-29 10:16:40.000000000 +0800
134 134
                    Xmp  packet generated by Adobe                 ==> Image Xmp metadata.
135 135
                    Description string                             ==> Image Comments.
136 136
         */
137
        static void parseChunkContent(Image*        pImage,
137
        static void parseChunkContent(      Image*  pImage,
138 138
                                      const byte*   key,
139
                                            long    keySize,
139 140
                                      const DataBuf arr);
140 141

  
141 142
        /*!
trunk-bug664/src/pngimage.cpp 2009-12-29 10:34:48.000000000 +0800
132 132
            if (io_->error()) throw Error(14);
133 133
            if (bufRead != cheaderBuf.size_) throw Error(20);
134 134

  
135
#ifdef DEBUG
136
            std::cout << "Exiv2::PngImage::readMetadata: Next Chunk: " << cheaderBuf.pData_ + 4 << "\n";
137
#endif
138 135
            // Decode chunk data length.
139

  
140 136
            uint32_t dataOffset = Exiv2::getULong(cheaderBuf.pData_, Exiv2::bigEndian);
141 137
            if (dataOffset > 0x7FFFFFFF) throw Exiv2::Error(14);
142 138

  
......
159 155
                {
160 156
                    // Last chunk found: we stop parsing.
161 157
#ifdef DEBUG
162
                    std::cout << "Exiv2::PngImage::readMetadata: Found IEND chunk (lenght: " << dataOffset << ")\n";
158
                    std::cout << "Exiv2::PngImage::readMetadata: Found IEND chunk (length: " << dataOffset << ")\n";
163 159
#endif
164 160
                    return;
165 161
                }
166 162
                else if (!memcmp(cheaderBuf.pData_ + 4, "IHDR", 4))
167 163
                {
168 164
#ifdef DEBUG
169
                    std::cout << "Exiv2::PngImage::readMetadata: Found IHDR chunk (lenght: " << dataOffset << ")\n";
165
                    std::cout << "Exiv2::PngImage::readMetadata: Found IHDR chunk (length: " << dataOffset << ")\n";
170 166
#endif
171 167
                    PngChunk::decodeIHDRChunk(cdataBuf, &pixelWidth_, &pixelHeight_);
172 168
                }
173 169
                else if (!memcmp(cheaderBuf.pData_ + 4, "tEXt", 4))
174 170
                {
175 171
#ifdef DEBUG
176
                    std::cout << "Exiv2::PngImage::readMetadata: Found tEXt chunk (lenght: " << dataOffset << ")\n";
172
                    std::cout << "Exiv2::PngImage::readMetadata: Found tEXt chunk (length: " << dataOffset << ")\n";
177 173
#endif
178 174
                    PngChunk::decodeTXTChunk(this, cdataBuf, PngChunk::tEXt_Chunk);
179 175
                }
180 176
                else if (!memcmp(cheaderBuf.pData_ + 4, "zTXt", 4))
181 177
                {
182 178
#ifdef DEBUG
183
                    std::cout << "Exiv2::PngImage::readMetadata: Found zTXt chunk (lenght: " << dataOffset << ")\n";
179
                    std::cout << "Exiv2::PngImage::readMetadata: Found zTXt chunk (length: " << dataOffset << ")\n";
184 180
#endif
185 181
                    PngChunk::decodeTXTChunk(this, cdataBuf, PngChunk::zTXt_Chunk);
186 182
                }
187 183
                else if (!memcmp(cheaderBuf.pData_ + 4, "iTXt", 4))
188 184
                {
189 185
#ifdef DEBUG
190
                    std::cout << "Exiv2::PngImage::readMetadata: Found iTXt chunk (lenght: " << dataOffset << ")\n";
186
                    std::cout << "Exiv2::PngImage::readMetadata: Found iTXt chunk (length: " << dataOffset << ")\n";
191 187
#endif
192 188
                    PngChunk::decodeTXTChunk(this, cdataBuf, PngChunk::iTXt_Chunk);
193 189
                }
......
270 266
            {
271 267
                // Last chunk found: we write it and done.
272 268
#ifdef DEBUG
273
                std::cout << "Exiv2::PngImage::doWriteMetadata: Write IEND chunk (lenght: " << dataOffset << ")\n";
269
                std::cout << "Exiv2::PngImage::doWriteMetadata: Write IEND chunk (length: " << dataOffset << ")\n";
274 270
#endif
275 271
                if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21);
276 272
                return;
......
278 274
            else if (!memcmp(cheaderBuf.pData_ + 4, "IHDR", 4))
279 275
            {
280 276
#ifdef DEBUG
281
                std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (lenght: " << dataOffset << ")\n";
277
                std::cout << "Exiv2::PngImage::doWriteMetadata: Write IHDR chunk (length: " << dataOffset << ")\n";
282 278
#endif
283 279
                if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21);
284 280

  
......
362 358
                {
363 359
#ifdef DEBUG
364 360
                    std::cout << "Exiv2::PngImage::doWriteMetadata: write " << cheaderBuf.pData_ + 4
365
                              << " chunk (lenght: " << dataOffset << ")\n";
361
                              << " chunk (length: " << dataOffset << ")\n";
366 362
#endif
367 363
                    if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21);
368 364
                }
......
372 368
                // Write all others chunk as well.
373 369
#ifdef DEBUG
374 370
                std::cout << "Exiv2::PngImage::doWriteMetadata: write " << cheaderBuf.pData_ + 4
375
                          << " chunk (lenght: " << dataOffset << ")\n";
371
                          << " chunk (length: " << dataOffset << ")\n";
376 372
#endif
377 373
                if (outIo.write(chunkBuf.pData_, chunkBuf.size_) != chunkBuf.size_) throw Error(21);
378 374

  
Redmine Appliance - Powered by TurnKey Linux