From 2ded3a46db6cf1e60c673181d54276f702074020 Mon Sep 17 00:00:00 2001 From: Eugene Kliuchnikov Date: Fri, 26 Jun 2026 11:24:49 +0200 Subject: Fix possible overflow in APNG decoder (#4870) Fixes #4803. Root reason: copy-paste in RectT::IsSame Drive-by: use a.IsInside(b) instead of a.Intersect(b).IsSame(a) Drive-by: harden ysize check before copying --- lib/extras/dec/apng.cc | 3 ++- lib/jxl/base/rect.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/extras/dec/apng.cc b/lib/extras/dec/apng.cc index 24b4795d..a8c5c5f3 100644 --- a/lib/extras/dec/apng.cc +++ b/lib/extras/dec/apng.cc @@ -878,6 +878,7 @@ Status DecodeImageAPNG(const Span bytes, const RectT& vp = current_frame.viewport; size_t xsize = static_cast(vp.xsize()); size_t ysize = static_cast(vp.ysize()); + JXL_ENSURE(ctx.frameRaw.rows.size() <= ysize); JXL_ASSIGN_OR_RETURN(PackedImage image, PackedImage::Create(xsize, ysize, format)); for (size_t y = 0; y < ysize; ++y) { @@ -962,7 +963,7 @@ Status DecodeImageAPNG(const Span bytes, /*delay_den=*/png_get_uint_16(payload.data() + 22), raw_viewport, static_cast(dispose_op), static_cast(blend_op)}; - if (!raw_viewport.Intersection(image_rect).IsSame(raw_viewport)) { + if (!raw_viewport.IsInside(image_rect)) { // Cropping happened. return JXL_FAILURE("PNG frame is outside of image rect"); } diff --git a/lib/jxl/base/rect.h b/lib/jxl/base/rect.h index 31fe12df..3f6632ed 100644 --- a/lib/jxl/base/rect.h +++ b/lib/jxl/base/rect.h @@ -109,7 +109,7 @@ class RectT { bool IsSame(const RectT& other) const { return x0_ == other.x0_ && xsize_ == other.xsize_ && y0_ == other.y0_ && - ysize_ <= other.ysize_; + ysize_ == other.ysize_; } // Returns true if this Rect fully resides in the given image. ImageT could be -- 2.47.3