diff options
author | fvogel <fvogelnew1@free.fr> | 2017-09-24 14:52:40 (GMT) |
---|---|---|
committer | fvogel <fvogelnew1@free.fr> | 2017-09-24 14:52:40 (GMT) |
commit | 8929e642afed819ec440118bd49de303443ad33b (patch) | |
tree | d7935acac51c778d3d3b69ec7a3d3fcd52289496 | |
parent | db26ea2e60aedecdc6ced529480fe23aee34841e (diff) | |
parent | 62847af89d0e7df4117135e9fbbcf30ef0546874 (diff) | |
download | tk-8929e642afed819ec440118bd49de303443ad33b.zip tk-8929e642afed819ec440118bd49de303443ad33b.tar.gz tk-8929e642afed819ec440118bd49de303443ad33b.tar.bz2 |
Fix [5239fd749b]: Segfault when copying a photo image to itself. Patch from Simon Bachmann.
-rw-r--r-- | generic/tkImgPhoto.c | 34 | ||||
-rw-r--r-- | tests/imgPhoto.test | 12 |
2 files changed, 32 insertions, 14 deletions
diff --git a/generic/tkImgPhoto.c b/generic/tkImgPhoto.c index 1fec208..cb46c41 100644 --- a/generic/tkImgPhoto.c +++ b/generic/tkImgPhoto.c @@ -625,7 +625,24 @@ ImgPhotoCmd( } /* + * Copy the image data over using Tk_PhotoPutZoomedBlock. + */ + + block.pixelPtr += options.fromX * block.pixelSize + + options.fromY * block.pitch; + block.width = options.fromX2 - options.fromX; + block.height = options.fromY2 - options.fromY; + result = Tk_PhotoPutZoomedBlock(interp, (Tk_PhotoHandle) masterPtr, + &block, options.toX, options.toY, options.toX2 - options.toX, + options.toY2 - options.toY, options.zoomX, options.zoomY, + options.subsampleX, options.subsampleY, + options.compositingRule); + + /* * Set the destination image size if the -shrink option was specified. + * This has to be done _after_ copying the data. Otherwise, if source + * and destination are the same image, block.pixelPtr would point to + * an invalid memory block (bug [5239fd749b]). */ if (options.options & OPT_SHRINK) { @@ -637,20 +654,9 @@ ImgPhotoCmd( return TCL_ERROR; } } - - /* - * Copy the image data over using Tk_PhotoPutZoomedBlock. - */ - - block.pixelPtr += options.fromX * block.pixelSize - + options.fromY * block.pitch; - block.width = options.fromX2 - options.fromX; - block.height = options.fromY2 - options.fromY; - return Tk_PhotoPutZoomedBlock(interp, (Tk_PhotoHandle) masterPtr, - &block, options.toX, options.toY, options.toX2 - options.toX, - options.toY2 - options.toY, options.zoomX, options.zoomY, - options.subsampleX, options.subsampleY, - options.compositingRule); + Tk_ImageChanged(masterPtr->tkMaster, 0, 0, 0, 0, + masterPtr->width, masterPtr->height); + return result; case PHOTO_DATA: { char *data; diff --git a/tests/imgPhoto.test b/tests/imgPhoto.test index 4bff5cc..0126ad9 100644 --- a/tests/imgPhoto.test +++ b/tests/imgPhoto.test @@ -820,6 +820,18 @@ test imgPhoto-4.75 {<photo> read command: filename starting with '-'} -constrain image delete photo1 file delete ./-teapotPhotoFile } -result {} +test imgPhoto-4.76 {ImgPhotoCmd procedure: copy to same image} -constraints { + hasTeapotPhoto +} -setup { + imageCleanup + image create photo photo1 -file $teapotPhotoFile +} -body { + # non-regression test for bug [5239fd749b] - shall just not crash + photo1 copy photo1 -to 0 0 2000 1000 + photo1 copy photo1 -subsample 2 2 -shrink +} -cleanup { + imageCleanup +} -result {} test imgPhoto-5.1 {ImgPhotoGet/Free procedures, shared instances} -constraints { hasTeapotPhoto |