From issues-return-92369-apmail-commons-issues-archive=commons.apache.org@commons.apache.org Mon Sep 21 00:03:03 2020 Return-Path: X-Original-To: apmail-commons-issues-archive@locus.apache.org Delivered-To: apmail-commons-issues-archive@locus.apache.org Received: from mailroute1-lw-us.apache.org (mailroute1-lw-us.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with ESMTP id 2055A19AC9 for ; Mon, 21 Sep 2020 00:03:03 +0000 (UTC) Received: from mail.apache.org (localhost [127.0.0.1]) by mailroute1-lw-us.apache.org (ASF Mail Server at mailroute1-lw-us.apache.org) with SMTP id BA7711227F9 for ; Mon, 21 Sep 2020 00:03:02 +0000 (UTC) Received: (qmail 14243 invoked by uid 500); 21 Sep 2020 00:03:02 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 14166 invoked by uid 500); 21 Sep 2020 00:03:02 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 14150 invoked by uid 99); 21 Sep 2020 00:03:02 -0000 Received: from mailrelay1-us-west.apache.org (HELO mailrelay1-us-west.apache.org) (209.188.14.139) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 21 Sep 2020 00:03:02 +0000 Received: from jira-he-de.apache.org (static.172.67.40.188.clients.your-server.de [188.40.67.172]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id 03ACD40C39 for ; Mon, 21 Sep 2020 00:03:01 +0000 (UTC) Received: from jira-he-de.apache.org (localhost.localdomain [127.0.0.1]) by jira-he-de.apache.org (ASF Mail Server at jira-he-de.apache.org) with ESMTP id 136C77801FB for ; Mon, 21 Sep 2020 00:03:00 +0000 (UTC) Date: Mon, 21 Sep 2020 00:03:00 +0000 (UTC) From: "ASF GitHub Bot (Jira)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Work logged] (IMAGING-265) ArrayIndexOutOfBoundsException on reading simple GeoTIFF MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/IMAGING-265?focusedWorklogId= =3D486721&page=3Dcom.atlassian.jira.plugin.system.issuetabpanels:worklog-ta= bpanel#worklog-486721 ] ASF GitHub Bot logged work on IMAGING-265: ------------------------------------------ Author: ASF GitHub Bot Created on: 21/Sep/20 00:02 Start Date: 21/Sep/20 00:02 Worklog Time Spent: 10m=20 Work Description: gwlucastrig commented on a change in pull request #= 98: URL: https://github.com/apache/commons-imaging/pull/98#discussion_r49175122= 0 ########## File path: src/main/java/org/apache/commons/imaging/formats/tiff/datareader= s/DataReaderStrips.java ########## @@ -291,25 +318,50 @@ public BufferedImage readImageData(final Rectangle su= bImage) // or working final ImageBuilder workingBuilder =3D new ImageBuilder(width, workingHeight, false); - - for (int strip =3D strip0; strip <=3D strip1; strip++) { - final long rowsPerStripLong =3D 0xFFFFffffL & rowsPerStrip; - final long rowsRemaining =3D height - (strip * rowsPerStripLon= g); - final long rowsInThisStrip =3D Math.min(rowsRemaining, rowsPer= StripLong); - final long bytesPerRow =3D (bitsPerPixel * width + 7) / 8; - final long bytesPerStrip =3D rowsInThisStrip * bytesPerRow; - final long pixelsPerStrip =3D rowsInThisStrip * width; - - final byte[] compressed =3D imageData.getImageData(strip).getD= ata(); - - final byte[] decompressed =3D decompress(compressed, compressi= on, - (int) bytesPerStrip, width, (int) rowsInThisStrip); - - interpretStrip( - workingBuilder, - decompressed, - (int) pixelsPerStrip, - yLimit); + if (planarConfiguration !=3D 2) { + for (int strip =3D strip0; strip <=3D strip1; strip++) { + final long rowsPerStripLong =3D 0xFFFFffffL & rowsPerStrip= ; + final long rowsRemaining =3D height - (strip * rowsPerStri= pLong); + final long rowsInThisStrip =3D Math.min(rowsRemaining, row= sPerStripLong); + final long bytesPerRow =3D (bitsPerPixel * width + 7) / 8; + final long bytesPerStrip =3D rowsInThisStrip * bytesPerRow= ; + final long pixelsPerStrip =3D rowsInThisStrip * width; + + final byte[] compressed =3D imageData.getImageData(strip).= getData(); + + final byte[] decompressed =3D decompress(compressed, compr= ession, + (int) bytesPerStrip, width, (int) rowsInThisStrip); + + interpretStrip( + workingBuilder, + decompressed, + (int) pixelsPerStrip, + yLimit); + } + } else { + int nStripsInPlane =3D imageData.getImageDataLength() / 3; + for (int strip =3D strip0; strip <=3D strip1; strip++) { + final long rowsPerStripLong =3D 0xFFFFffffL & rowsPerStrip= ; + final long rowsRemaining =3D height - (strip * rowsPerStri= pLong); + final long rowsInThisStrip =3D Math.min(rowsRemaining, row= sPerStripLong); + final long bytesPerRow =3D (bitsPerPixel * width + 7) / 8; + final long bytesPerStrip =3D rowsInThisStrip * bytesPerRow= ; + final long pixelsPerStrip =3D rowsInThisStrip * width; + + byte[] b =3D new byte[(int) bytesPerStrip]; + for (int iPlane =3D 0; iPlane < 3; iPlane++) { + int planeStrip =3D iPlane * nStripsInPlane + strip; + final byte[] compressed =3D imageData.getImageData(pla= neStrip).getData(); + final byte[] decompressed =3D decompress(compressed, c= ompression, + (int) bytesPerStrip, width, (int) rowsInThisStrip); + int index =3D iPlane; + for (int i =3D 0; i < decompressed.length; i++) { + b[index] =3D decompressed[i]; + index +=3D 3; + } + } + interpretStrip(workingBuilder, b, (int) pixelsPerStrip, he= ight); + } Review comment: These are two methods have a lot of redundancy and it would be bette= r to combine them into one. Unfortunately, they are both public APIs, so I= 'm not sure we could change their external appearance. Of course, we coul= d create a single, consolidated method that does the processing. Then we co= uld rewrite the existing methods to be "wrapper" methods that called the ne= w consolidated method. =20 I think it might be better to treat that change as a separate pull reque= st. =20 I contributed the "sub-image" logic a number of years ago. At the time, = there was a certain amount of resistance to the idea of a sub-image API, bu= t I thought it was necessary because may GeoTIFFs are huge (I'd been workin= g with some that are 20000-by-20000 pixels large). Anyway, I think I left = the original method in place because the code was simpler than the sub-imag= e code and I thought it would serve as a reference for anyone who was tryin= g to figure out how it worked. But I think you are right and the time has = come to clean things up.=20 ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org Issue Time Tracking ------------------- Worklog Id: (was: 486721) Time Spent: 1h (was: 50m) > ArrayIndexOutOfBoundsException on reading simple GeoTIFF > -------------------------------------------------------- > > Key: IMAGING-265 > URL: https://issues.apache.org/jira/browse/IMAGING-265 > Project: Commons Imaging > Issue Type: Bug > Components: Format: TIFF > Affects Versions: 1.0-alpha2 > Reporter: edgar soldin > Assignee: Bruno P. Kinoshita > Priority: Major > Attachments: small_world.tif, small_world_split.jpg > > Time Spent: 1h > Remaining Estimate: 0h > > hi, > =C2=A0 > we on the OpenJUMP project cannot open some GeoTIFFs with commons.imaging= . for details you may find a ticket in our bug tracker [https://sourceforg= e.net/p/jump-pilot/bugs/498/]=C2=A0. > =C2=A0 > the gist is: on loading the attached file getBufferedImage() fails with t= his stack > Caused by: java.lang.ArrayIndexOutOfBoundsException: 8000Caused by: java.= lang.ArrayIndexOutOfBoundsException: 8000 at org.apache.commons.imaging.for= mats.tiff.datareaders.DataReaderStrips.interpretStrip(DataReaderStrips.java= :196) at org.apache.commons.imaging.formats.tiff.datareaders.DataReaderStri= ps.readImageData(DataReaderStrips.java:254) at org.apache.commons.imaging.f= ormats.tiff.TiffImageParser.getBufferedImage(TiffImageParser.java:665) at o= rg.apache.commons.imaging.formats.tiff.TiffDirectory.getTiffImage(TiffDirec= tory.java:254) at org.apache.commons.imaging.formats.tiff.TiffImageParser.g= etBufferedImage(TiffImageParser.java:469) at org.apache.commons.imaging.Ima= ging.getBufferedImage(Imaging.java:1442) at org.apache.commons.imaging.Imag= ing.getBufferedImage(Imaging.java:1335) at org.apache.commons.imaging.Imagi= ng.getBufferedImage(Imaging.java:1304) at com.vividsolutions.jump.workbench= .imagery.graphic.CommonsImage.initImage(CommonsImage.java:108) -- This message was sent by Atlassian Jira (v8.3.4#803005)