question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Infinite loop on corrupt jpeg

See original GitHub issue

In trying to break PDFBox via embedded corrupt jpegs, I found an infinite loop in twelvemonkeys. Many thanks to Tilman Hausherr for helping me replicate this with the unembedded jpeg and for recommending testing with TwelveMonkeys.

File: extracted

        Iterator<ImageReader> readers = ImageIO.getImageReadersByFormatName("JPEG");
        ImageReader reader = null;
        while (readers.hasNext()) {
            reader = readers.next();
            break;
        }
        try (InputStream is = Files.newInputStream(p)) {
            ImageInputStream iis = ImageIO.createImageInputStream(is);

            reader.setInput(iis);
            ImageReadParam irp = reader.getDefaultReadParam();

            Raster raster;
            try {
                BufferedImage image = reader.read(0, irp);
                raster = image.getRaster();
            } catch (IIOException var20) {
                raster = reader.readRaster(0, irp);
            }
        }

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
tballisoncommented, Mar 8, 2021

Let me ignore that test and give it a go!

1reaction
tballisoncommented, Mar 5, 2021

var5 can == 0, which means nothing is read. read:581, JPEGSegmentImageInputStream$ReplacementSegment (com.twelvemonkeys.imageio.plugins.jpeg) read:426, JPEGSegmentImageInputStream (com.twelvemonkeys.imageio.plugins.jpeg) readInputData:312, JPEGImageReader (com.sun.imageio.plugins.jpeg) readImageHeader:-1, JPEGImageReader (com.sun.imageio.plugins.jpeg) readNativeHeader:731, JPEGImageReader (com.sun.imageio.plugins.jpeg) readHeader:725, JPEGImageReader (com.sun.imageio.plugins.jpeg) readInternal:1130, JPEGImageReader (com.sun.imageio.plugins.jpeg) readRaster:1541, JPEGImageReader (com.sun.imageio.plugins.jpeg) readRaster:1056, JPEGImageReader (com.twelvemonkeys.imageio.plugins.jpeg) main:39, TwelveMonkeysMetadata (org.tallison.pdfbox.images) Screenshot from 2021-03-05 08-09-54 Screenshot from 2021-03-05 08-08-59

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decoding JPEG puts the process to infinite loop if there is an ...
When you are loading a jpg file with some broken bytes in it, process gets in to infinite loop. Steps to Reproduce. Try...
Read more >
jpeg: Avoid an infinite loop with invalid images (!141) · Merge ...
When loading an invalid image with a missing EOI marker we end up triggering an infinite loop inside libjpeg. ... Merge blocked: all...
Read more >
PHP :: Bug #34704 :: Infinite recursion due to corrupt JPEG
Bug #34704, Infinite recursion due to corrupt JPEG ... IFD offset" field pointing back to the same structure, creating an infinite loop.
Read more >
How to fix corrupt JPEG files - Quora
First Download the Wondershare Repairit application on your system. Hit on "Add Files" to upload the image you want to repair. You can...
Read more >
MagickReadImageBlob stuck in endless loop - ImageMagick
The version of IM is 6.8.4-8 (downloaded on April 10th). Basically an encoder passes a JPEG image in memory as a char*. I...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found