Skip to content

Commit

Permalink
OIRReader - improve safety:
Browse files Browse the repository at this point in the history
* set optimalTileHeight to 0 in close
* check reader initialisation in optimal tile size method calls
* checks and warns in case of null PixelBlocks
  • Loading branch information
NicoKiaru committed Sep 9, 2024
1 parent d7ccc56 commit 26efbd1
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions components/formats-gpl/src/loci/formats/in/OIRReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,13 @@ public short[][] get16BitLookupTable() throws FormatException, IOException {

@Override
public int getOptimalTileHeight() {
FormatTools.assertId(currentId, true, 1);
return Math.min(2048, optimalTileHeight);
}

@Override
public int getOptimalTileWidth() {
FormatTools.assertId(currentId, true, 1);
return Math.min(2048, getSizeX());
}

Expand Down Expand Up @@ -211,6 +213,10 @@ public byte[] openBytes(int no, byte[] buf, int x, int y, int w, int h)
int yOffsetInBuffer = 0; // current y offset within the exported buffer

for (PixelBlock block : blocks) { // This list is sorted along y
if (block == null) {
LOGGER.warn("Block not found.");
continue;
}
// Skips blocks positioned fully outside [y, y+h[
if (block.yEnd<y) continue; // The pixel block is completely above the requested region - skip it
if (block.yStart>y+h) break; // The pixel block is completely below the requested region - skip all remaining blocks
Expand Down Expand Up @@ -264,6 +270,7 @@ public void close(boolean fileOnly) throws IOException {
defaultXMLSkip = 36;
blocksPerPlane = 0;
cztToPixelBlocks.clear();
optimalTileHeight = 0;
baseName = null;
lastChannel = -1;
minZ = Integer.MAX_VALUE;
Expand Down

0 comments on commit 26efbd1

Please sign in to comment.