|
34 | 34 |
|
35 | 35 | #include <PiscesRenderer.inl>
|
36 | 36 |
|
| 37 | +#include <limits.h> |
| 38 | + |
37 | 39 | #define RENDERER_NATIVE_PTR 0
|
38 | 40 | #define RENDERER_SURFACE 1
|
39 | 41 | #define RENDERER_LAST RENDERER_SURFACE
|
@@ -684,11 +686,34 @@ JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_fillAlphaMaskImpl
|
684 | 686 | jint maskOffset;
|
685 | 687 | rdr = (Renderer*)JLongToPointer((*env)->GetLongField(env, this, fieldIds[RENDERER_NATIVE_PTR]));
|
686 | 688 |
|
| 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 | + |
687 | 697 | minX = MAX(x, rdr->_clip_bbMinX);
|
688 | 698 | minY = MAX(y, rdr->_clip_bbMinY);
|
689 | 699 | maxX = MIN(x + maskWidth - 1, rdr->_clip_bbMaxX);
|
690 | 700 | maxY = MIN(y + maskHeight - 1, rdr->_clip_bbMaxY);
|
691 | 701 |
|
| 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 | + |
692 | 717 | maskOffset = offset + (minY - y) * maskWidth + minX - x;
|
693 | 718 |
|
694 | 719 | fillAlphaMask(rdr, minX, minY, maxX, maxY, env, this, ALPHA_MASK, jmask,
|
@@ -721,11 +746,35 @@ JNIEXPORT void JNICALL Java_com_sun_pisces_PiscesRenderer_fillLCDAlphaMaskImpl
|
721 | 746 | jint maskOffset;
|
722 | 747 | rdr = (Renderer*)JLongToPointer((*env)->GetLongField(env, this, fieldIds[RENDERER_NATIVE_PTR]));
|
723 | 748 |
|
| 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 | + |
724 | 757 | minX = MAX(x, rdr->_clip_bbMinX);
|
725 | 758 | minY = MAX(y, rdr->_clip_bbMinY);
|
726 | 759 | maxX = MIN(x + (maskWidth/3) - 1, rdr->_clip_bbMaxX);
|
727 | 760 | maxY = MIN(y + maskHeight - 1, rdr->_clip_bbMaxY);
|
728 | 761 |
|
| 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 | + |
729 | 778 | maskOffset = offset + (minY - y) * maskWidth + (minX - x) * 3;
|
730 | 779 |
|
731 | 780 | fillAlphaMask(rdr, minX, minY, maxX, maxY, env, this, LCD_ALPHA_MASK, jmask,
|
|
4 commit comments
johanvos commentedon Jul 18, 2023
/tag 17.0.8+2
openjdk[bot] commentedon Jul 18, 2023
@johanvos The tag 17.0.8+2 was successfully created.
johanvos commentedon Jul 24, 2023
/tag 17.0.9+0
openjdk[bot] commentedon Jul 24, 2023
@johanvos The tag 17.0.9+0 was successfully created.