-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8357299: Graphics copyArea doesn't copy any pixels when there is overflow #25340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /* | ||
| * Copyright (c) 2000, 2024, Oracle and/or its affiliates. All rights reserved. | ||
| * Copyright (c) 2000, 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
|
|
@@ -74,19 +74,16 @@ Java_sun_java2d_loops_Blit_Blit | |
|
|
||
| srcInfo.bounds.x1 = srcx; | ||
| srcInfo.bounds.y1 = srcy; | ||
| if (UNSAFE_TO_ADD(srcx, width) || | ||
| UNSAFE_TO_ADD(srcy, height) || | ||
| UNSAFE_TO_ADD(dstx, width) || | ||
| UNSAFE_TO_ADD(dsty, height)) { | ||
| return; | ||
| } | ||
|
|
||
| srcInfo.bounds.x2 = srcx + width; | ||
| srcInfo.bounds.y2 = srcy + height; | ||
| srcInfo.bounds.x2 = UNSAFE_TO_ADD(srcx, width) | ||
| ? clipInfo.bounds.x2 : (srcx + width); | ||
| srcInfo.bounds.y2 = UNSAFE_TO_ADD(srcy, height) | ||
| ? clipInfo.bounds.y2 : (srcy + height); | ||
| dstInfo.bounds.x1 = dstx; | ||
| dstInfo.bounds.y1 = dsty; | ||
| dstInfo.bounds.x2 = dstx + width; | ||
| dstInfo.bounds.y2 = dsty + height; | ||
| dstInfo.bounds.x2 = UNSAFE_TO_ADD(dstx, width) | ||
| ? clipInfo.bounds.x2 : (dstx + width); | ||
| dstInfo.bounds.y2 = UNSAFE_TO_ADD(dsty, height) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why wouldn't you always want to limit it to the clip ?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is because down below it anyway calls
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @prrace Since it is going to clip dstInfo.bounds to clipInfo.bounds in SurfaceData_IntersectBounds, I believe is not necessary to do the duplicate clip here.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
In addition to intersecting dst with clip, you're also intersecting src with clip, which seems incorrect. A better approach might be to compute the drawable width based on the non-overflowing range for both src and dst, and then proceed with the original logic. BTW I have not checked MaskBlit_MaskBlit yet it might require a similar update.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have not found any problem with that part of code so far..We have addressed the issue that was raised.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is incorrect because the clip bounds are relative to the destination (dst), so you cannot intersect them directly with the source (src) surface. The usage of UNSAFE_TO_SUB below is also wrong, we cannot just exists. filed https://bugs.openjdk.org/browse/JDK-8358103 and https://bugs.openjdk.org/browse/JDK-8358107 |
||
| ? clipInfo.bounds.y2 : (dsty + height); | ||
| if (UNSAFE_TO_SUB(srcx, dstx) || | ||
| UNSAFE_TO_SUB(srcy, dsty)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we also should check this part of the code, is it correct to simply exit here, or should we instead calculate and use the maximum distance we can handle? |
||
| return; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| /* | ||
| * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| /* | ||
| * @test | ||
| * @bug 8357299 | ||
| * @summary Verifies if Graphics copyArea doesn't copy any pixels | ||
| * when there is overflow | ||
| * @run main BrokenBoundsClip | ||
| */ | ||
|
|
||
| import java.awt.Color; | ||
| import java.awt.Graphics2D; | ||
| import java.awt.image.BufferedImage; | ||
|
|
||
| import static java.awt.image.BufferedImage.TYPE_INT_RGB; | ||
|
|
||
| public final class BrokenBoundsClip { | ||
|
|
||
| public static final int SIZE = 100; | ||
|
|
||
| public static void main(String[] args) { | ||
| BufferedImage bi = new BufferedImage(SIZE, SIZE, TYPE_INT_RGB); | ||
|
|
||
| Graphics2D g2d = bi.createGraphics(); | ||
| g2d.setColor(Color.RED); | ||
| g2d.fillRect(SIZE / 2, SIZE / 2, SIZE / 2, SIZE / 2); | ||
|
|
||
| g2d.copyArea(bi.getWidth() / 2, bi.getHeight() / 2, | ||
| Integer.MAX_VALUE , Integer.MAX_VALUE , | ||
| -bi.getWidth() / 2, -bi.getHeight() / 2); | ||
| int actual = bi.getRGB(0, 0); | ||
| int expected = Color.RED.getRGB(); | ||
| if (actual != expected) { | ||
| System.err.println("Actual: " + Integer.toHexString(actual)); | ||
| System.err.println("Expected: " + Integer.toHexString(expected)); | ||
| throw new RuntimeException("Wrong color"); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't the MaskBlit_MaskBlit use the same pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But that doesn't cause any issue to the testcase given and existing testcase..Do you have any testcase which doesnt work because of MaskBlit pattern?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have not tried to create a test for MaskBlit, only for a simple Blit. I will take a look at the possibility of reproducing it.