8242695: Enhanced buffer support

Reviewed-by: alanb, rhalade
This commit is contained in:
Brian Burkhalter 2020-05-20 13:56:21 -07:00 committed by Henry Jen
parent a6723c8552
commit fc5fca9ade
2 changed files with 15 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -55,10 +55,15 @@ public class RegistryFileTypeDetector
// query HKEY_CLASSES_ROOT\<ext> // query HKEY_CLASSES_ROOT\<ext>
String key = filename.substring(dot); String key = filename.substring(dot);
NativeBuffer keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key); NativeBuffer keyBuffer = null;
NativeBuffer nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type"); NativeBuffer nameBuffer = null;
try { try {
keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
return queryStringValue(keyBuffer.address(), nameBuffer.address()); return queryStringValue(keyBuffer.address(), nameBuffer.address());
} catch (WindowsException we) {
we.rethrowAsIOException(file.toString());
return null; // keep compiler happy
} finally { } finally {
nameBuffer.release(); nameBuffer.release();
keyBuffer.release(); keyBuffer.release();

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -1123,7 +1123,12 @@ class WindowsNativeDispatcher {
private static final Unsafe unsafe = Unsafe.getUnsafe(); 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 stringLengthInBytes = s.length() << 1;
int sizeInBytes = stringLengthInBytes + 2; // char terminator int sizeInBytes = stringLengthInBytes + 2; // char terminator