diff --git a/src/main/java/com/glencoesoftware/omero/zarr/ZarrPixelBuffer.java b/src/main/java/com/glencoesoftware/omero/zarr/ZarrPixelBuffer.java index 29c2e98..fc5fd54 100644 --- a/src/main/java/com/glencoesoftware/omero/zarr/ZarrPixelBuffer.java +++ b/src/main/java/com/glencoesoftware/omero/zarr/ZarrPixelBuffer.java @@ -28,7 +28,6 @@ import java.util.Arrays; import java.util.List; import java.util.Map; -import java.util.concurrent.CompletionException; import java.util.concurrent.ExecutionException; import java.util.stream.IntStream; @@ -137,8 +136,6 @@ public ZarrPixelBuffer(Pixels pixels, Path root, Integer maxPlaneWidth, int w = key.get(6); int h = key.get(7); int[] shape = new int[] { 1, 1, 1, h, w }; - // Check planar read size (sizeX and sizeY only) - checkReadSize(Arrays.copyOfRange(shape, 3, 5)); byte[] innerBuffer = new byte[(int) length(shape) * getByteWidth()]; setResolutionLevel(resolutionLevel); @@ -459,6 +456,11 @@ public PixelData getTile( checkBounds(x, y, z, c, t); //Check check bottom-right of tile in bounds checkBounds(x + w - 1, y + h - 1, z, c, t); + //Check planar read size (sizeX and sizeY only), essential that this + //happens before the similar check in read(). Otherwise we will + //potentially allocate massive inner buffers in the tile cache + //asynchronous entry builder that will never be used. + checkReadSize(new int[] { w, h }); List> keys = new ArrayList>(); List key = null; @@ -481,15 +483,7 @@ public PixelData getTile( // of channels can be unpredictable. tileCache.synchronous().invalidateAll(); } - try { - return toPixelData(tileCache.getAll(keys).join().get(key)); - } catch (CompletionException e) { - if (e.getCause() instanceof IllegalArgumentException) { - // Request arguments out of bounds - throw (IllegalArgumentException) e.getCause(); - } - throw e; - } + return toPixelData(tileCache.getAll(keys).join().get(key)); } @Override diff --git a/src/test/java/com/glencoesoftware/omero/zarr/ZarrPixelBufferTest.java b/src/test/java/com/glencoesoftware/omero/zarr/ZarrPixelBufferTest.java index 85ec303..1618c9e 100644 --- a/src/test/java/com/glencoesoftware/omero/zarr/ZarrPixelBufferTest.java +++ b/src/test/java/com/glencoesoftware/omero/zarr/ZarrPixelBufferTest.java @@ -32,7 +32,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.concurrent.CompletionException; import java.util.stream.IntStream; import org.junit.Assert; @@ -530,8 +529,7 @@ public void testTileIntegerOverflow() mapper.writeValue(output.resolve("0/0/.zarray").toFile(), zArray); try (ZarrPixelBuffer zpbuf = createPixelBuffer(pixels, output.resolve("0"), 32, 32)) { - PixelData pixelData = zpbuf.getTile(0, 0, 0, 0, 0, 50000, 50000); - Assert.assertNull(pixelData); + zpbuf.getTile(0, 0, 0, 0, 0, 50000, 50000); } }