Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[class-parse] Ignore .jnilib files within .jar files (dotnet#890)
Fixes: dotnet#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
- Loading branch information