VirtualBox

Ignore:
Timestamp:
Feb 12, 2024 3:57:56 PM (12 months ago)
Author:
vboxsync
Message:

libpng-1.6.42: Applied and adjusted our libpng changes to 1.6.42. bugref:8515

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/libs/libpng-1.6.42/contrib/oss-fuzz/libpng_read_fuzzer.cc

    r96425 r103316  
    55// Use of this source code is governed by a BSD-style license that may
    66// 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]
    97
    108// The modifications in 2017 by Glenn Randers-Pehrson include
     
    1816#include <stddef.h>
    1917#include <stdint.h>
     18#include <stdlib.h>
    2019#include <string.h>
    2120
     
    6160    if (end_info_ptr)
    6261      png_destroy_read_struct(&png_ptr, &info_ptr, &end_info_ptr);
    63     else if (info_ptr) 
     62    else if (info_ptr)
    6463      png_destroy_read_struct(&png_ptr, &info_ptr, nullptr);
    6564    else
     
    7776  buf_state->bytes_left -= length;
    7877  buf_state->data += length;
     78}
     79
     80void* 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
     92void default_free(png_structp, png_voidp ptr) {
     93  return free(ptr);
    7994}
    8095
     
    118133    return 0;
    119134  }
     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);
    120138
    121139  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.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette