8242695: Enhanced buffer support

Wed, 20 May 2020 13:56:21 -0700

author
bpb
date
Wed, 20 May 2020 13:56:21 -0700
changeset 14215
05922d77fc13
parent 14214
e333a640d78f
child 14216
f6804947798c

8242695: Enhanced buffer support
Reviewed-by: alanb, rhalade

src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java file | annotate | diff | comparison | revisions
src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java	Fri Oct 16 19:55:07 2020 +0100
     1.2 +++ b/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java	Wed May 20 13:56:21 2020 -0700
     1.3 @@ -57,10 +57,15 @@
     1.4  
     1.5          // query HKEY_CLASSES_ROOT\<ext>
     1.6          String key = filename.substring(dot);
     1.7 -        NativeBuffer keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
     1.8 -        NativeBuffer nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
     1.9 +        NativeBuffer keyBuffer = null;
    1.10 +        NativeBuffer nameBuffer = null;
    1.11          try {
    1.12 +            keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
    1.13 +            nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
    1.14              return queryStringValue(keyBuffer.address(), nameBuffer.address());
    1.15 +        } catch (WindowsException we) {
    1.16 +            we.rethrowAsIOException(file.toString());
    1.17 +            return null; // keep compiler happy
    1.18          } finally {
    1.19              nameBuffer.release();
    1.20              keyBuffer.release();
     2.1 --- a/src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java	Fri Oct 16 19:55:07 2020 +0100
     2.2 +++ b/src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java	Wed May 20 13:56:21 2020 -0700
     2.3 @@ -1123,7 +1123,12 @@
     2.4  
     2.5      private static final Unsafe unsafe = Unsafe.getUnsafe();
     2.6  
     2.7 -    static NativeBuffer asNativeBuffer(String s) {
     2.8 +    static NativeBuffer asNativeBuffer(String s) throws WindowsException {
     2.9 +        if (s.length() > (Integer.MAX_VALUE - 2)/2) {
    2.10 +            throw new WindowsException
    2.11 +                ("String too long to convert to native buffer");
    2.12 +        }
    2.13 +
    2.14          int stringLengthInBytes = s.length() << 1;
    2.15          int sizeInBytes = stringLengthInBytes + 2;  // char terminator
    2.16  

mercurial