Open afboteroz opened 8 years ago
Do you have a copy of the data
that causes an infinite loop? I can't see how readBit()
would cause an infinite loop as it should progress through the stream until bpos
reaches 0?
Or is the problem with bit stuffing..? It assumes nextbbuf
has been updated, but if you have a stream with more than 7 0xFF
s I guess it could fall over and just keep looking within the same bytes.
The PDF that was trying to extract the first image was this: 00006567119070520-1-original.pdf
I have been experiencing this issue as well.
I have pr up to prevent the infinite loop from happening on the codice fork of the project here https://github.com/codice/jai-imageio-jpeg2000/pull/3
This is the j2k file that was causing the issue for me. I gave it a pdf extension so github would let me upload it. p1_05.pdf
Seems to have been merged, so this can be closed now?
I have a PDF file where I can see a similar issue. I use PDFBox to extract an embedded image in JPEG2000 format, but it gets stuck in infinite loop in:
at jj2000.j2k.codestream.reader.PktDecoder.readPktHead(PktDecoder.java:1027)
at jj2000.j2k.codestream.reader.FileBitstreamReaderAgent.readResLyCompPos(FileBitstreamReaderAgent.java:1162)
at jj2000.j2k.codestream.reader.FileBitstreamReaderAgent.readTilePkts(FileBitstreamReaderAgent.java:1963)
at jj2000.j2k.codestream.reader.FileBitstreamReaderAgent.setTile(FileBitstreamReaderAgent.java:2228)
at jj2000.j2k.wavelet.synthesis.MultiResImgDataAdapter.setTile(MultiResImgDataAdapter.java:291)
at jj2000.j2k.wavelet.synthesis.MultiResImgDataAdapter.setTile(MultiResImgDataAdapter.java:291)
at jj2000.j2k.quantization.dequantizer.Dequantizer.setTile(Dequantizer.java:226)
at jj2000.j2k.wavelet.synthesis.InvWTAdapter.setTile(InvWTAdapter.java:339)
at jj2000.j2k.wavelet.synthesis.InvWTFull.setTile(InvWTFull.java:578)
at jj2000.j2k.image.ImgDataAdapter.setTile(ImgDataAdapter.java:288)
at jj2000.j2k.image.invcomptransf.InvCompTransf.setTile(InvCompTransf.java:643)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.readSubsampledRaster(J2KReadState.java:763)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KReadState.readBufferedImage(J2KReadState.java:384)
at com.sun.media.imageioimpl.plugins.jpeg2000.J2KImageReader.read(J2KImageReader.java:454)
at org.apache.pdfbox.filter.JPXFilter.readJPX(JPXFilter.java:132)
at org.apache.pdfbox.filter.JPXFilter.decode(JPXFilter.java:64)
at org.apache.pdfbox.cos.COSInputStream.create(COSInputStream.java:80)
at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:176)
at org.apache.pdfbox.cos.COSStream.createInputStream(COSStream.java:164)
at org.apache.pdfbox.pdmodel.common.PDStream.createInputStream(PDStream.java:236)
at org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject.<init>(PDImageXObject.java:142)
at org.apache.pdfbox.pdmodel.graphics.PDXObject.createXObject(PDXObject.java:70)
at org.apache.pdfbox.pdmodel.PDResources.getXObject(PDResources.java:426)
at org.apache.pdfbox.contentstream.operator.graphics.DrawObject.process(DrawObject.java:58)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processOperator(PDFStreamEngine.java:933)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStreamOperators(PDFStreamEngine.java:515)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processStream(PDFStreamEngine.java:489)
at org.apache.pdfbox.contentstream.PDFStreamEngine.processPage(PDFStreamEngine.java:156)
at org.apache.pdfbox.rendering.PageDrawer.drawPage(PageDrawer.java:275)
at org.apache.pdfbox.rendering.PDFRenderer.renderPageToGraphics(PDFRenderer.java:458)
at org.apache.pdfbox.rendering.PDFRenderer.renderPageToGraphics(PDFRenderer.java:414)
at org.apache.pdfbox.rendering.PDFRenderer.renderPageToGraphics(PDFRenderer.java:396)
at org.apache.pdfbox.rendering.PDFRenderer.renderPageToGraphics(PDFRenderer.java:379)
I have tried the patch from the other fork where it's supposed to be fixed (https://github.com/codice/jai-imageio-jpeg2000), but it didn't work for me. The PDF looks fine when I look at it in Adobe.
Sample file is attached: The digital overhaul Exec Report.pdf
I'm using jpedal to get an image of a pdf and where jpedal tries to read the imagen it's enter in an infinite loop.
https://github.com/jai-imageio/jai-imageio-jpeg2000/blob/master/src/main/java/jj2000/j2k/codestream/reader/PktDecoder.java#L1028
Execution Code: