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

Side by Side Diff: testing/libfuzzer/fuzzers/libpng_read_fuzzer.cc

Issue 1808123004: [libfuzzer] Add a sanity check for too big images in libpng_read_fuzzer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 buf_state->data = data + kPngHeaderSize; 63 buf_state->data = data + kPngHeaderSize;
64 buf_state->bytes_left = size - kPngHeaderSize; 64 buf_state->bytes_left = size - kPngHeaderSize;
65 png_set_read_fn(png_ptr, buf_state.get(), user_read_data); 65 png_set_read_fn(png_ptr, buf_state.get(), user_read_data);
66 png_set_sig_bytes(png_ptr, kPngHeaderSize); 66 png_set_sig_bytes(png_ptr, kPngHeaderSize);
67 67
68 // libpng error handling. 68 // libpng error handling.
69 if (setjmp(png_ptr->jmpbuf)) { 69 if (setjmp(png_ptr->jmpbuf)) {
70 return 0; 70 return 0;
71 } 71 }
72 72
73 // Reading 73 // Reading.
74 png_read_info(png_ptr, info_ptr); 74 png_read_info(png_ptr, info_ptr);
75 png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr)); 75 png_voidp row = png_malloc(png_ptr, png_get_rowbytes(png_ptr, info_ptr));
76 base::ScopedClosureRunner png_deleter(base::Bind( 76 base::ScopedClosureRunner png_deleter(base::Bind(
77 &png_free, png_ptr, row)); 77 &png_free, png_ptr, row));
78 78
79 // reset error handler to put png_deleter into scope. 79 // reset error handler to put png_deleter into scope.
80 if (setjmp(png_ptr->jmpbuf)) { 80 if (setjmp(png_ptr->jmpbuf)) {
81 return 0; 81 return 0;
82 } 82 }
83 83
84 png_uint_32 width, height; 84 png_uint_32 width, height;
85 int bit_depth, color_type, interlace_type, compression_type; 85 int bit_depth, color_type, interlace_type, compression_type;
86 int filter_type; 86 int filter_type;
87 87
88 if (!png_get_IHDR(png_ptr, info_ptr, &width, &height, 88 if (!png_get_IHDR(png_ptr, info_ptr, &width, &height,
89 &bit_depth, &color_type, &interlace_type, 89 &bit_depth, &color_type, &interlace_type,
90 &compression_type, &filter_type)) { 90 &compression_type, &filter_type)) {
91 return 0; 91 return 0;
92 } 92 }
93 93
94 // This is going to be too slow.
95 if (height * width > 100000000)
krasin 2016/03/17 17:02:48 what if height * width overflow?
96 return 0;
97
94 int passes = png_set_interlace_handling(png_ptr); 98 int passes = png_set_interlace_handling(png_ptr);
95 png_start_read_image(png_ptr); 99 png_start_read_image(png_ptr);
96 100
97 for (int pass = 0; pass < passes; ++pass) { 101 for (int pass = 0; pass < passes; ++pass) {
98 for (png_uint_32 y = 0; y < height; ++y) { 102 for (png_uint_32 y = 0; y < height; ++y) {
99 png_read_row(png_ptr, static_cast<png_bytep>(row), NULL); 103 png_read_row(png_ptr, static_cast<png_bytep>(row), NULL);
100 } 104 }
101 } 105 }
102 106
103 return 0; 107 return 0;
104 } 108 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698