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

Crash when InputStream on JarEntry read after JarFile closed

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.3.0
    • core-libs
    • generic
    • generic



      Name: skT45625 Date: 06/09/2000


      java version "1.2.1-beta1"
      Fast VM (build J2SDK.v.1.2.1:06/09/19100-16:14, native threads, jfex_jit_121)

      and

      Classic VM (build JDK-1.2.2-W, native threads, symcjit)


      The program below illustrates the problem: reading an input stream
      on a jar file entry after closing the jar file. We've seen this cause
      crashes due to segmentation violations, and we've seen it hang the system.

      This program should fail with a nice, easy to understand exception. It is fine
      to require keeping the jar file open while reading the input stream, but
      incorrect programming should not hang or crash the system.

      import java.util.jar.*;
      import java.io.*;

      public class Test {
          public static void main(String[] argv) throws IOException {
      JarFile jf = new JarFile(argv[0]);
      JarEntry jent = jf.getJarEntry("DATA/DESC");
      if (jent == null) {
      throw new IOException("File not found in jar file");
      }
      InputStream in = jf.getInputStream(jent);
      jf.close();
      in.read();
          }
      }

      Here's a stack trace from a different program that had this behavior:

      AnalyzerJarFileTestsegmentation violation at 0x30000043c3c
         r00 = 0x0000000000000000 r16 = 0x00000000b75e0000
         r01 = 0x0000000000000001 r17 = 0xffffffffffffe07b
         r02 = 0x0000000000100000 r18 = 0x000000014043bd80
         r03 = 0xffffffffb75e0000 r19 = 0x000000014042e438
         r04 = 0x0000000000000000 r20 = 0x0000000000000000
         r05 = 0x0000000000000000 r21 = 0x0000000040044c60
         r06 = 0x0000000000000000 r22 = 0x0000000000000000
         r07 = 0x0000000000000000 r23 = 0x000000011fffec80
         r08 = 0x0000000000000001 r24 = 0x000000011fffd660
         r09 = 0x00000000b75e0000 r25 = 0x000000000000007c
         r10 = 0x0000000020027460 r26 = 0x000003000005c5fc
         r11 = 0x0000000000000000 r27 = 0x000003ff80589d10
         r12 = 0x00000000b75e0000 r28 = 0x000003000009d42c
         r13 = 0x0000000000000000 r29 = 0x000003004015d2e0
         r14 = 0xffffffffb75e0000 r30 = 0x000000011fffc430
         r15 = 0x000000011fffe660 r31 = 0x0000000000000000
      Stack trace:
          pc 0x030000099fa4 sp 0x14003d9f0 debug_full_trace
          pc 0x030000099180 sp 0x14003dc80 einfo_segv_handler
          pc 0x03ff800d5db0 sp 0x14003dd60 __sigtramp
          pc 0x030000043c3c sp 0x11fffc430 thread_suspend_it
          pc 0x03000005c5f8 sp 0x11fffc440 share_lock
          pc 0x03000005b87c sp 0x11fffc480 monitor_enter
          pc 0x03000007e8c0 sp 0x11fffc4e0 JVM_RawMonitorEnter
          pc 0x030000815550 sp 0x11fffc4f0 ZIP_Lock
          pc 0x0300008063f8 sp 0x11fffc500 Java_java_util_zip_ZipFile_read
          pc 0x000020023260 sp 0x11fffe550 -1: java/util/zip/ZipFile.read(JJI[BII)I
          pc 0x0300000a4a88 sp 0x11fffe610 unpack_and_call
          pc 0x03000009d59c sp 0x11fffe620 make_native_call
          pc 0x030000055eb0 sp 0x11fffe700 interpret
          pc 0x030000055eb0 sp 0x11fffe700 10: java/util/zip/ZipFile.access$5(JJI
      [BII)I
          pc 0x030000055eb0 sp 0x11fffe700 43:
      java/util/zip/ZipFile$ZipFileInputStream.read([BII)I
          pc 0x030000055eb0 sp 0x11fffe700 32: java/util/zip/ZipFile$1.fill()V
          pc 0x03000009d1e4 sp 0x11fffe7d0 exec_vararg
          pc 0x03000009cc2c sp 0x11fffe890 interp_wrapper
          pc 0x0300000a47a4 sp 0x11fffe8d0 comp_interp_stub
          pc 0x000020023040 sp 0x11fffe950 51:
      java/util/zip/InflaterInputStream.read([BII)I
          pc 0x0300000a4a88 sp 0x11fffe9a0 unpack_and_call
          pc 0x03000009d59c sp 0x11fffe9b0 make_native_call
          pc 0x030000055eb0 sp 0x11fffea80 interpret
          pc 0x030000055eb0 sp 0x11fffea80 12:
      java/util/zip/InflaterInputStream.read()I
          pc 0x030000056c1c sp 0x11fffeb50 enlarge_stack_and_interpret
          pc 0x030000055f78 sp 0x11fffeda0 interpret
          pc 0x030000055f78 sp 0x11fffeda0 11: wib/util/sx/Lexer.<init>
      (Ljava/io/InputStream;)V
          pc 0x030000055f78 sp 0x11fffeda0 5: wib/util/sx/Sx.New
      (Ljava/io/InputStream;)Lwib/util/sx/Sx;
          pc 0x03000009d1e4 sp 0x11fffee70 exec_vararg
          pc 0x03000009cc2c sp 0x11fffef30 interp_wrapper
          pc 0x0300000a47a4 sp 0x11fffef70 comp_interp_stub
          pc 0x000020027780 sp 0x11fffeff0 5:
      wib/analyzer/AnalyzerJarFile.parseDescriptorFile(Ljava/io/InputStream;)V
          pc 0x0300000a4a88 sp 0x11ffff060 unpack_and_call
          pc 0x03000009d570 sp 0x11ffff070 make_native_call
          pc 0x030000055eb0 sp 0x11ffff140 interpret
          pc 0x030000055eb0 sp 0x11ffff140 57: wib/analyzer/AnalyzerJarFile.<init>
      (Ljava/lang/String;)V
          pc 0x030000055eb0 sp 0x11ffff140 7:
      wib/analyzer/test/AnalyzerJarFileTest.runtest(Ljava/lang/String;)V
          pc 0x030000055eb0 sp 0x11ffff140 45:
      wib/analyzer/test/AnalyzerJarFileTest.main([Ljava/lang/String;)V
          pc 0x030000056c1c sp 0x11ffff210 enlarge_stack_and_interpret
          pc 0x030000055f78 sp 0x11ffff460 interpret
          pc 0x0300000609f8 sp 0x11ffff530 jni_call
          pc 0x03000006196c sp 0x11ffff5f0 jni_CallStaticVoidMethodA
          pc 0x030000061a0c sp 0x11ffff620 jni_CallStaticVoidMethod
          pc 0x000120002448 sp 0x11ffff6b0 main
          pc 0x000120001d48 sp 0x11ffff7f0 __start
      (Review ID: 105987)
      ======================================================================

            kkladkosunw Konstantin Kladko (Inactive)
            skondamasunw Suresh Kondamareddy (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: