diff --git a/lib/jxl/fields_test.cc b/lib/jxl/fields_test.cc index 50e3ac22122..c11b0523019 100644 --- a/lib/jxl/fields_test.cc +++ b/lib/jxl/fields_test.cc @@ -228,7 +228,7 @@ TEST(FieldsTest, TestRoundtripSize) { // Ensure all values can be reached by the encoding. TEST(FieldsTest, TestCropRect) { CodecMetadata metadata; - for (int32_t i = -1000; i < 19000; ++i) { + for (int32_t i = -999; i < 19000; ++i) { FrameHeader f(&metadata); f.custom_size_or_origin = true; f.frame_origin.x0 = i; diff --git a/lib/jxl/frame_header.cc b/lib/jxl/frame_header.cc index b08c351e81f..c2f6b26ae34 100644 --- a/lib/jxl/frame_header.cc +++ b/lib/jxl/frame_header.cc @@ -271,6 +271,11 @@ Status FrameHeader::VisitFields(Visitor* JXL_RESTRICT visitor) { // Frame size JXL_QUIET_RETURN_IF_ERROR(visitor->U32(enc, 0, &frame_size.xsize)); JXL_QUIET_RETURN_IF_ERROR(visitor->U32(enc, 0, &frame_size.ysize)); + if (custom_size_or_origin && + (frame_size.xsize == 0 || frame_size.ysize == 0)) { + return JXL_FAILURE( + "Invalid crop dimensions for frame: zero width or height"); + } int32_t image_xsize = default_xsize(); int32_t image_ysize = default_ysize(); if (frame_type == FrameType::kRegularFrame ||