Skip to content
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

TIFF: Exception when reading region of a tiled float32 BigTIFF #746

Open
rfreeman853 opened this issue Apr 18, 2023 · 3 comments
Open

TIFF: Exception when reading region of a tiled float32 BigTIFF #746

rfreeman853 opened this issue Apr 18, 2023 · 3 comments

Comments

@rfreeman853
Copy link

This code fragment raises an exception with some specific files:


    try {
      ImageInputStream input = ImageIO.createImageInputStream(file);
      ImageReader reader = ImageIO.getImageReaders(input).next();
      System.out.println( "Using reader: " + reader );

      reader.setInput(input);
      int width  = reader.getWidth(reader.getMinIndex());
      int height = reader.getHeight(reader.getMinIndex());
      System.out.println( "width, height: " + width + ", " + height );

      ImageReadParam param = reader.getDefaultReadParam();
      Rectangle rect = new Rectangle(256, 256, 2, 2);
      param.setSourceRegion(rect);
      System.out.println( "sourceRegion:    " + param.getSourceRegion().toString() );
      BufferedImage image = reader.read(0, param);
    }
    catch (Exception e) {
      System.out.println( "Exception:" );
      e.printStackTrace();
    }

When the requested rectangle is inside the initial tile in the image, the result is java.lang.ArrayIndexOutOfBoundsException with the message 'Coordinate out of bounds!'. Outside the first tile (as above) the output is:

Using reader: com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader@76ccd017
width, height: 58000, 66500
sourceRegion:    java.awt.Rectangle[x=256,y=256,width=2,height=2]
Exception:
java.awt.image.RasterFormatException: (parentX + width) is outside raster
        at java.desktop/java.awt.image.Raster.createChild(Raster.java:1526)
        at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.clipRowToRect(TIFFImageReader.java:1909)
        at com.twelvemonkeys.imageio.plugins.tiff.TIFFImageReader.read(TIFFImageReader.java:1094)
        at smallest_test.main(smallest_test.java:58)

The BigTIFF file is available from this page:
https://www.data.gov.uk/dataset/8311f42d-bddd-4cd4-98a3-e543de5be4cb/lidar-composite-dtm-2019-10m
Beware: the download is 3.6Gb; the file is 15.5Gb.

On that page, there is a message about a newer version of the BigTIFF. That file has the same effect.

An observation: the number of pixels in the two files is between 2^31 and 2^32. That might cause a signed integer to become negative. No idea if that's useful.

@haraldk
Copy link
Owner

haraldk commented Apr 19, 2023

Thanks!

I'll have a look! Haven't tested with such large rasters, but in theory it should work... I'll see if I can find the issue.

Update: Seems the server responds with 500 Internal Server Error at the moment. I'll come by later...

@haraldk
Copy link
Owner

haraldk commented Apr 19, 2023

Okay, seems there is a bug in the clipRowToRect method in relation to a combination of source region and tiles... I'll find a fix.

@rfreeman853
Copy link
Author

Thanks for your efforts on this!

@haraldk haraldk changed the title Exception when reading a tiled float32 BigTIFF TIFF: Exception when reading region of a tiled float32 BigTIFF Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants