summaryrefslogtreecommitdiff
path: root/core/src/main/java/com/google
diff options
context:
space:
mode:
authorjmestwa-coder <jmestwa@gmail.com>2026-06-26 18:50:33 +0300
committerGitHub <noreply@github.com>2026-06-26 18:50:33 +0300
commit7f129804e396958ae762da288da5df330d142da0 (patch)
tree031007c51f0d187a9c49dcd7751ba4c04366dc10 /core/src/main/java/com/google
parent329f34a8849544c78f8478bd35925da25d6f30d2 (diff)
downloadzxing-7f129804e396958ae762da288da5df330d142da0.tar.xz
reject negative and overflowing crop in core LuminanceSource classes (#2112)
the crop constructors in PlanarYUVLuminanceSource and GrayscaleLuminanceSource did not reject negative offsets or sizes and overflowed when checking left+width and top+height, letting an out-of-bounds crop reach getRow and getMatrix; validate the rectangle the same way as BufferedImageLuminanceSource.
Diffstat (limited to 'core/src/main/java/com/google')
-rw-r--r--core/src/main/java/com/google/zxing/GrayscaleLuminanceSource.java3
-rw-r--r--core/src/main/java/com/google/zxing/PlanarYUVLuminanceSource.java3
2 files changed, 4 insertions, 2 deletions
diff --git a/core/src/main/java/com/google/zxing/GrayscaleLuminanceSource.java b/core/src/main/java/com/google/zxing/GrayscaleLuminanceSource.java
index 7941bad81..3afa20bcf 100644
--- a/core/src/main/java/com/google/zxing/GrayscaleLuminanceSource.java
+++ b/core/src/main/java/com/google/zxing/GrayscaleLuminanceSource.java
@@ -48,7 +48,8 @@ public class GrayscaleLuminanceSource extends LuminanceSource {
int width,
int height) {
super(width, height);
- if (left + width > dataWidth || top + height > dataHeight) {
+ if (left < 0 || top < 0 || width < 0 || height < 0 ||
+ width > dataWidth - left || height > dataHeight - top) {
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
}
this.luminances = pixels;
diff --git a/core/src/main/java/com/google/zxing/PlanarYUVLuminanceSource.java b/core/src/main/java/com/google/zxing/PlanarYUVLuminanceSource.java
index cecff3efa..b94ebe6e5 100644
--- a/core/src/main/java/com/google/zxing/PlanarYUVLuminanceSource.java
+++ b/core/src/main/java/com/google/zxing/PlanarYUVLuminanceSource.java
@@ -46,7 +46,8 @@ public final class PlanarYUVLuminanceSource extends LuminanceSource {
boolean reverseHorizontal) {
super(width, height);
- if (left + width > dataWidth || top + height > dataHeight) {
+ if (left < 0 || top < 0 || width < 0 || height < 0 ||
+ width > dataWidth - left || height > dataHeight - top) {
throw new IllegalArgumentException("Crop rectangle does not fit within image data.");
}