Jump to content

Non-rectangular "Copy", "Cut", and "Crop to selection" do not destroy pixels, but rather make them alpha 0


Recommended Posts

Posted

I can't be certain if you would qualify this as a bug, but it was very unexpected and alarming behavior for me.

 

I just noticed today (in Paint.NET 5.1 on Windows 10) that if I "crop to selection" for an irregularly-shaped selection, the outer pixels that are removed are not deleted (e.g. set to transparent black like when you Clear Selection or use the Eraser), but are instead kept intact and set to alpha 0.

 

For example, I take an image:

image.jpeg.2cd65803a081090938b94806419d8be0.jpeg

I create a funny-shaped selection:

image.jpeg.751ba35ef12d939ff0fe6f270a23dbf8.jpeg

And then I crop to selection (Ctrl-Shift-X):

image.jpeg.e664dcb3fc0c317f28badfd365d649d4.jpeg

This gives the impression to the user that it has destroyed the pixels from the image, like they would be if you had pressed Erase Selection (Del).

 

However, the pixels have not been destroyed, but have merely been made transparent:

image.jpeg.c7264eb896b6e29f8f4c5765875de559.jpeg

If you were to save this as a file (e.g. PNG) or copy and paste it into another program, the transparent data in the outer section is retained and can be easily recovered. This seems like it could result in a privacy/security issue, since I think many people would assume that the cropped pixels had been destroyed. I decided to test in 5.0.13 to see if this was a regression, but the issue is present there as well.

 

However, that led me to another issue that was not present in 5.0.13 which I found to be even more startling. I discovered that in 5.1 that this affects copying and pasting (into other applications) as well.

 

For example, first I start with a regular image and I make a silly selection:

image.jpeg.809e9f5fff081900effe972e0942d4b1.jpeg

I copy and paste this raw clipboard data into a chat application that supports transparency, Discord.

Everything's well and good because the other user only received the cropped pixels, right?:

image.jpeg.b5c76aa3b13a42335eacea19a48fd5ec.jpeg

Nope! They can actually save the image and fully recover them:

image.jpeg.1912ac5e9e8f9c0e1bc3677298f21768.jpeg

TLDR:

I think there was an unintended regression between 5.0 and 5.1 that causes outside-of-selection pixels to not be properly destroyed when copying and pasting.

It led me to the realization that outside-of-selection pixels are not and possibly have never been fully destroyed when using "crop to selection", which is a little scary.

Posted

I'm rereading my post now, and I should clarify that the second set of instructions refers to a standard copy/cut and paste operation. Just the lasso tool followed by Ctrl-C. No "crop to selection" was involved in that one, which was why it was particularly spooky to see.

 

The clipboard looked and behaved as if only contained the T-shaped data, which is what I would have expected from a copy and paste operation, and why it would have felt safe to paste and send on Discord. It was only when saving the file from Discord, or pasting into an application like MSPaint or Irfanview that it became apparent that the data was still intact.

 

Paint.NET itself seems to correct for this issue automatically within itself, for what it's worth. When the same exact T-shaped clipboard data (containing the transparent data) was pasted back into a new layer or image in Paint.NET, it destroyed the transparent data during the paste operation.

Posted

The underlying issue is that the alpha channel of the pixels is being multiplied by the alpha value from the selection's mask bitmap. This works great except that it still leaves transparent pixels with their color information. I'm adding a second step to these code paths so that any pixels with A=0 also get B=G=R=0 set as well. I agree that this is a potential privacy issue.

  • Like 2

The Paint.NET Blog: https://blog.getpaint.net/

Donations are always appreciated! https://www.getpaint.net/donate.html

forumSig_bmwE60.jpg

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...