Changeset 103316 in vbox for trunk/src/libs/libpng-1.6.42/contrib/oss-fuzz/libpng_read_fuzzer.cc
- Timestamp:
- Feb 12, 2024 3:57:56 PM (12 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/libs/libpng-1.6.42/contrib/oss-fuzz/libpng_read_fuzzer.cc
r96425 r103316 5 5 // Use of this source code is governed by a BSD-style license that may 6 6 // be found in the LICENSE file https://cs.chromium.org/chromium/src/LICENSE 7 8 // Last changed in libpng 1.6.35 [July 15, 2018]9 7 10 8 // The modifications in 2017 by Glenn Randers-Pehrson include … … 18 16 #include <stddef.h> 19 17 #include <stdint.h> 18 #include <stdlib.h> 20 19 #include <string.h> 21 20 … … 61 60 if (end_info_ptr) 62 61 png_destroy_read_struct(&png_ptr, &info_ptr, &end_info_ptr); 63 else if (info_ptr) 62 else if (info_ptr) 64 63 png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); 65 64 else … … 77 76 buf_state->bytes_left -= length; 78 77 buf_state->data += length; 78 } 79 80 void* limited_malloc(png_structp, png_alloc_size_t size) { 81 // libpng may allocate large amounts of memory that the fuzzer reports as 82 // an error. In order to silence these errors, make libpng fail when trying 83 // to allocate a large amount. This allocator used to be in the Chromium 84 // version of this fuzzer. 85 // This number is chosen to match the default png_user_chunk_malloc_max. 86 if (size > 8000000) 87 return nullptr; 88 89 return malloc(size); 90 } 91 92 void default_free(png_structp, png_voidp ptr) { 93 return free(ptr); 79 94 } 80 95 … … 118 133 return 0; 119 134 } 135 136 // Use a custom allocator that fails for large allocations to avoid OOM. 137 png_set_mem_fn(png_handler.png_ptr, nullptr, limited_malloc, default_free); 120 138 121 139 png_set_crc_action(png_handler.png_ptr, PNG_CRC_QUIET_USE, PNG_CRC_QUIET_USE);
Note:
See TracChangeset
for help on using the changeset viewer.