From dd00d32a89426c4c9b36774dec3dbe026c069158 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 8 Jun 2024 08:36:50 +0000 Subject: Add test imgPhoto-12.5 demonstrating bug [a0241c0e25]. --- tests/imgPhoto.test | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/imgPhoto.test b/tests/imgPhoto.test index 1d3b6e5..c006775 100644 --- a/tests/imgPhoto.test +++ b/tests/imgPhoto.test @@ -1054,6 +1054,17 @@ test imgPhoto-12.4 {Tk_ImgPhotoPutZoomedBlock, empty image} -setup { } -cleanup { imageCleanup } -result {0 0} +test imgPhoto-12.5 {Tk_ImgPhotoPutZoomedBlock, copy from area outside the image, bug [a0241c0e25]} -setup { + imageCleanup +} -body { + image create photo photo1 -width 20 -height 20 + image create photo photo2 -width 9 -height 10 + # next line used to loop for a very long time; if the bug is present + # the CI runner will time out, leading to test suite failure + photo2 copy photo1 -to 0 5 3 8 -from 21 0 +} -cleanup { + imageCleanup +} test imgPhoto-13.1 {check separation of images in different interpreters} -setup { imageCleanup -- cgit v0.12 From 9e67b3bff485409680adc5c89f47fe54adcc457b Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 8 Jun 2024 08:37:20 +0000 Subject: Fix [a0241c0e25]: photo image copy command can unexpectedly hang for 20+ seconds. --- generic/tkImgPhoto.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index cadbb2d..9c5f91c 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -3173,7 +3173,7 @@ Tk_PhotoPutZoomedBlock( * Zero-sized blocks never cause any changes. [Bug 3078902] */ - if (blockPtr->height == 0 || blockPtr->width == 0) { + if (blockPtr->height <= 0 || blockPtr->width <= 0) { return TCL_OK; } -- cgit v0.12 From 249fc690380f4cb9524794298a86a314ee4d53a5 Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 8 Jun 2024 08:54:50 +0000 Subject: Add explanatory comment. --- generic/tkImgPhoto.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index 9c5f91c..61d1c9b 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -3171,6 +3171,8 @@ Tk_PhotoPutZoomedBlock( /* * Zero-sized blocks never cause any changes. [Bug 3078902] + * Negative-size blocks happen when trying to copy from an area outside + * the source image. [Bug a0241c0e25] */ if (blockPtr->height <= 0 || blockPtr->width <= 0) { -- cgit v0.12 From 9b6c43c2c577b2b086822e8c98bb2a2b4c5b852a Mon Sep 17 00:00:00 2001 From: fvogel Date: Sat, 8 Jun 2024 09:07:18 +0000 Subject: Better fix for [a0241c0e25]. The checks for coordinates outside of the source image were incorrect. --- generic/tkImgPhoto.c | 6 ++---- tests/imgPhoto.test | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index 61d1c9b..e619910 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -577,7 +577,7 @@ ImgPhotoCmd( return TCL_ERROR; } Tk_PhotoGetImage(srcHandle, &block); - if ((options.fromX2 > block.width) || (options.fromY2 > block.height) + if ((options.fromX > block.width) || (options.fromY > block.height) || (options.fromX2 > block.width) || (options.fromY2 > block.height)) { Tcl_SetObjResult(interp, Tcl_NewStringObj( @@ -3171,11 +3171,9 @@ Tk_PhotoPutZoomedBlock( /* * Zero-sized blocks never cause any changes. [Bug 3078902] - * Negative-size blocks happen when trying to copy from an area outside - * the source image. [Bug a0241c0e25] */ - if (blockPtr->height <= 0 || blockPtr->width <= 0) { + if (blockPtr->height == 0 || blockPtr->width == 0) { return TCL_OK; } diff --git a/tests/imgPhoto.test b/tests/imgPhoto.test index c006775..865e96c 100644 --- a/tests/imgPhoto.test +++ b/tests/imgPhoto.test @@ -1064,7 +1064,7 @@ test imgPhoto-12.5 {Tk_ImgPhotoPutZoomedBlock, copy from area outside the image, photo2 copy photo1 -to 0 5 3 8 -from 21 0 } -cleanup { imageCleanup -} +} -returnCodes error -result {coordinates for -from option extend outside source image} test imgPhoto-13.1 {check separation of images in different interpreters} -setup { imageCleanup -- cgit v0.12