Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4398120

JPEGImageDecoderImpl infinite loop on bad jpeg

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • 2d
    • beta
    • x86
    • linux



      Name: yyT116575 Date: 12/14/2000


      java version "1.3.0_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0_01)
      Java HotSpot(TM) Client VM (build 1.3.0_01, mixed mode)

      1. Obtain a "bad" jpeg file (vague definition, but don't worry)
      2. Call JPEGImageDecoder.decodeAsBufferedImage() with an InputStream pointing at
      the bad jpeg file.
      3. Observe the error message: "2 extraneous bytes before marker 0xd9"
      4. Note that the routine never completes, and that CPU use moves to 100%, which
      seems to indicate an infinite loop problem.

      Further investigation revealed the problem to be in libjpeg.so, file
      jpegimagedecoderimpl.c, function "cleanup", on or about line 690 (assumes the
      JDK 1.2.2 source), which repeatedly calls InputStream.skip(x) until it is told
      that "x" bytes were actually skipped. From what I can tell, in my problem case,
      the InputStream returns 0 skipped bytes, so this loop continues forever.

      To test my theory, I added some code to drop out of the loop when
      InputStream.skip(x) returns <= 0, installed my modified libjpeg.so, and retried
      my "bad jpeg" test case. Result: no more infinite loop. Eyeball the code and
      hopefully this fix makes sense to you as well.

      A parenthetical remark: I could not have found this problem without
      your "community source" program.
      (Review ID: 113780)
      ======================================================================

            prr Philip Race
            yyoungsunw Yung-ching Young (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: