Skip to content

Commit fc5fca9

Browse files
Brian Burkhalterslowhog
authored andcommitted
8242695: Enhanced buffer support
Reviewed-by: alanb, rhalade
1 parent a6723c8 commit fc5fca9

2 files changed

Lines changed: 15 additions & 5 deletions

File tree

src/java.base/windows/classes/sun/nio/fs/RegistryFileTypeDetector.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -55,10 +55,15 @@ public String implProbeContentType(Path file) throws IOException {
5555

5656
// query HKEY_CLASSES_ROOT\<ext>
5757
String key = filename.substring(dot);
58-
NativeBuffer keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
59-
NativeBuffer nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
58+
NativeBuffer keyBuffer = null;
59+
NativeBuffer nameBuffer = null;
6060
try {
61+
keyBuffer = WindowsNativeDispatcher.asNativeBuffer(key);
62+
nameBuffer = WindowsNativeDispatcher.asNativeBuffer("Content Type");
6163
return queryStringValue(keyBuffer.address(), nameBuffer.address());
64+
} catch (WindowsException we) {
65+
we.rethrowAsIOException(file.toString());
66+
return null; // keep compiler happy
6267
} finally {
6368
nameBuffer.release();
6469
keyBuffer.release();

src/java.base/windows/classes/sun/nio/fs/WindowsNativeDispatcher.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2008, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1123,7 +1123,12 @@ static native int GetOverlappedResult(long hFile, long lpOverlapped)
11231123

11241124
private static final Unsafe unsafe = Unsafe.getUnsafe();
11251125

1126-
static NativeBuffer asNativeBuffer(String s) {
1126+
static NativeBuffer asNativeBuffer(String s) throws WindowsException {
1127+
if (s.length() > (Integer.MAX_VALUE - 2)/2) {
1128+
throw new WindowsException
1129+
("String too long to convert to native buffer");
1130+
}
1131+
11271132
int stringLengthInBytes = s.length() << 1;
11281133
int sizeInBytes = stringLengthInBytes + 2; // char terminator
11291134

0 commit comments

Comments
 (0)