Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: src/images/SkImageDecoder_libpng.cpp

Issue 951663002: Fix a memory leak when decoding corrupted indexed PNGs. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Disable test on platforms that don't use libpng Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "SkImageDecoder.h" 8 #include "SkImageDecoder.h"
9 #include "SkImageEncoder.h" 9 #include "SkImageEncoder.h"
10 #include "SkColor.h" 10 #include "SkColor.h"
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 355
356 SkAutoUnref aur(colorTable); 356 SkAutoUnref aur(colorTable);
357 357
358 if (!this->allocPixelRef(decodedBitmap, 358 if (!this->allocPixelRef(decodedBitmap,
359 kIndex_8_SkColorType == colorType ? colorTable : NU LL)) { 359 kIndex_8_SkColorType == colorType ? colorTable : NU LL)) {
360 return kFailure; 360 return kFailure;
361 } 361 }
362 362
363 SkAutoLockPixels alp(*decodedBitmap); 363 SkAutoLockPixels alp(*decodedBitmap);
364 364
365 // Repeat setjmp, otherwise variables declared since the last call (e.g. alp
366 // and aur) won't get their destructors called in case of a failure.
367 if (setjmp(png_jmpbuf(png_ptr))) {
368 return kFailure;
369 }
370
365 /* Turn on interlace handling. REQUIRED if you are not using 371 /* Turn on interlace handling. REQUIRED if you are not using
366 * png_read_image(). To see how to handle interlacing passes, 372 * png_read_image(). To see how to handle interlacing passes,
367 * see the png_read_row() method below: 373 * see the png_read_row() method below:
368 */ 374 */
369 const int number_passes = (interlaceType != PNG_INTERLACE_NONE) ? 375 const int number_passes = (interlaceType != PNG_INTERLACE_NONE) ?
370 png_set_interlace_handling(png_ptr) : 1; 376 png_set_interlace_handling(png_ptr) : 1;
371 377
372 /* Optional call to gamma correct and add the background to the palette 378 /* Optional call to gamma correct and add the background to the palette
373 * and update info structure. REQUIRED if you are expecting libpng to 379 * and update info structure. REQUIRED if you are expecting libpng to
374 * update the palette for you (ie you selected such a transform above). 380 * update the palette for you (ie you selected such a transform above).
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
1270 return SkImageDecoder::kUnknown_Format; 1276 return SkImageDecoder::kUnknown_Format;
1271 } 1277 }
1272 1278
1273 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) { 1279 SkImageEncoder* sk_libpng_efactory(SkImageEncoder::Type t) {
1274 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL; 1280 return (SkImageEncoder::kPNG_Type == t) ? SkNEW(SkPNGImageEncoder) : NULL;
1275 } 1281 }
1276 1282
1277 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory); 1283 static SkImageDecoder_DecodeReg gDReg(sk_libpng_dfactory);
1278 static SkImageDecoder_FormatReg gFormatReg(get_format_png); 1284 static SkImageDecoder_FormatReg gFormatReg(get_format_png);
1279 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory); 1285 static SkImageEncoder_EncodeReg gEReg(sk_libpng_efactory);
OLDNEW
« no previous file with comments | « gyp/tests.gypi ('k') | tests/InvalidIndexedPngTest.cpp » ('j') | tests/InvalidIndexedPngTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698