Skip to content

Commit 403dd37

Browse files
authored
[class-parse] Ignore .jnilib files within .jar files (#890)
Fixes: #860 Context: https://bugs.openjdk.java.net/browse/JDK-8127215 A long time ago (2002-ish?), the custom Java distributed on Mac OS X required that native libraries containing JNI code have a `.jnilib` file extension, apparently as part of [Java Web Start][0]: > Java Web Start: Mac OS X Details: > … > * Native libraries must be in JARs and end in .jnilib This was supported up through Apple Java 6. Some types of support for the `.jnilib` extension was [removed in OpenJDK 7][1], but `.jar` files containing `.jnilib` entries can still be found, e.g. in the [`jna-4.5.1.jar` file][2]: ![image](https://user-images.githubusercontent.com/179295/136593203-c8a017b6-f113-4ee2-8b44-e5ffa4eaa34b.png) Additionally, `.jnilib` files contain a `0xCAFEBABE` file header, as found in `.class` files, but it's not a Java `.class` file: it's otherwise a Mac OS X `.dylib` file: % hexdump -C com/sun/jna/darwin/libjnidispatch.jnilib | head -1 00000000 ca fe ba be 00 00 00 02 00 00 00 07 00 00 00 03 |................| % objdump -h com/sun/jna/darwin/libjnidispatch.jnilib Sections: Idx Name Size VMA Type 0 __text 0000d3de 0000000000000dc0 TEXT 1 __stubs 000000de 000000000000e19e TEXT … Trying to parse a `.jar` file containing such a `.jnilib` entry results in an `ArgumentOutOfRangeException`: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource) at System.Collections.Generic.List`1.get_Item(Int32 index) at Xamarin.Android.Tools.Bytecode.AttributeInfo.CreateFromStream(ConstantPool constantPool, Stream stream) Fix this error by ignoring `.jnilib` files found within a `.jar`. [0]: https://ia903107.us.archive.org/16/items/Wwdc2002DvdSet/WWDC_2002/PDFs/400/403.pdf [1]: https://bugs.openjdk.java.net/browse/JDK-8127215 [2]: http://www.java2s.com/example/jar/j/download-jna451jar-file.html
1 parent bda6be4 commit 403dd37

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/Xamarin.Android.Tools.Bytecode/ClassPath.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public void Load (Stream jarStream, bool leaveOpen = false)
6161
if (entry.Length == 0)
6262
continue;
6363
using (var s = entry.Open ()) {
64-
if (!ClassFile.IsClassFile (s))
64+
if (!ClassFile.IsClassFile (s) || entry.Name.EndsWith (".jnilib", StringComparison.OrdinalIgnoreCase))
6565
continue;
6666
}
6767
using (var s = entry.Open ()) {

0 commit comments

Comments
 (0)