Skip to content

Commit

Permalink
Do the read size check earlier
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-allan committed Oct 2, 2024
1 parent e9313f5 commit 8a695fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
18 changes: 6 additions & 12 deletions src/main/java/com/glencoesoftware/omero/zarr/ZarrPixelBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<List<Integer>> keys = new ArrayList<List<Integer>>();
List<Integer> key = null;
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 8a695fa

Please sign in to comment.