Skip to content

Commit 21fa61a

Browse files
Lukasz Kostyrajohanvos
Lukasz Kostyra
authored andcommittedJul 17, 2023
8304751: Improve pipeline layout
Reviewed-by: mschoene, arapte, rhalade, kcr
1 parent fa95c23 commit 21fa61a

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
 

‎modules/javafx.graphics/src/main/native-prism-sw/JPiscesRenderer.c

+49
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#include <PiscesRenderer.inl>
3636

37+
#include <limits.h>
38+
3739
#define RENDERER_NATIVE_PTR 0
3840
#define RENDERER_SURFACE 1
3941
#define RENDERER_LAST RENDERER_SURFACE
@@ -684,11 +686,34 @@ JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_fillAlphaMaskImpl
684686
jint maskOffset;
685687
rdr = (Renderer*)JLongToPointer((*env)->GetLongField(env, this, fieldIds[RENDERER_NATIVE_PTR]));
686688

689+
if (x <= -(INT_MAX - maskWidth) || y <= -(INT_MAX - maskHeight)) {
690+
return;
691+
}
692+
693+
if (x >= INT_MAX - maskWidth || y >= INT_MAX - maskHeight) {
694+
return;
695+
}
696+
687697
minX = MAX(x, rdr->_clip_bbMinX);
688698
minY = MAX(y, rdr->_clip_bbMinY);
689699
maxX = MIN(x + maskWidth - 1, rdr->_clip_bbMaxX);
690700
maxY = MIN(y + maskHeight - 1, rdr->_clip_bbMaxY);
691701

702+
// offset, width, height and stride cannot be negative - checked in Java code.
703+
// below checks might be a bit excessive (probably won't happen because fillMaskAlpha()
704+
// min/max check will make maskOffset not be used at all) but better to be safe than sorry
705+
if (maskWidth > 0 && (minY - y) >= (INT_MAX / maskWidth)) {
706+
return;
707+
}
708+
709+
if ((minX - x) >= INT_MAX - ((minY - y) * maskWidth)) {
710+
return;
711+
}
712+
713+
if (offset >= INT_MAX - ((minY - y) * maskWidth + minX - x)) {
714+
return;
715+
}
716+
692717
maskOffset = offset + (minY - y) * maskWidth + minX - x;
693718

694719
fillAlphaMask(rdr, minX, minY, maxX, maxY, env, this, ALPHA_MASK, jmask,
@@ -721,11 +746,35 @@ JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_fillLCDAlphaMaskImpl
721746
jint maskOffset;
722747
rdr = (Renderer*)JLongToPointer((*env)->GetLongField(env, this, fieldIds[RENDERER_NATIVE_PTR]));
723748

749+
if (x < -(INT_MAX - maskWidth/3) || y < -(INT_MAX - maskHeight)) {
750+
return;
751+
}
752+
753+
if (x >= INT_MAX - (maskWidth/3) || y >= INT_MAX - maskHeight) {
754+
return;
755+
}
756+
724757
minX = MAX(x, rdr->_clip_bbMinX);
725758
minY = MAX(y, rdr->_clip_bbMinY);
726759
maxX = MIN(x + (maskWidth/3) - 1, rdr->_clip_bbMaxX);
727760
maxY = MIN(y + maskHeight - 1, rdr->_clip_bbMaxY);
728761

762+
if (maskWidth > 0 && (minY - y) >= (INT_MAX / maskWidth)) {
763+
return;
764+
}
765+
766+
if ((minX - x) >= INT_MAX / 3) {
767+
return;
768+
}
769+
770+
if (((minX - x) * 3) >= INT_MAX - ((minY - y) * maskWidth)) {
771+
return;
772+
}
773+
774+
if (offset >= INT_MAX - ((minY - y) * maskWidth + (minX - x) * 3)) {
775+
return;
776+
}
777+
729778
maskOffset = offset + (minY - y) * maskWidth + (minX - x) * 3;
730779

731780
fillAlphaMask(rdr, minX, minY, maxX, maxY, env, this, LCD_ALPHA_MASK, jmask,

4 commit comments

Comments
 (4)

johanvos commented on Jul 18, 2023

@johanvos
Collaborator

/tag 17.0.8+2

openjdk[bot] commented on Jul 18, 2023

@openjdk[bot]

@johanvos The tag 17.0.8+2 was successfully created.

johanvos commented on Jul 24, 2023

@johanvos
Collaborator

/tag 17.0.9+0

openjdk[bot] commented on Jul 24, 2023

@openjdk[bot]

@johanvos The tag 17.0.9+0 was successfully created.

Please sign in to comment.