-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix and expand range checks when performing tile retrieval #11
Changes from all commits
f2cb10a
3638127
bcecc20
1056d95
756e356
8abbf8b
4313e95
cb1ca8c
e9313f5
8a695fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,12 +41,11 @@ | |
|
||
import com.bc.zarr.ZarrArray; | ||
import com.bc.zarr.ZarrGroup; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.github.benmanes.caffeine.cache.Caffeine; | ||
|
||
import picocli.CommandLine; | ||
import com.glencoesoftware.bioformats2raw.Converter; | ||
import com.glencoesoftware.omero.zarr.ZarrPixelsService; | ||
import com.glencoesoftware.omero.zarr.ZarrPixelBuffer; | ||
|
||
import loci.formats.FormatTools; | ||
import loci.formats.in.FakeReader; | ||
|
@@ -503,8 +502,39 @@ public void testGetTileLargerThanImage() | |
} | ||
} | ||
|
||
@Test | ||
public void testTileExceedsMax() throws IOException, InvalidRangeException { | ||
@Test(expected = IllegalArgumentException.class) | ||
public void testTileIntegerOverflow() | ||
throws IOException, InvalidRangeException { | ||
int sizeT = 1; | ||
int sizeC = 3; | ||
int sizeZ = 1; | ||
int sizeY = 1; | ||
int sizeX = 1; | ||
int resolutions = 1; | ||
Pixels pixels = new Pixels( | ||
null, null, sizeX, sizeY, sizeZ, sizeC, sizeT, "", null); | ||
Path output = writeTestZarr( | ||
sizeT, sizeC, sizeZ, sizeY, sizeX, "uint16", | ||
resolutions); | ||
|
||
// Hack the .zarray so we can appear as though we have more data than | ||
// we actually have written above. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume the rationale if that is we want to generate an OME-Zarr of a given dimensions without actually writing the underlying test data (which increases the test time for no value). @melissalinkert this makes me wonder whether we could introduce an option in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Correct. Creating an array large enough to not end up with earlier out of bounds checks can take minutes. |
||
ObjectMapper mapper = new ObjectMapper(); | ||
HashMap<String, Object> zArray = mapper.readValue( | ||
Files.readAllBytes(output.resolve("0/0/.zarray")), | ||
HashMap.class); | ||
List<Integer> shape = (List<Integer>) zArray.get("shape"); | ||
shape.set(3, 50000); | ||
shape.set(4, 50000); | ||
mapper.writeValue(output.resolve("0/0/.zarray").toFile(), zArray); | ||
try (ZarrPixelBuffer zpbuf = | ||
createPixelBuffer(pixels, output.resolve("0"), 32, 32)) { | ||
zpbuf.getTile(0, 0, 0, 0, 0, 50000, 50000); | ||
} | ||
} | ||
|
||
@Test(expected = IllegalArgumentException.class) | ||
public void testTileExceedsMinMax() throws IOException { | ||
int sizeT = 1; | ||
int sizeC = 3; | ||
int sizeZ = 1; | ||
|
@@ -519,8 +549,9 @@ public void testTileExceedsMax() throws IOException, InvalidRangeException { | |
|
||
try (ZarrPixelBuffer zpbuf = | ||
createPixelBuffer(pixels, output.resolve("0"), 32, 32)) { | ||
PixelData pixelData = zpbuf.getTile(0, 0, 0, 0, 0, 32, 33); | ||
Assert.assertNull(pixelData); | ||
Assert.assertNull(zpbuf.getTile(0, 0, 0, 0, 0, 32, 33)); | ||
// Throws exception | ||
zpbuf.getTile(0, 0, 0, -1, 0, 1, 1); | ||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be worth doing long multiplication here too? Or do we know for sure that
maxPlaneWidth * maxPlaneHeight
will always be less thanInteger.MAX_VALUE
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't know for sure but if you were to configure your server like that all sorts of other stuff would break spectacularly.