| Ticket UUID: | a0241c0e257c3206d711ebfefbfaa76ff87bf18e | |||
| Title: | photo image copy command can unexpectedly hang for 20+ seconds | |||
| Type: | Bug | Version: | 8.6 | |
| Submitter: | dusthillresident | Created on: | 2024-06-07 22:04:24 | |
| Subsystem: | 41. Photo Images | Assigned To: | fvogel | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2024-06-09 12:39:08 | |
| Resolution: | Fixed | Closed By: | fvogel | |
| Closed on: | 2024-06-09 12:39:08 | |||
| Description: |
Hello, With Tcl/Tk 8.6.12 on Linux and Windows (the latest version I have access to on both systems at the moment), with the 'photo' images, some image copy commands including both -to and -from options can hang up for very long amounts of time, up to 40 seconds on my system (Ryzen 5 3600, not a slow computer). It looks like it might be caused by out of bounds values being passed to the -from option. Expectation: If the values passed to the options are incorrect, it should fail and raise an error, rather than attempt to do something that doesn't make sense and hang up for ~40 seconds. Further details: I am able to replicate it very reliably, but I'm not precisely sure what the trigger is. I feel like it seems to have something to do with the -from option with x,y values that are out of bounds (larger than the dimensions of the source image) but I am unsure. Here is a test harness program that (on my system and in my testing) replicates the behaviour very reliably. Click and hold in the box, and slowly drag your mouse to the left, and then the app should freeze up, and after ~40 seconds, you should see a message in the terminal reporting how many microseconds it was hung up for.
| |||
| User Comments: |
fvogel added on 2024-06-09 12:39:08:
Merged. fvogel added on 2024-06-08 09:10:13: Now done. This is the correct fix, the code was checking twice the same thing by error. fvogel added on 2024-06-08 09:00:56: An alternative would be to refine the check here and spit the adequate error. That would be better, I'll have a look. fvogel added on 2024-06-08 08:52:41: I have added a new test, [25c8602c|imgPhoto-12.5], demonstrating the problem. What is happening is that the programmer tries to copy a photo image into another photo image, and the area to copy is outside the limits of the source image. The code does not detect this case, and computes and passes a negative block.width (or block.height) to Tk_PhotoPutZoomedBlock(). Tk_PhotoPutZoomedBlock() in turn transfers this negative width/height to Tk_PhotoPutBlock(). Then, Tk_PhotoPutBlock() iterates on, say, the width with a negative value. This loop has to span the entire range of an int until wLeft overflows, becomes negative and ends the loop! A piece of art...! So the fix is to not allow this to happen, see [dbd79c00]. Since there is no point in copying from an area outside the limits of the source image, let's just silently do nothing, exactly the same way [3078902] was fixed for zero-sized width/height. With this change the new test passes in no time, of course. fvogel added on 2024-06-08 07:21:37: Thanks for this high quality bug report! I can reproduce indeed. The code loops for a very long time in Tk_PhotoPutBlock(). A shorter example script is: package require Tk image create photo ball -width 20 -height 20 image create photo testimg -width 150 -height 150 set tempimg [image create photo -width 9 -height 20] $tempimg copy ball testimg copy $tempimg -to 0 72 9 92 -from 11 0 ; # very long | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki