System.loadLibrary() not present in EncoderJNI.java ? #210

Closed
opened 2026-01-29 20:39:57 +00:00 by claunia · 4 comments
Owner

Originally created by @kjatin on GitHub (Jan 8, 2018).

I was trying to use the JNI wrapper but found that EncoderJNI.java file does not have a loadLibrary statement in a static block.
It does not work until I add the following piece of code:

static{ System.loadLibrary("myBrotliJNILibraryName"); }
Any particular reason for this?

Originally created by @kjatin on GitHub (Jan 8, 2018). I was trying to use the JNI wrapper but found that EncoderJNI.java file does not have a loadLibrary statement in a static block. It does not work until I add the following piece of code: ` static{ System.loadLibrary("myBrotliJNILibraryName"); } ` Any particular reason for this?
Author
Owner

@eustas commented on GitHub (Jan 8, 2018):

There are 2 main reasons:

  • the name / location of JNI library (if any) depends on build system
  • often, to avoid tricky problems, all JNI code is compiled into a single library per app; thus, it is impossible to know before-head what to load

The solution is to let developer decide, when and what library to load. For testing we use a simple but flexible stub: https://github.com/google/brotli/blob/master/java/org/brotli/integration/BrotliJniTestBase.java#L10

@eustas commented on GitHub (Jan 8, 2018): There are 2 main reasons: * the name / location of JNI library (if any) depends on build system * often, to avoid tricky problems, all JNI code is compiled into a single library per app; thus, it is impossible to know before-head what to load The solution is to let developer decide, when and what library to load. For testing we use a simple but flexible stub: https://github.com/google/brotli/blob/master/java/org/brotli/integration/BrotliJniTestBase.java#L10
Author
Owner

@kjatin commented on GitHub (Jan 8, 2018):

Does this mean that if we want to import the source code as a third-party code, we would need to make modifications to the source code? Is there a simpler way of loading the library (something similar to the stub you mentioned). Please excuse my in-experience with JNI build systems.

@kjatin commented on GitHub (Jan 8, 2018): Does this mean that if we want to import the source code as a third-party code, we would need to make modifications to the source code? Is there a simpler way of loading the library (something similar to the stub you mentioned). Please excuse my in-experience with JNI build systems.
Author
Owner

@eustas commented on GitHub (Jan 8, 2018):

Yup.

It is possible to write a generalized stub, but it is a little bit scary, because:

  • AFAIK there is no formal agreement for naming vendor-specific system properties (e.g. BROTLI_JNI_LIBRARY)
  • system property could be altered by attacker -> could cause arbitrary code execution (via DLL initialization)
@eustas commented on GitHub (Jan 8, 2018): Yup. It is possible to write a generalized stub, but it is a little bit scary, because: * AFAIK there is no formal agreement for naming vendor-specific system properties (e.g. `BROTLI_JNI_LIBRARY`) * system property could be altered by attacker -> could cause arbitrary code execution (via DLL initialization)
Author
Owner

@kjatin commented on GitHub (Jan 12, 2018):

I get the point here. Thanks for the clarification. However I would suggest you put this instruction in the README or some other suitable file as a documentation.

@kjatin commented on GitHub (Jan 12, 2018): I get the point here. Thanks for the clarification. However I would suggest you put this instruction in the README or some other suitable file as a documentation.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/brotli#210