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/test/java/com | |
| 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/test/java/com')
| -rw-r--r-- | core/src/test/java/com/google/zxing/GrayscaleLuminanceSourceTestCase.java | 10 | ||||
| -rw-r--r-- | core/src/test/java/com/google/zxing/PlanarYUVLuminanceSourceTestCase.java | 10 |
2 files changed, 20 insertions, 0 deletions
diff --git a/core/src/test/java/com/google/zxing/GrayscaleLuminanceSourceTestCase.java b/core/src/test/java/com/google/zxing/GrayscaleLuminanceSourceTestCase.java index bd911f6d6..eb47aa1b3 100644 --- a/core/src/test/java/com/google/zxing/GrayscaleLuminanceSourceTestCase.java +++ b/core/src/test/java/com/google/zxing/GrayscaleLuminanceSourceTestCase.java @@ -109,6 +109,16 @@ public final class GrayscaleLuminanceSourceTestCase extends Assert { } @Test(expected = IllegalArgumentException.class) + public void testNegativeCrop() { + SOURCE.crop(-1, 0, 3, 3); + } + + @Test(expected = IllegalArgumentException.class) + public void testOverflowCrop() { + SOURCE.crop(1, 0, Integer.MAX_VALUE, 3); + } + + @Test(expected = IllegalArgumentException.class) public void testNullPixelArray() { // Test regression: null pixel array should throw IllegalArgumentException new RGBLuminanceSource(3, 3, null); diff --git a/core/src/test/java/com/google/zxing/PlanarYUVLuminanceSourceTestCase.java b/core/src/test/java/com/google/zxing/PlanarYUVLuminanceSourceTestCase.java index 4d5912a61..d0c06f97b 100644 --- a/core/src/test/java/com/google/zxing/PlanarYUVLuminanceSourceTestCase.java +++ b/core/src/test/java/com/google/zxing/PlanarYUVLuminanceSourceTestCase.java @@ -72,6 +72,16 @@ public final class PlanarYUVLuminanceSourceTestCase extends Assert { source.renderThumbnail()); } + @Test(expected = IllegalArgumentException.class) + public void testNegativeCrop() { + new PlanarYUVLuminanceSource(YUV, COLS, ROWS, -1, 0, COLS, ROWS, false); + } + + @Test(expected = IllegalArgumentException.class) + public void testOverflowCrop() { + new PlanarYUVLuminanceSource(YUV, COLS, ROWS, 1, 0, Integer.MAX_VALUE, ROWS, false); + } + private static void assertEquals(byte[] expected, int expectedFrom, byte[] actual, int actualFrom, int length) { |
