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

(fs) Writing to a read-only mapped byte buffer crashes the VM

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 1.4.1
    • 1.4.0
    • core-libs
    • hopper
    • x86
    • windows_2000
    • Verified



        Name: rmT116609 Date: 10/03/2001


        C:\temp\jdk14test\src\main>c:\jdk1.4\bin\java -version
        java version "1.4.0-beta2"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta2-b77)
        Java HotSpot(TM) Client VM (build 1.4.0-beta2-b77, mixed mode)


        1. Executed a test program to demo MappedByteBuffer. It is taken from the Rot13
        example from "Early Adopter J2SE 1.4" featured on JDC
        http://developer.java.sun.com/developer/Books/EarlyJ2SE/

        ran the program after a successful compile using

        The command I used was c:\jdk1.4\bin\java nio.Rot13 README.txt

        The README is the one distributed with the JDK .

        2. The source to nio.Rot13.java

        package nio;

        import java.io.*;
        import java.nio.channels.*;
        import java.nio.*;

        public class Rot13 {

            /** Creates new Rot13 */
            public Rot13() {
            }

            /**
            * @param args the command line arguments
            */
            public static void main (String args[]) {
                FileChannel in = null;
                
                if (args.length < 1) {
                    System.err.println("No file specified");
                    System.err.println("Usage: java Rot13 <file>");
                    System.exit(1);
                }
                
                try {
                    in = new RandomAccessFile(args[0], "rw").getChannel();
                    MappedByteBuffer mbb = in.map(FileChannel.MAP_RO, 0L, (int) in.size());
                    mbb.load();
                    
                    while (mbb.hasRemaining()) {
                        byte c = mbb.get(mbb.position());
                        
                        if (('a' <= c) && (c <= 'z')) {
                            if (c < 'n') {
                                c += 13;
                            } else {
                                c -= 13;
                            }
                        } else if (('A' <= c) && (c <= 'Z')) {
                            if (c < 'N') {
                                c += 13;
                            } else {
                                c -= 13;
                            }
                        }
                        
                        mbb.put(c);
                    }
                    
                    mbb.force();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    try {
                        if (in != null) {
                            in.close();
                        }
                    } catch (IOException io) {}
                }
            }

        }


        3. the resulting log file:

        Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6D3BBB22
        Function=Unsafe_SetNativeByte+0x59
        Library=c:\jdk1.4\jre\bin\client\jvm.dll

        Current Java thread:
        at sun.misc.Unsafe.putByte(Native Method)
        at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:186)
        at nio.Rot13.main(Rot13.java:57)

        Dynamic libraries:
        0x00400000 - 0x00406000 c:\jdk1.4\bin\java.exe
        0x77F80000 - 0x77FFA000 C:\WINNT\System32\ntdll.dll
        0x77DB0000 - 0x77E0A000 C:\WINNT\system32\ADVAPI32.dll
        0x77E80000 - 0x77F35000 C:\WINNT\system32\KERNEL32.DLL
        0x77D40000 - 0x77DB0000 C:\WINNT\system32\RPCRT4.DLL
        0x78000000 - 0x78046000 C:\WINNT\system32\MSVCRT.dll
        0x6D330000 - 0x6D446000 c:\jdk1.4\jre\bin\client\jvm.dll
        0x77E10000 - 0x77E74000 C:\WINNT\system32\USER32.dll
        0x77F40000 - 0x77F7C000 C:\WINNT\system32\GDI32.DLL
        0x77570000 - 0x775A0000 C:\WINNT\System32\WINMM.dll
        0x6D1D0000 - 0x6D1D7000 c:\jdk1.4\jre\bin\hpi.dll
        0x6D300000 - 0x6D30D000 c:\jdk1.4\jre\bin\verify.dll
        0x6D210000 - 0x6D227000 c:\jdk1.4\jre\bin\java.dll
        0x6D320000 - 0x6D32D000 c:\jdk1.4\jre\bin\zip.dll
        0x6D2E0000 - 0x6D2E7000 C:\jdk1.4\jre\bin\nio.dll
        0x75030000 - 0x75044000 C:\WINNT\System32\WS2_32.dll
        0x75020000 - 0x75028000 C:\WINNT\System32\WS2HELP.DLL
        0x77920000 - 0x77942000 C:\WINNT\system32\imagehlp.dll
        0x72A00000 - 0x72A2D000 C:\WINNT\system32\DBGHELP.dll
        0x690A0000 - 0x690AB000 C:\WINNT\System32\PSAPI.DLL

        Local Time = Mon Oct 01 11:50:58 2001
        Elapsed Time = 1
        #
        # HotSpot Virtual Machine Error : EXCEPTION_ACCESS_VIOLATION
        # Error ID : 4F530E43505002D7
        # Please report this error at
        # http://java.sun.com/cgi-bin/bugreport.cgi
        #
        # Java VM: Java HotSpot(TM) Client VM (1.4.0-beta2-b77 mixed mode)
        #


        Interestingly I tried the same on a win98 m/c and it blows up as
        but with a slightly different error log.

        An unexpected exception has been detected in native code outside the VM.
        Unexpected Signal : EXCEPTION_ACCESS_VIOLATION occurred at PC=0x6D3BBB22
        Function=[Unknown.]
        Library=(N/A)

        NOTE: We are unable to locate the function name symbol for the error
              just occurred. Please refer to release documentation for possible
              reason and solutions.


        Current Java thread:
        at sun.misc.Unsafe.putByte(Native Method)
        at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:186)
        at nio.Rot13.main(Rot13.java:47)

        Dynamic libraries:
        0x7CC00000 - 0x7CC1D000 C:\WINDOWS\SYSTEM\IMAGEHLP.DLL

        Local Time = Wed Oct 03 17:31:46 2001
        Elapsed Time = 0
        #
        # The exception above was detected in native code outside the VM
        #
        # Java VM: Java HotSpot(TM) Client VM (1.4.0-beta2-b77 mixed mode)
        #
        (Review ID: 132886)
        ======================================================================

              mmcclosksunw Michael Mccloskey (Inactive)
              rmandalasunw Ranjith Mandala (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: