changeset 14164:05922d77fc13

8242695: Enhanced buffer support Reviewed-by: alanb, rhalade
author bpb
date Wed, 20 May 2020 13:56:21 -0700
parents e333a640d78f
children f6804947798c
files src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java
diffstat 2 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java	Fri Oct 16 19:55:07 2020 +0100
+++ b/src/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java	Wed May 20 13:56:21 2020 -0700
@@ -57,10 +57,15 @@
 
         // query HKEY_CLASSES_ROOT\<ext>
         String key = filename.substring(dot);
-        NativeBuffer keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
-        NativeBuffer nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
+        NativeBuffer keyBuffer = null;
+        NativeBuffer nameBuffer = null;
         try {
+            keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
+            nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
             return queryStringValue(keyBuffer.address(), nameBuffer.address());
+        } catch (WindowsException we) {
+            we.rethrowAsIOException(file.toString());
+            return null; // keep compiler happy
         } finally {
             nameBuffer.release();
             keyBuffer.release();
--- a/src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java	Fri Oct 16 19:55:07 2020 +0100
+++ b/src/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java	Wed May 20 13:56:21 2020 -0700
@@ -1123,7 +1123,12 @@
 
     private static final Unsafe unsafe = Unsafe.getUnsafe();
 
-    static NativeBuffer asNativeBuffer(String s) {
+    static NativeBuffer asNativeBuffer(String s) throws WindowsException {
+        if (s.length() > (Integer.MAX_VALUE - 2)/2) {
+            throw new WindowsException
+                ("String too long to convert to native buffer");
+        }
+
         int stringLengthInBytes = s.length() << 1;
         int sizeInBytes = stringLengthInBytes + 2;  // char terminator