Skip to content

Commit

Permalink
Update libpng from Chromium 114.0.5735.358
Browse files Browse the repository at this point in the history
Issue: 326748668
Reviewed-on: #3155
  • Loading branch information
dahlstrom-g authored May 5, 2024
2 parents d7a1523 + 74fb31d commit 38d4e2b
Show file tree
Hide file tree
Showing 52 changed files with 32,389 additions and 16,736 deletions.
10 changes: 5 additions & 5 deletions cobalt/loader/image/png_image_decoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ uint32 FixPointUnsignedMultiply(uint32 fixed, uint32 alpha) {
// static
void DecodingFailed(png_structp png, png_const_charp) {
DLOG(WARNING) << "Decoding failed.";
longjmp(png->jmpbuf, 1);
longjmp(png_jmpbuf(png), 1);
}

// static
Expand Down Expand Up @@ -99,7 +99,7 @@ size_t PNGImageDecoder::DecodeChunkInternal(const uint8* data, size_t size) {
MSVC_PUSH_DISABLE_WARNING(4611);
// warning C4611: interaction between '_setjmp' and C++ object destruction is
// non-portable.
if (setjmp(png_->jmpbuf)) {
if (setjmp(png_jmpbuf(png_))) {
// image data is empty.
DLOG(WARNING) << "Decoder encounters an error.";
set_state(kError);
Expand Down Expand Up @@ -181,7 +181,7 @@ void PNGImageDecoder::HeaderAvailableCallback() {
DLOG(WARNING) << "Large PNG with width: " << width
<< ", height: " << height;
set_state(kError);
longjmp(png_->jmpbuf, 1);
longjmp(png_jmpbuf(png_), 1);
return;
}

Expand Down Expand Up @@ -251,7 +251,7 @@ void PNGImageDecoder::HeaderAvailableCallback() {
if (!interlace_buffer_) {
DLOG(WARNING) << "Allocate interlace buffer failed.";
set_state(kError);
longjmp(png_->jmpbuf, 1);
longjmp(png_jmpbuf(png_), 1);
return;
}
}
Expand All @@ -261,7 +261,7 @@ void PNGImageDecoder::HeaderAvailableCallback() {
has_alpha_);
if (!decoded_image_data_) {
set_state(kError);
longjmp(png_->jmpbuf, 1);
longjmp(png_jmpbuf(png_), 1);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion cobalt/renderer/test/png_utils/png_decode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ PNGFileReadContext::PNGFileReadContext(const base::FilePath& file_path,
// will not be called. This is fine though, since we abort upon errors here.
// If alternative behavior is desired, custom error and warning handler
// functions can be passed into the png_create_read_struct() call above.
if (setjmp(png_->jmpbuf)) {
if (setjmp(png_jmpbuf(png_))) {
LOG(FATAL) << "libpng returned error reading " << file_path.value();
}

Expand Down
2 changes: 1 addition & 1 deletion cobalt/renderer/test/png_utils/png_encode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ std::unique_ptr<uint8[]> EncodeRGBAToBuffer(const uint8_t* pixel_data,
// if error encountered png will call longjmp(), so we set up a setjmp() here
// with a failed assert to indicate an error in one of the png functions.
// yo libpng, 1980 called, they want their longjmp() back....
if (setjmp(png->jmpbuf)) {
if (setjmp(png_jmpbuf(png))) {
png_destroy_write_struct(&png, &info);
NOTREACHED() << "libpng encountered an error during processing.";
return std::unique_ptr<uint8[]>();
Expand Down
109 changes: 74 additions & 35 deletions third_party/libpng/BUILD.gn
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
# Copyright 2014 The Chromium Authors. All rights reserved.
# Copyright 2014 The Chromium Authors
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

config("libpng_config") {
include_dirs = [ "." ]
import("//build/config/arm.gni")
import("//build/config/chromecast_build.gni")
import("//build/config/mips.gni")

defines = [
"CHROME_PNG_WRITE_SUPPORT",
"PNG_USER_CONFIG",
]
if (build_with_chromium) {
import("//testing/libfuzzer/fuzzer_test.gni")
}

if (is_starboard) {
defines += [ "CHROME_PNG_READ_PACK_SUPPORT" ] # Required by freetype.
defines += [ "PNG_SKIP_SETJMP_CHECK" ]
}
config("libpng_config") {
include_dirs = [ "." ]

if (is_android) {
#'toolsets': ['target', 'host'],
defines += [ "CHROME_PNG_READ_PACK_SUPPORT" ] # Required by freetype.
}
defines = []

if (is_win) {
if (is_component_build) {
Expand All @@ -34,68 +29,112 @@ config("libpng_config") {
# appear after this, and turn it back on).
config("clang_warnings") {
if (is_clang) {
# Upstream uses self-assignment to avoid warnings.
cflags = [ "-Wno-self-assign" ]
cflags = [
# libpng checks that the width is not greater than PNG_SIZE_MAX.
# On platforms where size_t is 64-bits, this comparison will always
# be false.
"-Wno-tautological-constant-out-of-range-compare",
]
}
}

# Cannot be a static_library in component builds
source_set("libpng_sources") {
sources = [
"png.c",
"png.h",
"pngconf.h",
"pngdebug.h",
"pngerror.c",
"pnggccrd.c",
"pngget.c",
"pnginfo.h",
"pnglibconf.h",
"pngmem.c",
"pngpread.c",
"pngpriv.h",
"pngread.c",
"pngrio.c",
"pngrtran.c",
"pngrutil.c",
"pngset.c",
"pngstruct.h",
"pngtrans.c",
"pngusr.h",
"pngvcrd.c",
"pngwio.c",
"pngwrite.c",
"pngwtran.c",
"pngwutil.c",
]

defines = [ "PNG_SET_OPTION_SUPPORTED" ]
cflags = []

if (current_cpu == "x86" || current_cpu == "x64") {
sources += [
"intel/filter_sse2_intrinsics.c",
"intel/intel_init.c",
]
defines += [ "PNG_INTEL_SSE_OPT=1" ]
} else if ((current_cpu == "arm" || current_cpu == "arm64") && arm_use_neon) {
sources += [
"arm/arm_init.c",
"arm/filter_neon_intrinsics.c",
"arm/palette_neon_intrinsics.c",
]
if (!is_starboard) {
defines += [
"PNG_ARM_NEON_OPT=2",
"PNG_ARM_NEON_IMPLEMENTATION=1",
]
}
configs -= [ "//build/config/compiler:default_optimization" ]
configs += [ "//build/config/compiler:optimize_speed" ]
} else if (current_cpu == "mips64el" && mips_use_msa) {
sources += [
"mips/filter_msa_intrinsics.c",
"mips/mips_init.c",
]
}

configs -= [ "//build/config/compiler:chromium_code" ]
configs += [ "//build/config/compiler:no_chromium_code" ]
}

if (is_win && is_component_build) {
defines = [ "PNG_BUILD_DLL" ]
if (is_win) {
# Unary minus applied to unsigned type.
cflags += [ "/wd4146" ]
}

if (is_starboard) {
configs -= [ "//starboard/build/config:size" ]
configs += [ "//starboard/build/config:speed" ]
if (is_win && is_component_build) {
defines += [ "PNG_BUILD_DLL" ]
}

public_configs = [ ":libpng_config" ]

public_deps = [
"//third_party/zlib",
]
public_deps = [ "//third_party/zlib" ]

configs += [ ":clang_warnings" ]
}

if (is_win) {
component("libpng") {
public_deps = [
":libpng_sources",
]
public_deps = [ ":libpng_sources" ]
}
} else {
group("libpng") {
public_deps = [
":libpng_sources",
]
public_deps = [ ":libpng_sources" ]
}
}

if (build_with_chromium) {
libpng_ossfuzz_seed_corpuses = [
"//components/test/data/viz",
"//third_party/blink/web_tests/images/png-suite/samples",
"//third_party/blink/web_tests/images/resources/pngfuzz",
]

fuzzer_test("libpng_read_fuzzer") {
sources = [ "contrib/oss-fuzz/libpng_read_fuzzer.cc" ]
deps = [ ":libpng" ]
dict = "contrib/oss-fuzz/png.dict"
seed_corpuses = libpng_ossfuzz_seed_corpuses
}
}
4 changes: 4 additions & 0 deletions third_party/libpng/DIR_METADATA
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
monorail: {
component: "Internals>Images>Codecs"
}
team_email: "[email protected]"
Loading

0 comments on commit 38d4e2b

Please sign in to comment.