diff options
| author | jmestwa-coder <jmestwa@gmail.com> | 2026-06-26 18:50:33 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-06-26 18:50:33 +0300 |
| commit | 7f129804e396958ae762da288da5df330d142da0 (patch) | |
| tree | 031007c51f0d187a9c49dcd7751ba4c04366dc10 /core/src/main/java | |
| parent | 329f34a8849544c78f8478bd35925da25d6f30d2 (diff) | |
| download | zxing-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')
| -rw-r--r-- | core/src/main/java/com/google/zxing/GrayscaleLuminanceSource.java | 3 | ||||
| -rw-r--r-- | core/src/main/java/com/google/zxing/PlanarYUVLuminanceSource.java | 3 |
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."); } |
